code: def get_checkpoint_state(checkpoint_dir):
      """
      Get tf checkpoint state from checkpoint directory without using native tensorflow accessing
      remote method.
      :param checkpoint_dir: tensorflow checkpoint directory. Could be local, hdfs, s3 filesystems.
      :return: tf checkpoint protobuf
      """
      import tensorflow as tf
  
      if is_local_path(checkpoint_dir):
          return tf.train.get_checkpoint_state(checkpoint_dir)
      else:
          # check if checkpoint file exists
          file_list = get_file_list(checkpoint_dir)
          has_checkpoint = False
          for file in file_list:
              if os.path.basename(file) == "checkpoint":
                  has_checkpoint = True
                  break
          if not has_checkpoint:
              return None
          # get checkpoint file
          temp = tempfile.mkdtemp()
          get_remote_file_to_local(
              os.path.join(checkpoint_dir, "checkpoint"),
              os.path.join(temp, "checkpoint"),
          )
          ckpt_name = None
          with open(os.path.join(temp, "checkpoint")) as f:
              lines = f.readlines()
              # get checkpoint name from 'checkpoint' file
              for line in lines:
                  m = re.compile(
                      '^model_checkpoint_path: "(.*)"$'
                  ).match(line)
                  if m:
                      ckpt_name = m.group(1)
                      break
          if ckpt_name is None:
              shutil.rmtree(temp)
              return None
          # filter checkpoint files
          checkpoint_files = [
              file
              for file in file_list
              if os.path.basename(file).startswith(ckpt_name)
          ]
          if not checkpoint_files:
              shutil.rmtree(temp)
              return None
          # get checkpoint files to local
          [
              get_remote_file_to_local(
                  file, os.path.join(temp, os.path.basename(file))
              )
              for file in checkpoint_files
          ]
          # get checkpoint state
          ckpt = tf.train.get_checkpoint_state(temp)
          if not ckpt:
              shutil.rmtree(temp)
              return None
          ckpt.model_checkpoint_path = os.path.join(
              checkpoint_dir, ckpt_name
          )
          ckpt.all_model_checkpoint_paths[:] = [
              os.path.join(checkpoint_dir, ckpt_name)
          ]
          shutil.rmtree(temp)
          return ckpt
  
file_path: analytics-zoo/pyzoo/zoo/util/tf.py
imports: import os
  import json
  import copy
  import tempfile
  import re
  import shutil
  from zoo.common.utils import put_local_file_to_remote, get_remote_file_to_local, get_file_list, is_local_path
label_desc: Use image node_id 10 for calling a global function with example usage: get_checkpoint_state(checkpoint_dir) and returns: tf, ckpt, None, None, None, None