code: def test_transfer_learning_hook_checkpoint_exists(self):
      # Force graph mode
      with tf.compat.v1.Graph().as_default():
          expected = 4
          root_dir = self.get_temp_dir()
          n_prev = self._create_previous_trials(
              root_dir,
              shapes=[()] * 3,
              dtypes=[tf.float32] * 3,
              values=list(range(3)),
          )
          # Create a checkpoint in the current trial directory.
          with self.test_session(graph=tf.Graph()) as sess:
              var = tf.compat.v1.get_variable(
                  "var",
                  shape=(),
                  dtype=tf.float32,
                  initializer=tf.compat.v1.zeros_initializer,
              )
              var = var.assign_add(expected)
              saver = tf.compat.v1.train.Saver()
              sess.run(tf.compat.v1.global_variables_initializer())
              sess.run(var)
              saver.save(sess, "{}/{}/ckpt".format(root_dir, n_prev))
  
          # Assert that hook does not warm start variables if a checkpoint exists.
          with self.test_session(graph=tf.Graph()) as sess:
              var = tf.compat.v1.get_variable(
                  "var",
                  shape=(),
                  dtype=tf.float32,
                  initializer=tf.compat.v1.zeros_initializer,
              )
              saver = tf.compat.v1.train.Saver()
              trials = []
              for i in range(3):
                  trials.append(
                      test_utils.trial_with_dir(
                          dir_value=os.path.join(root_dir, str(i)), id=i
                      )
                  )
              hook = (
                  transfer_learning.UniformAverageTransferLearningHook(
                      vars_to_warm_start=[var],
                      current_trial_id=n_prev,
                      completed_trials=trials,
                      discount_factor=1.0,
                      max_completed_trials=1000000,
                      model_dir=os.path.join(root_dir, str(n_prev)),
                  )
              )
              hook.begin()
              saver.restore(sess, "{}/{}/ckpt".format(root_dir, n_prev))
              hook.after_create_session(sess, None)
              actual = sess.run(var)
              self.assertEqual(actual, expected)
              self.assertNotEqual(actual, sum(range(3)) / 3)
  
file_path: model_search/model_search/meta/transfer_learning_test.py
imports: import os
  from absl.testing import parameterized
  from model_search import test_utils
  from model_search.meta import transfer_learning
  from model_search.metadata import trial
  import tensorflow.compat.v2
label_desc: Use image node_id 2 for calling the TransferLearningTest obj's underlying member method code with example usage: obj.test_transfer_learning_hook_checkpoint_exists() without return types