code: def build_graph(self, image, label):
      image = tf.expand_dims(image, 3) * 2 - 1
      ctx = get_current_tower_context()
  
      M = get_keras_model()
      logits = M(image)
      if ctx.is_main_training_tower:
          for op in M.updates:
              tf.add_to_collection(tf.GraphKeys.UPDATE_OPS, op)
  
      # build cost function by tensorflow
      cost = tf.nn.sparse_softmax_cross_entropy_with_logits(
          logits=logits, labels=label
      )
      cost = tf.reduce_mean(
          cost, name="cross_entropy_loss"
      )  # the average cross-entropy loss
  
      # for tensorpack validation
      acc = tf.cast(tf.nn.in_top_k(logits, label, 1), tf.float32)
      acc = tf.reduce_mean(acc, name="accuracy")
      summary.add_moving_summary(acc)
  
      wd_cost = tf.add_n(
          M.losses, name="regularize_loss"
      )  # this is how Keras manage regularizers
      cost = tf.add_n([wd_cost, cost], name="total_cost")
      summary.add_moving_summary(cost, wd_cost)
      return cost
  
file_path: tensorpack/examples/keras/mnist-keras.py
imports: import tensorflow
  from tensorflow import keras
  from contextlib import contextmanager
  from tensorpack import *
  from tensorpack.contrib.keras import KerasPhaseCallback
  from tensorpack.dataflow import dataset
  from tensorpack.utils.argtools import memoized
  from tensorpack.utils.gpu import get_num_gpu
  from tensorpack.tfutils.tower import get_current_tower_context
label_desc: Use image node_id 2 for calling the Model obj's underlying member method code with example usage: obj.build_graph(image, label) and returns: cost