class_docstr: ConvNet model.
class_docstr_tok: ["ConvNet","model","."]
docstr: Residual unit with 2 sub layers, using Plan A for shortcut connection.
docstr_tok: ["Residual","unit","with","2","sub","layers",",","using","Plan","A","for","shortcut","connection","."]
code: def _residual_layer(
      self,
      x,
      kernel_size,
      in_filter,
      out_filter,
      stride,
      activate_before_residual=False,
  ):
      """Residual unit with 2 sub layers, using Plan A for shortcut connection."""
  
      del activate_before_residual
      with tf.name_scope("residual_layer") as name_scope:
          in_filter = int(in_filter)
          out_filter = int(out_filter)
          orig_x = x
          x = self._myConv(x, kernel_size, out_filter, stride)
          x = self._conv(x, kernel_size, out_filter, 1)
          x = self._batch_norm(x)
  
          # Pad for different number of filters
          if out_filter != in_filter:
              pad_diff = abs(out_filter - in_filter)
              pad1 = pad_diff // 2
              pad2 = pad_diff - pad1
              if out_filter > in_filter:
                  orig_x = self._myAvgPool(orig_x, stride, stride)
                  if self._data_format == "channels_first":
                      orig_x = tf.pad(
                          orig_x, [[0, 0], [pad1, pad2], [0, 0], [0, 0]]
                      )
                  else:
                      orig_x = tf.pad(
                          orig_x, [[0, 0], [0, 0], [0, 0], [pad1, pad2]]
                      )
              elif in_filter > out_filter:
                  x = self._myAvgPool(x, stride, stride)
                  if self._data_format == "channels_first":
                      x = tf.pad(
                          x, [[0, 0], [pad1, pad2], [0, 0], [0, 0]]
                      )
                  else:
                      x = tf.pad(
                          x, [[0, 0], [0, 0], [0, 0], [pad1, pad2]]
                      )
  
          # Also pad for different image heights and widths (due to pooling)
          orig_xshape = orig_x.get_shape().as_list()
          xshape = x.get_shape().as_list()
          if self._data_format == "channels_first":
              # Pad height, case: channels_first
              oldHeight = int(orig_xshape[2])
              newHeight = int(xshape[2])
              pad_height_diff = abs(newHeight - oldHeight)
              pad_height1 = pad_height_diff // 2
              pad_height2 = pad_height_diff - pad_height1
              if newHeight < oldHeight:
                  x = tf.pad(
                      x,
                      [
                          [0, 0],
                          [0, 0],
                          [pad_height1, pad_height2],
                          [0, 0],
                      ],
                  )
              elif oldHeight < newHeight:
                  orig_x = tf.pad(
                      orig_x,
                      [
                          [0, 0],
                          [0, 0],
                          [pad_height1, pad_height2],
                          [0, 0],
                      ],
                  )
              # Pad width, case: channels_first
              oldWidth = int(orig_xshape[3])
              newWidth = int(xshape[3])
              pad_width_diff = abs(newWidth - oldWidth)
              pad_width1 = pad_width_diff // 2
              pad_width2 = pad_width_diff - pad_width1
              if newWidth < oldWidth:
                  x = tf.pad(
                      x,
                      [
                          [0, 0],
                          [0, 0],
                          [0, 0],
                          [pad_width1, pad_width2],
                      ],
                  )
              elif oldWidth < newWidth:
                  orig_x = tf.pad(
                      orig_x,
                      [
                          [0, 0],
                          [0, 0],
                          [0, 0],
                          [pad_width1, pad_width2],
                      ],
                  )
          else:
              # Pad height, case: channels_last
              oldHeight = int(orig_xshape[1])
              newHeight = int(xshape[1])
              pad_height_diff = abs(newHeight - oldHeight)
              pad_height1 = pad_height_diff // 2
              pad_height2 = pad_height_diff - pad_height1
              if newHeight < oldHeight:
                  x = tf.pad(
                      x,
                      [
                          [0, 0],
                          [pad_height1, pad_height2],
                          [0, 0],
                          [0, 0],
                      ],
                  )
              elif oldHeight < newHeight:
                  orig_x = tf.pad(
                      orig_x,
                      [
                          [0, 0],
                          [pad_height1, pad_height2],
                          [0, 0],
                          [0, 0],
                      ],
                  )
              # Pad width, case: channels_last
              oldWidth = int(orig_xshape[2])
              newWidth = int(xshape[2])
              pad_width_diff = abs(newWidth - oldWidth)
              pad_width1 = pad_width_diff // 2
              pad_width2 = pad_width_diff - pad_width1
              if newWidth < oldWidth:
                  x = tf.pad(
                      x,
                      [
                          [0, 0],
                          [0, 0],
                          [pad_width1, pad_width2],
                          [0, 0],
                      ],
                  )
              elif oldWidth < newWidth:
                  orig_x = tf.pad(
                      orig_x,
                      [
                          [0, 0],
                          [0, 0],
                          [pad_width1, pad_width2],
                          [0, 0],
                      ],
                  )
  
          x = self._relu(tf.add(x, orig_x))
          tf.logging.info(
              "image after unit %s: %s", name_scope, x.get_shape()
          )
          return x
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import tensorflow
label_desc: Use image node_id 17 for calling the ConvNet obj's underlying member method code with example usage: obj._residual_layer(x, kernel_size, in_filter, out_filter, stride, activate_before_residual) and returns: x