class_docstr: Residual Network.
class_docstr_tok: ["Residual","Network","."]
code: def body(self, features):
      hp = self.hparams
      block_fns = {
          "residual": residual_block,
          "bottleneck": bottleneck_block,
      }
      assert hp.block_fn in block_fns
      is_training = hp.mode == tf_estimator.ModeKeys.TRAIN
      if is_training:
          targets = features["targets_raw"]
  
      inputs = features["inputs"]
  
      data_format = "channels_last"
      if hp.use_nchw:
          # Convert from channels_last (NHWC) to channels_first (NCHW). This
          # provides a large performance boost on GPU.
          inputs = tf.transpose(inputs, [0, 3, 1, 2])
          data_format = "channels_first"
  
      inputs = conv2d_fixed_padding(
          inputs=inputs,
          filters=hp.filter_sizes[0],
          kernel_size=7,
          strides=1 if hp.is_cifar else 2,
          data_format=data_format,
      )
      inputs = tf.identity(inputs, "initial_conv")
      inputs = batch_norm_relu(
          inputs, is_training, data_format=data_format
      )
  
      if not hp.is_cifar:
          inputs = layers().MaxPooling2D(
              pool_size=3,
              strides=2,
              padding="SAME",
              data_format=data_format,
          )(inputs)
          inputs = tf.identity(inputs, "initial_max_pool")
  
      out = resnet_v2(
          inputs,
          block_fns[hp.block_fn],
          hp.layer_sizes,
          hp.filter_sizes,
          data_format,
          is_training=is_training,
          is_cifar=hp.is_cifar,
          use_td=hp.use_td,
          targeting_rate=hp.targeting_rate,
          keep_prob=hp.keep_prob,
          bottleneck_ratios=hp.bottleneck_ratios,
      )
  
      if hp.use_nchw:
          out = tf.transpose(out, [0, 2, 3, 1])
  
      if not hp.is_cifar:
          return out
  
      out = tf.reduce_mean(out, [1, 2])
      num_classes = self._problem_hparams.vocab_size["targets"]
      if hasattr(self._hparams, "vocab_divisor"):
          num_classes += (-num_classes) % self._hparams.vocab_divisor
      logits = layers().Dense(num_classes, name="logits")(out)
  
      losses = {"training": 0.0}
      if is_training:
          loss = tf.losses.sparse_softmax_cross_entropy(
              labels=tf.squeeze(targets), logits=logits
          )
          loss = tf.reduce_mean(loss)
  
          losses = {"training": loss}
  
      logits = tf.reshape(logits, [-1, 1, 1, 1, logits.shape[1]])
  
      return logits, losses
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from tensor2tensor.layers import common_hparams
  from tensor2tensor.layers import common_layers
  from tensor2tensor.utils import hparam
  from tensor2tensor.utils import registry
  from tensor2tensor.utils import t2t_model
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
label_desc: Use image node_id 1 for calling the Resnet obj's underlying member method code with example usage: obj.body(features) and returns: logits,  losses, out