class_docstr: PatchDiscriminator architecture.
  
  Implemented as a compare_gan layer. This has the benefit that we can use
  spectral_norm from that framework.
class_docstr_tok: ["PatchDiscriminator","architecture",".","Implemented","as","a","compare_gan","layer",".","This","has","the","benefit","that","we","can","use","spectral_norm","from","that","framework","."]
docstr: Overwriting compare_gan's apply as we only need `x`.
docstr_tok: ["Overwriting","compare_gan","'s","apply","as","we","only","need","`","x","`","."]
code: def apply(self, x):
      """Overwriting compare_gan's apply as we only need `x`."""
      if not isinstance(x, tuple) or len(x) != 2:
          raise ValueError("Expected 2-tuple, got {}".format(x))
      x, latent = x
      x_shape = tf.shape(x)
  
      # Upscale and fuse latent.
      latent = arch_ops.conv2d(
          latent,
          12,
          3,
          3,
          1,
          1,
          name="latent",
          use_sn=self._spectral_norm,
      )
      latent = arch_ops.lrelu(latent, leak=0.2)
      latent = tf.image.resize(
          latent,
          [x_shape[1], x_shape[2]],
          tf.image.ResizeMethod.NEAREST_NEIGHBOR,
      )
      x = tf.concat([x, latent], axis=-1)
  
      # The discriminator:
      k = 4
      net = arch_ops.conv2d(
          x,
          self._num_filters_base,
          k,
          k,
          2,
          2,
          name="d_conv_head",
          use_sn=self._spectral_norm,
      )
      net = arch_ops.lrelu(net, leak=0.2)
  
      num_filters = self._num_filters_base
      for i in range(self._num_layers - 1):
          num_filters = min(num_filters * 2, 512)
          net = arch_ops.conv2d(
              net,
              num_filters,
              k,
              k,
              2,
              2,
              name=f"d_conv_{i}",
              use_sn=self._spectral_norm,
          )
          net = arch_ops.lrelu(net, leak=0.2)
  
      num_filters = min(num_filters * 2, 512)
      net = arch_ops.conv2d(
          net,
          num_filters,
          k,
          k,
          1,
          1,
          name="d_conv_a",
          use_sn=self._spectral_norm,
      )
      net = arch_ops.lrelu(net, leak=0.2)
  
      # Final 1x1 conv that maps to 1 Channel
      net = arch_ops.conv2d(
          net,
          1,
          k,
          k,
          1,
          1,
          name="d_conv_b",
          use_sn=self._spectral_norm,
      )
  
      out_logits = tf.reshape(
          net, [-1, 1]
      )  # Reshape all into batch dimension.
      out = tf.nn.sigmoid(out_logits)
  
      return DiscOutAll(out, out_logits)
  
imports: import collections
  from compare_gan.architectures import abstract_arch
  from compare_gan.architectures import arch_ops
  import numpy
  import tensorflow.compat.v1
  import tensorflow_compression
  from hific.helpers import ModelMode
label_desc: Use image node_id 3 for calling the _PatchDiscriminatorCompareGANImpl obj's underlying member method code with example usage: obj.apply(x) and returns: DiscOutAll