Ejemplo n.º 1
0
    def _input_and_output_same_shape_helper(self, kernel_size):
        img_batch = tf.placeholder(tf.float32, shape=[None, 32, 32, 3])
        output_img_batch, _ = cyclegan.cyclegan_generator_resnet(
            img_batch, kernel_size=kernel_size)

        self.assertAllEqual(img_batch.shape.as_list(),
                            output_img_batch.shape.as_list())
Ejemplo n.º 2
0
 def test_generator_inference(self):
     """Check one inference step."""
     img_batch = tf.zeros([2, 32, 32, 3])
     model_output, _ = cyclegan.cyclegan_generator_resnet(img_batch)
     with self.test_session() as sess:
         sess.run(tf.global_variables_initializer())
         sess.run(model_output)
Ejemplo n.º 3
0
def generator(input_images):
    """Thin wrapper around CycleGAN generator to conform to the TFGAN API.

  Args:
    input_images: A batch of images to translate. Images should be normalized
      already. Shape is [batch, height, width, channels].

  Returns:
    Returns generated image batch.

  Raises:
    ValueError: If shape of last dimension (channels) is not defined.
  """
    input_images.shape.assert_has_rank(4)
    input_size = input_images.shape.as_list()
    channels = input_size[-1]
    if channels is None:
        raise ValueError('Last dimension shape must be known but is None: %s' %
                         input_size)
    with tf.contrib.framework.arg_scope(cyclegan.cyclegan_arg_scope()):
        output_images, _ = cyclegan.cyclegan_generator_resnet(
            input_images, num_outputs=channels)
    return output_images
Ejemplo n.º 4
0
    def test_generator_unknown_batch_dim(self):
        """Check that generator can take unknown batch dimension inputs."""
        img = tf.placeholder(tf.float32, shape=[None, 32, None, 3])
        output_imgs, _ = cyclegan.cyclegan_generator_resnet(img)

        self.assertAllEqual([None, 32, None, 3], output_imgs.shape.as_list())
Ejemplo n.º 5
0
 def _test_generator_graph_helper(self, shape):
     """Check that generator can take small and non-square inputs."""
     output_imgs, _ = cyclegan.cyclegan_generator_resnet(tf.ones(shape))
     self.assertAllEqual(shape, output_imgs.shape.as_list())