code: def test_checkpoint(self):
      features = np.random.randn(20, 10)
      labels = np.random.randint(0, 10, size=[20])
      with tf.Graph().as_default():
          dataset = TFDataset.from_ndarrays(
              (features, labels),
              batch_size=4,
              val_tensors=(features, labels),
          )
          feature_tensor, label_tensor = dataset.tensors
          features = tf.layers.dense(feature_tensor, 8)
          output = tf.layers.dense(features, 10)
          loss = tf.reduce_mean(
              tf.losses.sparse_softmax_cross_entropy(
                  logits=output, labels=label_tensor
              )
          )
          model_dir = tempfile.mkdtemp()
          try:
              optimizer = TFOptimizer.from_loss(
                  loss,
                  Adam(),
                  val_outputs=[output],
                  val_labels=[label_tensor],
                  val_method=Accuracy(),
                  metrics={"loss": loss},
                  model_dir=model_dir,
              )
              optimizer.optimize(end_trigger=MaxEpoch(1))
  
              first_weights = optimizer.sess.run(
                  tf.trainable_variables()[0]
              )
              import re
  
              ckpt_path = None
              versions = []
              for root, dirs, files in os.walk(model_dir, topdown=True):
                  temp_versions = []
                  for file_name in files:
                      if (
                          re.match(
                              "^optimMethod-TFParkTraining\.[0-9]+$",
                              file_name,
                          )
                          is not None
                      ):
                          version = int(file_name.split(".")[1])
                          temp_versions.append(version)
                  if temp_versions:
                      ckpt_path = root
                      versions = temp_versions
                      break
  
              assert (
                  ckpt_path is not None
              ), "Cannot fine checkpoint file"
              optimizer.sess.run(
                  tf.global_variables_initializer()
              )  # reset variable
              optimizer_load = TFOptimizer.from_loss(
                  loss,
                  Adam(),
                  session=optimizer.sess,
                  val_outputs=[output],
                  val_labels=[label_tensor],
                  val_method=Accuracy(),
                  metrics={"loss": loss},
                  model_dir=model_dir,
              )
              optimizer_load.load_checkpoint(ckpt_path, max(versions))
              loaded_first_weights_before_train = optimizer.sess.run(
                  tf.trainable_variables()[0]
              )
              assert np.allclose(
                  first_weights, loaded_first_weights_before_train
              )
              # max epoch still 1, should not train
              optimizer_load.optimize(end_trigger=MaxEpoch(1))
              loaded_first_weights = optimizer.sess.run(
                  tf.trainable_variables()[0]
              )
              assert np.allclose(first_weights, loaded_first_weights)
  
              # max epoch increase 1, should train 1 epoch
              optimizer_load.optimize(end_trigger=MaxEpoch(2))
              loaded_first_weights_2 = optimizer.sess.run(
                  tf.trainable_variables()[0]
              )
              assert not np.allclose(
                  first_weights, loaded_first_weights_2
              )
              optimizer_load.sess.close()
          finally:
              import shutil
  
              shutil.rmtree(model_dir)
  
file_path: analytics-zoo/pyzoo/test/zoo/tfpark/test_tfpark_tfoptimizer.py
imports: import pytest
  from bigdl.optim.optimizer import Adam, SGD, MaxEpoch
  from zoo.pipeline.api.keras.metrics import Accuracy
  from test.zoo.pipeline.utils.test_utils import ZooTestCase
  import tensorflow
  import numpy
  import tempfile
  import os
  from zoo.tfpark import TFDataset, TFOptimizer
label_desc: Use image node_id 5 for calling the TestTFParkTFOptimizer obj's underlying member method code with example usage: obj.test_checkpoint() without return types