def _build(self, inputs):
    """Connects the _ConvNDTranspose module into the graph.

    If this is not the first time the module has been connected to the graph,
    the input Tensor provided here must have the same final N dimensions, in
    order for the existing variables to be the correct size for the
    multiplication. The batch size may differ for each connection.

    Args:
      inputs: A Tensor of shape `data_format` and of type
          `tf.float16`, `tf.bfloat16` or `tf.float32`.

    Returns:
      A Tensor of shape `data_format` and of type `tf.float16`, `tf.bfloat16`
          or `tf.float32`.

    Raises:
      ValueError: If connecting the module into the graph any time after the
          first time and the inferred size of the input does not match previous
          invocations.
      base.IncompatibleShapeError: If the input tensor has the wrong number
          of dimensions.
      base.UnderspecifiedError: If the channel dimension of `inputs` isn't
          defined.
      base.IncompatibleShapeError: If `output_shape` is an iterable and is not
          in the format `(out_height, out_width)`.
      TypeError: If input Tensor dtype is not compatible with either
          `tf.float16`, `tf.bfloat16` or `tf.float32`.
    """
    _verify_inputs(inputs, self._channel_index, self._data_format)
    self._input_shape = tuple(inputs.get_shape().as_list())
    self._input_channels = self._input_shape[self._channel_index]

    # First, figure out what the non-(N,C) dims will be.
    if self._use_default_output_shape:
      def _default_transpose_size_wrapper():
        if self._data_format.startswith("NC"):
          input_size = self._input_shape[2:]
          stride = self.stride[2:]
        else:  # self._data_format == N*WC
          input_size = self._input_shape[1:-1]
          stride = self.stride[1:-1]
        return _default_transpose_size(input_size,
                                       stride,
                                       kernel_shape=self._kernel_shape,
                                       padding=self._padding)

      self._output_shape = _default_transpose_size_wrapper

    if len(self.output_shape) != self._n:
      raise base.IncompatibleShapeError(
          "Output shape must have rank {}, but instead was {}".format(
              self._n, len(self.output_shape)))

    # Now, construct the size of the output, including the N + C dims.
    output_shape = self._infer_all_output_dims(inputs)

    self._w = self._construct_w(inputs)

    if self._n == 1:
      # Add a dimension for the height.
      if self._data_format == DATA_FORMAT_NWC:
        h_dim = 1
        two_dim_conv_data_format = DATA_FORMAT_NHWC
      else:  # self._data_format == DATA_FORMAT_NCW
        h_dim = 2
        two_dim_conv_data_format = DATA_FORMAT_NCHW
      inputs = tf.expand_dims(inputs, h_dim)
      two_dim_conv_stride = self.stride[:h_dim] + (1,) + self.stride[h_dim:]
      outputs = tf.nn.conv2d_transpose(inputs,
                                       self._w,
                                       output_shape,
                                       strides=two_dim_conv_stride,
                                       padding=self._padding,
                                       data_format=two_dim_conv_data_format)
      # Remove the height dimension to return a 3D tensor.
      outputs = tf.squeeze(outputs, [h_dim])
    elif self._n == 2:
      outputs = tf.nn.conv2d_transpose(inputs,
                                       self._w,
                                       output_shape,
                                       strides=self._stride,
                                       padding=self._padding,
                                       data_format=self._data_format)
    else:
      outputs = tf.nn.conv3d_transpose(inputs,
                                       self._w,
                                       output_shape,
                                       strides=self._stride,
                                       padding=self._padding,
                                       data_format=self._data_format)

    if self._use_bias:
      self._b, outputs = _apply_bias(
          inputs, outputs, self._channel_index, self._data_format,
          self._output_channels, self._initializers, self._partitioners,
          self._regularizers)

    outputs = self._recover_shape_information(inputs, outputs)
    return outputs
def _build ( self , inputs ) : _verify_inputs ( inputs , self . _channel_index , self . _data_format ) self . _input_shape = tuple ( inputs . get_shape ( ) . as_list ( ) ) self . _input_channels = self . _input_shape [ self . _channel_index ] if self . _use_default_output_shape : def _default_transpose_size_wrapper ( ) : if self . _data_format . startswith ( "NC" ) : input_size = self . _input_shape [ 2 : ] stride = self . stride [ 2 : ] else : input_size = self . _input_shape [ 1 : - 1 ] stride = self . stride [ 1 : - 1 ] return _default_transpose_size ( input_size , stride , kernel_shape = self . _kernel_shape , padding = self . _padding ) self . _output_shape = _default_transpose_size_wrapper if len ( self . output_shape ) != self . _n : raise base . IncompatibleShapeError ( "Output shape must have rank {}, but instead was {}" . format ( self . _n , len ( self . output_shape ) ) ) output_shape = self . _infer_all_output_dims ( inputs ) self . _w = self . _construct_w ( inputs ) if self . _n == 1 : if self . _data_format == DATA_FORMAT_NWC : h_dim = 1 two_dim_conv_data_format = DATA_FORMAT_NHWC else : h_dim = 2 two_dim_conv_data_format = DATA_FORMAT_NCHW inputs = tf . expand_dims ( inputs , h_dim ) two_dim_conv_stride = self . stride [ : h_dim ] + ( 1 , ) + self . stride [ h_dim : ] outputs = tf . nn . conv2d_transpose ( inputs , self . _w , output_shape , strides = two_dim_conv_stride , padding = self . _padding , data_format = two_dim_conv_data_format ) outputs = tf . squeeze ( outputs , [ h_dim ] ) elif self . _n == 2 : outputs = tf . nn . conv2d_transpose ( inputs , self . _w , output_shape , strides = self . _stride , padding = self . _padding , data_format = self . _data_format ) else : outputs = tf . nn . conv3d_transpose ( inputs , self . _w , output_shape , strides = self . _stride , padding = self . _padding , data_format = self . _data_format ) if self . _use_bias : self . _b , outputs = _apply_bias ( inputs , outputs , self . _channel_index , self . _data_format , self . _output_channels , self . _initializers , self . _partitioners , self . _regularizers ) outputs = self . _recover_shape_information ( inputs , outputs ) return outputs
Connects the _ConvNDTranspose module into the graph.

    If this is not the first time the module has been connected to the graph,
    the input Tensor provided here must have the same final N dimensions, in
    order for the existing variables to be the correct size for the
    multiplication. The batch size may differ for each connection.

    Args:
      inputs: A Tensor of shape `data_format` and of type
          `tf.float16`, `tf.bfloat16` or `tf.float32`.

    Returns:
      A Tensor of shape `data_format` and of type `tf.float16`, `tf.bfloat16`
          or `tf.float32`.

    Raises:
      ValueError: If connecting the module into the graph any time after the
          first time and the inferred size of the input does not match previous
          invocations.
      base.IncompatibleShapeError: If the input tensor has the wrong number
          of dimensions.
      base.UnderspecifiedError: If the channel dimension of `inputs` isn't
          defined.
      base.IncompatibleShapeError: If `output_shape` is an iterable and is not
          in the format `(out_height, out_width)`.
      TypeError: If input Tensor dtype is not compatible with either
          `tf.float16`, `tf.bfloat16` or `tf.float32`.