code: def infer_latest_model_file(model_dir):
      """
      Infer initial iteration number from model_dir/checkpoint.
  
      :param model_dir: model folder to search
      :return:
      """
      ckpt_state = tf.train.get_checkpoint_state(model_dir)
      try:
          assert ckpt_state, (
              "{}/checkpoint not found, please check "
              "config parameter: model_dir".format(model_dir)
          )
          checkpoint = ckpt_state.model_checkpoint_path
          assert (
              checkpoint
          ), "checkpoint path not found " "in {}/checkpoint".format(
              model_dir
          )
          initial_iter = int(checkpoint.rsplit("-")[-1])
          tf.logging.info(
              "set initial_iter to %d based " "on checkpoints",
              initial_iter,
          )
          return initial_iter
      except (ValueError, AttributeError, AssertionError):
          tf.logging.fatal(
              "Failed to get iteration number "
              "from checkpoint path (%s),\n"
              "please check config parameter: "
              "model_dir, and initial_iter",
              model_dir,
          )
          raise
  
imports: from __future__ import absolute_import, print_function, unicode_literals
  import errno
  import importlib
  import logging
  import os
  import re
  import sys
  import warnings
  import nibabel
  import numpy
  import pandas
  import scipy.ndimage
  import tensorflow
  from tensorflow.core.framework import summary_pb2
  from niftynet.io.image_loader import load_image_obj
  from niftynet.utilities.niftynet_global_config import NiftyNetGlobalConfig
  from niftynet.utilities.util_import import require_module
label_desc: Use image node_id 30 for calling a global function with example usage: infer_latest_model_file(model_dir) and returns: initial_iter