class_docstr: Abstract base class for transfer learning hooks.
  
  This hook initializes the model's variables with values from previously
  completed trials. Subclasses are responsible for determining how to combine
  matching variables from previous trials. If any variable of a particular
  previous trial does not match in name, shape, or dtype to corresponding
  variable of the current trial it will be ignored.
class_docstr_tok: ["Abstract","base","class","for","transfer","learning","hooks",".","This","hook","initializes","the","model","'s","variables","with","values","from","previously","completed","trials",".","Subclasses","are","responsible","for","determining","how","to","combine","matching","variables","from","previous","trials",".","If","any","variable","of","a","particular","previous","trial","does","not","match","in","name",",","shape",",","or","dtype","to","corresponding","variable","of","the","current","trial","it","will","be","ignored","."]
docstr: Creates the ops needed to warm start the model's variables.
docstr_tok: ["Creates","the","ops","needed","to","warm","start","the","model","'s","variables","."]
code: def begin(self):
      """Creates the ops needed to warm start the model's variables."""
      # Do not warm start the model if a checkopint already exists. If the model
      # has already been training, we do not want to overwrite its variables.
      if tf.train.latest_checkpoint(self._model_dir):
          return
      if not self._completed_trials:
          return
  
      # Create CheckpointReaders for all completed trials.
      readers = []
      shape_maps = []
      dtype_maps = []
      for trial in self._completed_trials:
          reader = tf.train.load_checkpoint(
              architecture_utils.DirectoryHandler.trial_dir(trial)
          )
          readers.append(reader)
          shape_maps.append(reader.get_variable_to_shape_map())
          dtype_maps.append(
              reader._GetVariableToDataTypeMap()
          )  # pylint: disable=protected-access
  
      # Create the warm start ops.
      for var in self._vars_to_warm_start:
          trial_to_var = []
          for trial, reader, shape_map, dtype_map in zip(
              self._completed_trials, readers, shape_maps, dtype_maps
          ):
              var_name = var.op.name
              if (
                  not reader.has_tensor(var_name)
                  or var.shape != shape_map[var_name]
                  or var.dtype.base_dtype.as_datatype_enum
                  != dtype_map[var_name]
              ):
                  continue
              tensor = reader.get_tensor(var_name)
              discounted = self._discount(trial, tensor)
              trial_to_var.append((trial, discounted))
          if not trial_to_var:
              logging.info(
                  "Skipped warm starting %s since it does not match any variables "
                  "from previous trials.",
                  var_name,
              )
              continue
          logging.info(
              "Warm starting %s with values from %d previous trials.",
              var_name,
              len(trial_to_var),
          )
          trial_to_var = self._sort_previous_trial_variables(
              trial_to_var
          )
          trial_to_var = trial_to_var[: self._max_completed_trials]
          combined = self._combine_previous_trial_variables(
              trial_to_var
          )
          self._assign_ops.append(var.assign(combined))
  
file_path: model_search/model_search/meta/transfer_learning.py
imports: import abc
  from absl import logging
  from model_search.architecture import architecture_utils
  import tensorflow.compat.v2
label_desc: Use image node_id 4 for calling the BaseTransferLearningHook obj's underlying member method code with example usage: obj.begin() without return types