class_docstr: ### Description
  
  ### Diagram
  
  ### Constraints
class_docstr_tok: ["#","#","#","Description","#","#","#","Diagram","#","#","#","Constraints"]
docstr: :param image: tensor, input image to distriminator
  :param is_training: boolean, True if network is in training mode
  :return: tensor, classification logits
docstr_tok: [":","param","image",":","tensor",",","input","image","to","distriminator",":","param","is_training",":","boolean",",","True","if","network","is","in","training","mode",":","return",":","tensor",",","classification","logits"]
code: def layer_op(self, image, is_training):
      """
  
      :param image: tensor, input image to distriminator
      :param is_training: boolean, True if network is in training mode
      :return: tensor, classification logits
      """
      batch_size = image.shape.as_list()[0]
      spatial_rank = len(image.shape) - 2
      image_channels = image.shape.as_list()[-1]
      acti_func = tf.nn.relu
      dropout_func = lambda x: tf.nn.dropout(x, 0.5)
      norm_func = tf.contrib.layers.batch_norm
      downscale = ["resize", "conv_stride"][0]
      if spatial_rank == 2:
          conv_func = tf.nn.conv2d
          if downscale == "conv_stride":
              conv_s_unit = lambda x, W: acti_func(
                  norm_func(
                      conv_func(
                          x, W, [1] + [2] * spatial_rank + [1], "SAME"
                      )
                  )
              )
          else:
              conv_s_unit = lambda x, W: acti_func(
                  norm_func(
                      conv_func(
                          tf.image.resize_images(
                              x,
                              [
                                  x.shape.as_list()[1] // 2,
                                  x.shape.as_list()[2] // 2,
                              ],
                          ),
                          W,
                          [1] + [1] * spatial_rank + [1],
                          "SAME",
                      )
                  )
              )
      elif spatial_rank in [3]:
          conv_func = tf.nn.conv3d
          if downscale == "conv_stride":
              conv_s_unit = lambda x, W: acti_func(
                  norm_func(
                      conv_func(
                          x, W, [1] + [2] * spatial_rank + [1], "SAME"
                      )
                  )
              )
          else:
  
              def resize3(x, sz):
                  r1 = tf.image.resize_images(
                      tf.reshape(x, x.shape.as_list()[:3] + [-1]),
                      sz[1:3],
                  )
                  r2 = tf.image.resize_images(
                      tf.reshape(
                          r1,
                          [
                              sz[0],
                              sz[1] * sz[2],
                              x.shape.as_list()[3],
                              -1,
                          ],
                      ),
                      [sz[1] * sz[2], sz[3]],
                  )
                  return tf.reshape(
                      r2, sz[:4] + [x.shape.as_list()[-1]]
                  )
  
              conv_s_unit = lambda x, W: acti_func(
                  norm_func(
                      conv_func(
                          resize3(
                              x,
                              [
                                  a // b
                                  for a, b in zip(
                                      x.shape.as_list(), [1, 2, 2, 2, 1]
                                  )
                              ],
                          ),
                          W,
                          [1] + [1] * spatial_rank + [1],
                          "SAME",
                      )
                  )
              )
      conv_unit = lambda x, W: acti_func(
          norm_func(
              conv_func(x, W, [1] + [1] * spatial_rank + [1], "SAME")
          )
      )
      down_sample_unit = lambda x, Ws, W: conv_s_unit(
          conv_unit(x, W), Ws
      )
      kernel_size = [3] * spatial_rank
      for it in range(len(self._layer_channels) - 1):
          if it == 0:
              W = tf.get_variable(
                  "D_W{}".format(it),
                  shape=kernel_size
                  + [image_channels, self._layer_channels[it]],
                  initializer=self.initializers["w"],
              )
          else:
              W = tf.get_variable(
                  "D_W{}".format(it),
                  shape=kernel_size
                  + [
                      self._layer_channels[it],
                      self._layer_channels[it],
                  ],
                  initializer=self.initializers["w"],
              )
          Ws = tf.get_variable(
              "D_Ws{}".format(it),
              shape=kernel_size
              + [
                  self._layer_channels[it],
                  self._layer_channels[it + 1],
              ],
              initializer=self.initializers["w"],
          )
          image = down_sample_unit(image, Ws, W)
      logits = tf.layers.dense(
          tf.reshape(image, [batch_size, -1]),
          1,
          activation=None,
          use_bias=True,
      )
      return logits
  
file_path: NiftyNet/niftynet/network/simple_gan.py
imports: from __future__ import absolute_import, print_function
  import tensorflow
  import numpy
  from niftynet.layer.base_layer import TrainableLayer
label_desc: Use image node_id 2 for calling the ImageDiscriminator obj's underlying member method code with example usage: obj.layer_op(image, is_training) and returns: logits, tf