示例#1
0
    def top(self, body_output, _):
        """Transform inputs from model space to target space.

    Perform the Xception "Exit flow", consisting of a single residual block and
    two separable convolutional upscalings followed by global spatial average
    pooling.

    Args:
      body_output: A Tensor with shape [batch, ?, ?, body_output_size].
    Returns:
      a Tensors, each with shape [batch_size, ?, ?, vocab_size]
    """
        with tf.variable_scope(self.name):
            x = body_output

            # Assume input is a square with self._body_input_depth channels.
            if self._is_2d:
                length_float = tf.to_float(tf.shape(x)[1])
                spatial_dim_float = tf.sqrt(length_float)
                spatial_dim = tf.to_int32(spatial_dim_float)
                x = tf.reshape(
                    x, [-1, spatial_dim, spatial_dim, self._body_input_depth])
            x = common_layers.conv_block_downsample(x, self._kernel,
                                                    self._strides,
                                                    self._padding)
            x = tf.nn.relu(x)
            x = tf.reduce_mean(x, axis=[1, 2], keep_dims=True)
            res = common_layers.conv(x, self._vocab_size, (1, 1))
            return tf.expand_dims(res, 3)
 def testConv(self):
   x = np.random.rand(5, 7, 1, 11)
   with self.test_session() as session:
     y = common_layers.conv(tf.constant(x, dtype=tf.float32), 13, (3, 3))
     session.run(tf.global_variables_initializer())
     res = session.run(y)
   self.assertEqual(res.shape, (5, 5, 1, 13))
  def top(self, body_output, _):
    """Transform inputs from model space to target space.

    Perform the Xception "Exit flow", consisting of a single residual block and
    two separable convolutional upscalings followed by global spatial average
    pooling.

    Args:
      body_output: A Tensor with shape [batch, ?, ?, body_output_size].
    Returns:
      a Tensors, each with shape [batch_size, ?, ?, vocab_size]
    """
    with tf.variable_scope(self.name):
      x = body_output

      # Assume input is a square with self._body_input_depth channels.
      if self._is_2d:
        length_float = tf.to_float(tf.shape(x)[1])
        spatial_dim_float = tf.sqrt(length_float)
        spatial_dim = tf.to_int32(spatial_dim_float)
        x = tf.reshape(x,
                       [-1, spatial_dim, spatial_dim, self._body_input_depth])
      x = common_layers.conv_block_downsample(x, self._kernel, self._strides,
                                              self._padding)
      x = tf.nn.relu(x)
      x = tf.reduce_mean(x, axis=[1, 2], keep_dims=True)
      res = common_layers.conv(x, self._vocab_size, (1, 1))
      return tf.expand_dims(res, 3)
 def testConv(self):
     x = np.random.rand(5, 7, 1, 11)
     with self.test_session() as session:
         y = common_layers.conv(tf.constant(x, dtype=tf.float32), 13,
                                (3, 1))
         session.run(tf.global_variables_initializer())
         res = session.run(y)
     self.assertEqual(res.shape, (5, 5, 1, 13))
示例#5
0
 def targets_top_simple(self, body_output, _):
   # TODO(lukaszkaiser): work on a better way to generate large images.
   with tf.variable_scope(self.name):
     decompressed_inputs = common_layers.deconv_stride2_multistep(
         body_output,
         self._model_hparams.compress_steps,
         body_output.get_shape()[-1],
         name="deconv")
     return common_layers.conv(
         decompressed_inputs, self._vocab_size, (1, 1), padding="SAME")
 def top(self, body_output, _):
   # TODO(lukaszkaiser): work on a better way to generate large images.
   with tf.variable_scope(self.name):
     decompressed_inputs = common_layers.deconv_stride2_multistep(
         body_output,
         self._model_hparams.compress_steps,
         body_output.get_shape()[-1],
         name="deconv")
     return common_layers.conv(
         decompressed_inputs, self._vocab_size, (1, 1), padding="SAME")