(self)
Adds model summaries.
Adds model summaries.
Adds model summaries .
def add_summaries(self):
    """Adds model summaries."""
    config = self.config
    data_helper = self.data_helper

    def _add_waves_summary(name, waves, max_outputs):
      tf.summary.audio(name,
                       waves,
                       sample_rate=config['sample_rate'],
                       max_outputs=max_outputs)

    def _add_specgrams_summary(name, specgrams, max_outputs):
      tf.summary.image(
          name + '_m', specgrams[:, :, :, 0:1], max_outputs=max_outputs)
      tf.summary.image(
          name + '_p', specgrams[:, :, :, 1:2], max_outputs=max_outputs)

    fake_batch_size = config['fake_batch_size']
    real_batch_size = self.batch_size
    real_one_hot_labels = self.real_one_hot_labels
    num_tokens = int(real_one_hot_labels.shape[1])

    # When making prediction, use the ema smoothed generator vars by
    # `_custom_getter`.
    with self.load_scope:
      noises = train_util.make_latent_vectors(fake_batch_size, **config)
      one_hot_labels = util.make_ordered_one_hot_vectors(fake_batch_size,
                                                         num_tokens)

      fake_images = self.gan_model.generator_fn((noises, one_hot_labels))
      real_images = self.real_images

    # Set shapes
    image_shape = list(self.resolution_schedule.final_resolutions)
    n_ch = 2
    fake_images.set_shape([fake_batch_size] + image_shape + [n_ch])
    real_images.set_shape([real_batch_size] + image_shape + [n_ch])

    # Generate waves and summaries
    # Convert to audio
    fake_waves = data_helper.data_to_waves(fake_images)
    real_waves = data_helper.data_to_waves(real_images)
    # Wave summaries
    _add_waves_summary('fake_waves', fake_waves, fake_batch_size)
    _add_waves_summary('real_waves', real_waves, real_batch_size)
    # Spectrogram summaries
    if isinstance(data_helper, data_helpers.DataWaveHelper):
      fake_images_spec = data_helper.specgrams_helper.waves_to_specgrams(
          fake_waves)
      real_images_spec = data_helper.specgrams_helper.waves_to_specgrams(
          real_waves)
      _add_specgrams_summary('fake_data', fake_images_spec, fake_batch_size)
      _add_specgrams_summary('real_data', real_images_spec, real_batch_size)
    else:
      _add_specgrams_summary('fake_data', fake_images, fake_batch_size)
      _add_specgrams_summary('real_data', real_images, real_batch_size)
    tfgan.eval.add_gan_model_summaries(self.gan_model)
def add_summaries ( self ) : config = self . config data_helper = self . data_helper def _add_waves_summary ( name , waves , max_outputs ) : tf . summary . audio ( name , waves , sample_rate = config [ 'sample_rate' ] , max_outputs = max_outputs ) def _add_specgrams_summary ( name , specgrams , max_outputs ) : tf . summary . image ( name + '_m' , specgrams [ : , : , : , 0 : 1 ] , max_outputs = max_outputs ) tf . summary . image ( name + '_p' , specgrams [ : , : , : , 1 : 2 ] , max_outputs = max_outputs ) fake_batch_size = config [ 'fake_batch_size' ] real_batch_size = self . batch_size real_one_hot_labels = self . real_one_hot_labels num_tokens = int ( real_one_hot_labels . shape [ 1 ] ) # When making prediction, use the ema smoothed generator vars by # `_custom_getter`. with self . load_scope : noises = train_util . make_latent_vectors ( fake_batch_size , * * config ) one_hot_labels = util . make_ordered_one_hot_vectors ( fake_batch_size , num_tokens ) fake_images = self . gan_model . generator_fn ( ( noises , one_hot_labels ) ) real_images = self . real_images # Set shapes image_shape = list ( self . resolution_schedule . final_resolutions ) n_ch = 2 fake_images . set_shape ( [ fake_batch_size ] + image_shape + [ n_ch ] ) real_images . set_shape ( [ real_batch_size ] + image_shape + [ n_ch ] ) # Generate waves and summaries # Convert to audio fake_waves = data_helper . data_to_waves ( fake_images ) real_waves = data_helper . data_to_waves ( real_images ) # Wave summaries _add_waves_summary ( 'fake_waves' , fake_waves , fake_batch_size ) _add_waves_summary ( 'real_waves' , real_waves , real_batch_size ) # Spectrogram summaries if isinstance ( data_helper , data_helpers . DataWaveHelper ) : fake_images_spec = data_helper . specgrams_helper . waves_to_specgrams ( fake_waves ) real_images_spec = data_helper . specgrams_helper . waves_to_specgrams ( real_waves ) _add_specgrams_summary ( 'fake_data' , fake_images_spec , fake_batch_size ) _add_specgrams_summary ( 'real_data' , real_images_spec , real_batch_size ) else : _add_specgrams_summary ( 'fake_data' , fake_images , fake_batch_size ) _add_specgrams_summary ( 'real_data' , real_images , real_batch_size ) tfgan . eval . add_gan_model_summaries ( self . gan_model )