class_docstr: Training hook to perform membership inference attack on epoch end.
class_docstr_tok: ["Training","hook","to","perform","membership","inference","attack","on","epoch","end","."]
docstr: Initialize the hook.
  
  Args:
    estimator: model to be tested
    in_train: (in_training samples, in_training labels,
      in_train_sample_weights=None)
    out_train: (out_training samples, out_training labels,
      out_train_sample_weights=None)
    input_fn_constructor: a function that receives sample, label and construct
      the input_fn for model prediction
    slicing_spec: slicing specification of the attack
    attack_types: a list of attacks, each of type AttackType
    tensorboard_dir: directory for tensorboard summary
    tensorboard_merge_classifiers: if true, plot different classifiers with
      the same slicing_spec and metric in the same figure
docstr_tok: ["Initialize","the","hook",".","Args",":","estimator",":","model","to","be","tested","in_train",":","(","in_training","samples",",","in_training","labels",",","in_train_sample_weights=None",")","out_train",":","(","out_training","samples",",","out_training","labels",",","out_train_sample_weights=None",")","input_fn_constructor",":","a","function","that","receives","sample",",","label","and","construct","the","input_fn","for","model","prediction","slicing_spec",":","slicing","specification","of","the","attack","attack_types",":","a","list","of","attacks",",","each","of","type","AttackType","tensorboard_dir",":","directory","for","tensorboard","summary","tensorboard_merge_classifiers",":","if","true",",","plot","different","classifiers","with","the","same","slicing_spec","and","metric","in","the","same","figure"]
code: def __init__(
      self,
      estimator,
      in_train,
      out_train,
      input_fn_constructor,
      slicing_spec: data_structures.SlicingSpec = None,
      attack_types: Iterable[data_structures.AttackType] = (
          data_structures.AttackType.THRESHOLD_ATTACK,
      ),
      tensorboard_dir=None,
      tensorboard_merge_classifiers=False,
  ):
      """Initialize the hook.
  
      Args:
        estimator: model to be tested
        in_train: (in_training samples, in_training labels,
          in_train_sample_weights=None)
        out_train: (out_training samples, out_training labels,
          out_train_sample_weights=None)
        input_fn_constructor: a function that receives sample, label and construct
          the input_fn for model prediction
        slicing_spec: slicing specification of the attack
        attack_types: a list of attacks, each of type AttackType
        tensorboard_dir: directory for tensorboard summary
        tensorboard_merge_classifiers: if true, plot different classifiers with
          the same slicing_spec and metric in the same figure
      """
      if len(in_train) == 2:
          in_train_data, self._in_train_labels = in_train
          self._in_train_sample_weights = None
      elif len(in_train) == 3:
          (
              in_train_data,
              self._in_train_labels,
              self._in_train_sample_weights,
          ) = in_train
      else:
          raise ValueError(
              "`in_train` should be length 2 or 3, received "
              f"{len(in_train)}"
          )
      if len(out_train) == 2:
          out_train_data, self._out_train_labels = out_train
          self._out_train_sample_weights = None
      elif len(out_train) == 3:
          (
              out_train_data,
              self._out_train_labels,
              self._out_train_sample_weights,
          ) = in_train
      else:
          raise ValueError(
              "`out_train` should be length 2 or 3, received "
              f"{len(out_train)}"
          )
  
      # Define the input functions for both in and out-training samples.
      self._in_train_input_fn = input_fn_constructor(
          in_train_data, self._in_train_labels
      )
      self._out_train_input_fn = input_fn_constructor(
          out_train_data, self._out_train_labels
      )
      self._estimator = estimator
      self._slicing_spec = slicing_spec
      self._attack_types = attack_types
      self._tensorboard_merge_classifiers = (
          tensorboard_merge_classifiers
      )
      if tensorboard_dir:
          if tensorboard_merge_classifiers:
              self._writers = {}
              with tf.Graph().as_default():
                  for attack_type in attack_types:
                      self._writers[
                          attack_type.name
                      ] = tf.summary.FileWriter(
                          os.path.join(
                              tensorboard_dir, "MI", attack_type.name
                          )
                      )
          else:
              with tf.Graph().as_default():
                  self._writers = tf.summary.FileWriter(
                      os.path.join(tensorboard_dir, "MI")
                  )
          logging.info("Will write to tensorboard.")
      else:
          self._writers = None
  
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 to create a new MembershipInferenceTrainingHook object from inherited base classes: tf_estimator with example: obj = MembershipInferenceTrainingHook(estimator, in_train, out_train, input_fn_constructor, slicing_spec, attack_types, tensorboard_dir, tensorboard_merge_classifiers)