code: def calculate_losses(
      estimator,
      input_fn,
      labels,
      sample_weight: Optional[np.ndarray] = None,
  ):
      """Get predictions and losses for samples.
  
      The assumptions are 1) the loss is cross-entropy loss, and 2) user have
      specified prediction mode to return predictions, e.g.,
      when mode == tf.estimator.ModeKeys.PREDICT, the model function returns
      tf.estimator.EstimatorSpec(mode=mode, predictions=tf.nn.softmax(logits)).
  
      Args:
        estimator: model to make prediction
        input_fn: input function to be used in estimator.predict
        labels: array of size (n_samples, ), true labels of samples (integer valued)
        sample_weight: a vector of weights of shape (n_samples, ) that are
          assigned to individual samples. If not provided, then each sample is
          given unit weight. Only the LogisticRegressionAttacker and the
          RandomForestAttacker support sample weights.
  
      Returns:
        preds: probability vector of each sample
        loss: cross entropy loss of each sample
      """
      pred = np.array(list(estimator.predict(input_fn=input_fn)))
      loss = utils.log_loss(labels, pred, sample_weight=sample_weight)
      return pred, loss
  
file_path: privacy/tensorflow_privacy/privacy/privacy_tests/membership_inference_attack/tf_estimator_evaluation.py
imports: import os
  from typing import Iterable, Optional
  from absl import logging
  import numpy
  import tensorflow
  from tensorflow import estimator
  from tensorflow_privacy.privacy.privacy_tests import utils
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack import data_structures
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack import membership_inference_attack
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack import utils_tensorboard
label_desc: Use image node_id 1 for calling a global function with example usage: calculate_losses(estimator, input_fn, labels, sample_weight) and returns: pred,  loss