code: def _compute_missing_privacy_report_metadata(
      metadata: PrivacyReportMetadata, attack_input: AttackInputData
  ) -> PrivacyReportMetadata:
      """Populates metadata fields if they are missing.
  
      Args:
        metadata: Metadata that is used to create a privacy report based on the
          attack results.
        attack_input: The input data used to run a membership attack.
  
      Returns:
        A new or updated metadata object containing information to create the
          privacy report.
      """
  
      if metadata is None:
          metadata = PrivacyReportMetadata()
      if attack_input.is_multilabel_data():
          accuracy_fn = _get_multilabel_accuracy
          sigmoid_func = special.expit
          # Multi label accuracy is calculated with the prediction probabilties and
          # the labels. A threshold with a default of 0.5 is used to get predicted
          # labels from the probabilities.
          if (
              attack_input.probs_train is None
              and attack_input.logits_train is not None
          ):
              logits_or_probs_train = sigmoid_func(
                  attack_input.logits_train
              )
          else:
              logits_or_probs_train = attack_input.probs_train
          if (
              attack_input.probs_test is None
              and attack_input.logits_test is not None
          ):
              logits_or_probs_test = sigmoid_func(
                  attack_input.logits_test
              )
          else:
              logits_or_probs_test = attack_input.probs_test
      else:
          accuracy_fn = _get_accuracy
          # Single label accuracy is calculated with the argmax of the logits which
          # is the same as the argmax of the probbilities.
          logits_or_probs_train = attack_input.logits_or_probs_train
          logits_or_probs_test = attack_input.logits_or_probs_test
      if metadata.accuracy_train is None:
          metadata.accuracy_train = accuracy_fn(
              logits_or_probs_train, attack_input.labels_train
          )
      if metadata.accuracy_test is None:
          metadata.accuracy_test = accuracy_fn(
              logits_or_probs_test, attack_input.labels_test
          )
      loss_train = attack_input.get_loss_train()
      loss_test = attack_input.get_loss_test()
      if metadata.loss_train is None and loss_train is not None:
          metadata.loss_train = np.average(loss_train)
      if metadata.loss_test is None and loss_test is not None:
          metadata.loss_test = np.average(loss_test)
      return metadata
  
imports: import logging
  from typing import Iterable, List, Optional, Union
  import numpy
  from scipy import special
  from sklearn import metrics
  from sklearn import model_selection
  from tensorflow_privacy.privacy.privacy_tests import epsilon_lower_bound
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack import models
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import AttackInputData
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import AttackResults
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import AttackType
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import DataSize
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import EPSILON_ALPHA
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import EPSILON_K
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import EPSILON_METHODS
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import EpsilonLowerBoundValue
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import MembershipProbabilityResults
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import PrivacyReportMetadata
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import RocCurve
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import SingleAttackResult
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import SingleMembershipProbabilityResult
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import SingleSliceSpec
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import SlicingSpec
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.dataset_slicing import get_single_slice_specs
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.dataset_slicing import get_slice
label_desc: Use image node_id 9 for calling a global function with example usage: _compute_missing_privacy_report_metadata(metadata, attack_input) and returns: metadata