Exemplo n.º 1
0
def add_gan_model_image_summaries(gan_model, grid_size=10):
    """Adds image summaries for real and fake images.

  Args:
    gan_model: A GANModel tuple.
    grid_size: The size of an image grid.

  Raises:
    ValueError: If real and generated data aren't images.
  """
    _assert_is_image(gan_model.real_data)
    _assert_is_image(gan_model.generated_data)

    num_images = grid_size**2
    real_image_shape = gan_model.real_data.shape.as_list()[1:3]
    generated_image_shape = gan_model.generated_data.shape.as_list()[1:3]
    real_channels = gan_model.real_data.shape.as_list()[3]
    generated_channels = gan_model.generated_data.shape.as_list()[3]

    summary.image('real_data',
                  eval_utils.image_grid(gan_model.real_data[:num_images],
                                        grid_shape=(grid_size, grid_size),
                                        image_shape=real_image_shape,
                                        num_channels=real_channels),
                  max_outputs=1)
    summary.image('generated_data',
                  eval_utils.image_grid(gan_model.generated_data[:num_images],
                                        grid_shape=(grid_size, grid_size),
                                        image_shape=generated_image_shape,
                                        num_channels=generated_channels),
                  max_outputs=1)
    add_gan_model_summaries(gan_model)
Exemplo n.º 2
0
def add_gan_model_image_summaries(gan_model, grid_size=4, model_summaries=True):
  """Adds image summaries for real and fake images.

  Args:
    gan_model: A GANModel tuple.
    grid_size: The size of an image grid.
    model_summaries: Also add summaries of the model.

  Raises:
    ValueError: If real and generated data aren't images.
  """
  if isinstance(gan_model, namedtuples.CycleGANModel):
    saved_params = locals()
    saved_params.pop('gan_model', None)
    with ops.name_scope('cyclegan_x2y_image_summaries'):
      add_gan_model_image_summaries(gan_model.model_x2y, **saved_params)
    with ops.name_scope('cyclegan_y2x_image_summaries'):
      add_gan_model_image_summaries(gan_model.model_y2x, **saved_params)
    return

  _assert_is_image(gan_model.real_data)
  _assert_is_image(gan_model.generated_data)

  num_images = grid_size ** 2
  real_image_shape = gan_model.real_data.shape.as_list()[1:3]
  generated_image_shape = gan_model.generated_data.shape.as_list()[1:3]
  real_channels = gan_model.real_data.shape.as_list()[3]
  generated_channels = gan_model.generated_data.shape.as_list()[3]

  summary.image(
      'real_data',
      eval_utils.image_grid(
          gan_model.real_data[:num_images],
          grid_shape=(grid_size, grid_size),
          image_shape=real_image_shape,
          num_channels=real_channels),
      max_outputs=1)
  summary.image(
      'generated_data',
      eval_utils.image_grid(
          gan_model.generated_data[:num_images],
          grid_shape=(grid_size, grid_size),
          image_shape=generated_image_shape,
          num_channels=generated_channels),
      max_outputs=1)

  if model_summaries:
    add_gan_model_summaries(gan_model)
def add_gan_model_image_summaries(gan_model,
                                  grid_size=4,
                                  model_summaries=True):
    """Adds image summaries for real and fake images.

  Args:
    gan_model: A GANModel tuple.
    grid_size: The size of an image grid.
    model_summaries: Also add summaries of the model.

  Raises:
    ValueError: If real and generated data aren't images.
  """
    if isinstance(gan_model, namedtuples.CycleGANModel):
        saved_params = locals()
        saved_params.pop('gan_model', None)
        with ops.name_scope('cyclegan_x2y_image_summaries'):
            add_gan_model_image_summaries(gan_model.model_x2y, **saved_params)
        with ops.name_scope('cyclegan_y2x_image_summaries'):
            add_gan_model_image_summaries(gan_model.model_y2x, **saved_params)
        return

    _assert_is_image(gan_model.real_data)
    _assert_is_image(gan_model.generated_data)

    num_images = grid_size**2
    real_image_shape = gan_model.real_data.shape.as_list()[1:3]
    generated_image_shape = gan_model.generated_data.shape.as_list()[1:3]
    real_channels = gan_model.real_data.shape.as_list()[3]
    generated_channels = gan_model.generated_data.shape.as_list()[3]

    summary.image('real_data',
                  eval_utils.image_grid(gan_model.real_data[:num_images],
                                        grid_shape=(grid_size, grid_size),
                                        image_shape=real_image_shape,
                                        num_channels=real_channels),
                  max_outputs=1)
    summary.image('generated_data',
                  eval_utils.image_grid(gan_model.generated_data[:num_images],
                                        grid_shape=(grid_size, grid_size),
                                        image_shape=generated_image_shape,
                                        num_channels=generated_channels),
                  max_outputs=1)

    if model_summaries:
        add_gan_model_summaries(gan_model)
