code: def decode_from_dataset(
      estimator,
      problem_name,
      hparams,
      decode_hp,
      decode_to_file=None,
      dataset_split=None,
      checkpoint_path=None,
  ):
      """Perform decoding from dataset."""
      tf.logging.info(
          "Performing local inference from dataset for %s.",
          str(problem_name),
      )
      # We assume that worker_id corresponds to shard number.
      shard = decode_hp.shard_id if decode_hp.shards > 1 else None
  
      # Setup output directory for any artifacts that may be written out.
      output_dir = os.path.join(estimator.model_dir, "decode")
      tf.gfile.MakeDirs(output_dir)
  
      # If decode_hp.batch_size is specified, use a fixed batch size
      if decode_hp.batch_size:
          hparams.batch_size = decode_hp.batch_size
          hparams.use_fixed_batch_size = True
  
      dataset_kwargs = {
          "shard": shard,
          "dataset_split": dataset_split,
          "max_records": decode_hp.num_samples,
      }
  
      # Build the inference input function
      problem = hparams.problem
      infer_input_fn = problem.make_estimator_input_fn(
          tf_estimator.ModeKeys.PREDICT,
          hparams,
          dataset_kwargs=dataset_kwargs,
      )
  
      predictions, output_dirs = [], []
      for decode_id in range(decode_hp.num_decodes):
          tf.logging.info("Decoding {}".format(decode_id))
  
          # Create decode directory if not in-memory decoding.
          if not decode_hp.decode_in_memory:
              output_dir = os.path.join(
                  estimator.model_dir, "decode_%05d" % decode_id
              )
              tf.gfile.MakeDirs(output_dir)
              output_dirs.append(output_dir)
  
          result = decode_once(
              estimator,
              problem_name,
              hparams,
              infer_input_fn,
              decode_hp,
              decode_to_file,
              output_dir,
              log_results=decode_hp.log_results,
              checkpoint_path=checkpoint_path,
          )
  
          if decode_hp.decode_in_memory:
              output_dirs = [output_dir]
              predictions.append(result)
  
      if decode_hp.decode_to_file:
          decode_hp.decode_to_file = _decode_filename(
              decode_hp.decode_to_file, problem_name, decode_hp
          )
  
      run_postdecode_hooks(
          DecodeHookArgs(
              estimator=estimator,
              problem=problem,
              output_dirs=output_dirs,
              hparams=hparams,
              decode_hparams=decode_hp,
              predictions=predictions,
          ),
          dataset_split,
      )
      return predictions
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import operator
  import os
  import re
  import string
  import time
  import numpy
  import six
  from six.moves import input
  from tensor2tensor.data_generators import problem
  from tensor2tensor.data_generators import text_encoder
  from tensor2tensor.data_generators import text_problems
  from tensor2tensor.utils import contrib
  from tensor2tensor.utils import hparam
  from tensor2tensor.utils import mlperf_log
  from tensor2tensor.utils import registry
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
label_desc: Use image node_id 3 for calling a global function with example usage: decode_from_dataset(estimator, problem_name, hparams, decode_hp, decode_to_file, dataset_split, checkpoint_path) and returns: predictions