code: def model_fn(features, labels, mode):
      models = []
      logits = []
      classes = []
      init_op = [tf.train.get_or_create_global_step().initializer]
      for i, model_name in enumerate(FLAGS.model_name.split(",")):
          with tf.device("/gpu:%d" % i):
              network_fn = getattr(nets, model_name)
              models.append(network_fn(features, is_training=False))
              logits.append(models[i].get_outputs()[-2])
              classes.append(tf.argmax(logits[i], axis=1))
              if FLAGS.checkpoint_path is None:
                  init_op.extend(models[i].pretrained())
  
      scaffold = None
      if FLAGS.checkpoint_path is None:
          scaffold = tf.train.Scaffold(init_op=init_op)
  
      loss = []
      for i in range(len(models)):
          cross_entropy = tf.losses.sparse_softmax_cross_entropy(
              logits=logits[i], labels=labels
          )
          loss.append(cross_entropy)
      loss = tf.reduce_sum(loss)
  
      metrics = None
      if mode == tf.estimator.ModeKeys.EVAL:
          metrics = {}
          for i in range(len(models)):
              top1 = tf.metrics.accuracy(
                  labels=labels, predictions=classes[i]
              )
              top5 = contrib.metrics.streaming_sparse_recall_at_k(
                  logits[i], tf.cast(labels, tf.int64), k=5
              )
              size = sum(
                  [
                      w.shape.num_elements()
                      for w in models[i].get_weights()
                  ]
              )
              run_meta = tf.RunMetadata()
              opts = tf.profiler.ProfileOptionBuilder.float_operation()
              opts["output"] = "none"
              flops = tf.profiler.profile(
                  tf.get_default_graph(),
                  run_meta=run_meta,
                  options=opts,
              )
              metrics.update(
                  {
                      "%dTop1" % i: top1,
                      "%dTop5" % i: top5,
                      "%dMAC"
                      % i: (
                          tf.constant(flops.total_float_ops),
                          tf.no_op(),
                      ),
                      "%dSize" % i: (tf.constant(size), tf.no_op()),
                  }
              )
  
      return tf.estimator.EstimatorSpec(
          mode=mode,
          scaffold=scaffold,
          predictions=None,
          loss=loss,
          train_op=None,
          eval_metric_ops=metrics,
          export_outputs=None,
      )
  
file_path: tensornets/examples/evaluate_imagenet.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import sys
  import tensorflow.compat.v1
  import tensornets
  from imagenet_preprocessing import input_fn
  from tensorflow import contrib
label_desc: Use image node_id 2 for calling a global function with example usage: model_fn(features, labels, mode) and returns: tf