Exemplo n.º 4
0
def add_gan_model_image_summaries(gan_model, grid_size=4, model_summaries=True):
  """Adds image summaries for real and fake images.

  Args:
    gan_model: A GANModel tuple.
    grid_size: The size of an image grid.
    model_summaries: Also add summaries of the model.

  Raises:
    ValueError: If real and generated data aren't images.
  """
  if isinstance(gan_model, namedtuples.CycleGANModel):
    raise ValueError(
        '`add_gan_model_image_summaries` does not take CycleGANModels. Please '
        'use `add_cyclegan_image_summaries` instead.')
  _assert_is_image(gan_model.real_data)
  _assert_is_image(gan_model.generated_data)

  num_images = grid_size ** 2
  real_image_shape = gan_model.real_data.shape.as_list()[1:3]
  generated_image_shape = gan_model.generated_data.shape.as_list()[1:3]
  real_channels = gan_model.real_data.shape.as_list()[3]
  generated_channels = gan_model.generated_data.shape.as_list()[3]

  summary.image(
      'real_data',
      eval_utils.image_grid(
          gan_model.real_data[:num_images],
          grid_shape=(grid_size, grid_size),
          image_shape=real_image_shape,
          num_channels=real_channels),
      max_outputs=1)
  summary.image(
      'generated_data',
      eval_utils.image_grid(
          gan_model.generated_data[:num_images],
          grid_shape=(grid_size, grid_size),
          image_shape=generated_image_shape,
          num_channels=generated_channels),
      max_outputs=1)

  if model_summaries:
    add_gan_model_summaries(gan_model)
Exemplo n.º 5
0
def add_gan_model_image_summaries(gan_model, grid_size=4, model_summaries=True):
  """Adds image summaries for real and fake images.

  Args:
    gan_model: A GANModel tuple.
    grid_size: The size of an image grid.
    model_summaries: Also add summaries of the model.

  Raises:
    ValueError: If real and generated data aren't images.
  """
  if isinstance(gan_model, namedtuples.CycleGANModel):
    raise ValueError(
        '`add_gan_model_image_summaries` does not take CycleGANModels. Please '
        'use `add_cyclegan_image_summaries` instead.')
  _assert_is_image(gan_model.real_data)
  _assert_is_image(gan_model.generated_data)

  num_images = grid_size ** 2
  real_image_shape = gan_model.real_data.shape.as_list()[1:3]
  generated_image_shape = gan_model.generated_data.shape.as_list()[1:3]
  real_channels = gan_model.real_data.shape.as_list()[3]
  generated_channels = gan_model.generated_data.shape.as_list()[3]

  summary.image(
      'real_data',
      eval_utils.image_grid(
          gan_model.real_data[:num_images],
          grid_shape=(grid_size, grid_size),
          image_shape=real_image_shape,
          num_channels=real_channels),
      max_outputs=1)
  summary.image(
      'generated_data',
      eval_utils.image_grid(
          gan_model.generated_data[:num_images],
          grid_shape=(grid_size, grid_size),
          image_shape=generated_image_shape,
          num_channels=generated_channels),
      max_outputs=1)

  if model_summaries:
    add_gan_model_summaries(gan_model)
Exemplo n.º 6
0
    def build(self, img_a, img_b, labels):
        self.__call__(img_a, img_b, labels)

        # Add summaries
        num_images = self.grid_size**2
        image_shape = self.img_a.get_shape().as_list()[1:3]

        summary.image('image_a',
                      eval_utils.image_grid(self.img_a[:num_images, :, :, :3],
                                            grid_shape=(self.grid_size,
                                                        self.grid_size),
                                            image_shape=image_shape,
                                            num_channels=3),
                      max_outputs=1)

        summary.image('image_b',
                      eval_utils.image_grid(self.img_b[:num_images, :, :, :3],
                                            grid_shape=(self.grid_size,
                                                        self.grid_size),
                                            image_shape=image_shape,
                                            num_channels=3),
                      max_outputs=1)
Exemplo n.º 7
0
def my_summary_image(name, tensor, grid_size=2):
    num_images = grid_size**2
    inp_image_shape = tensor.shape.as_list()[1:3]
    inp_channels = tensor.shape.as_list()[3]
    tensor = (tensor + 1) / 2
    tensor = tf.image.convert_image_dtype(tensor,
                                          dtype=tf.uint8,
                                          saturate=True)
    tf.summary.image(name,
                     eval_utils.image_grid(tensor[:num_images],
                                           grid_shape=(grid_size, grid_size),
                                           image_shape=inp_image_shape,
                                           num_channels=inp_channels),
                     max_outputs=1)
Exemplo n.º 8
0
def add_gan_model_image_summaries(gan_model, grid_size=10):
  """Adds image summaries for real and fake images.

  Args:
    gan_model: A GANModel tuple.
    grid_size: The size of an image grid.

  Raises:
    ValueError: If real and generated data aren't images.
  """
  _assert_is_image(gan_model.real_data)
  _assert_is_image(gan_model.generated_data)

  num_images = grid_size ** 2
  real_image_shape = gan_model.real_data.shape.as_list()[1:3]
  generated_image_shape = gan_model.generated_data.shape.as_list()[1:3]
  real_channels = gan_model.real_data.shape.as_list()[3]
  generated_channels = gan_model.generated_data.shape.as_list()[3]

  summary.image(
      'real_data',
      eval_utils.image_grid(
          gan_model.real_data[:num_images],
          grid_shape=(grid_size, grid_size),
          image_shape=real_image_shape,
          num_channels=real_channels),
      max_outputs=1)
  summary.image(
      'generated_data',
      eval_utils.image_grid(
          gan_model.generated_data[:num_images],
          grid_shape=(grid_size, grid_size),
          image_shape=generated_image_shape,
          num_channels=generated_channels),
      max_outputs=1)
  add_gan_model_summaries(gan_model)