Removed visualization of latent space
Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
@ -97,15 +97,14 @@ def _run_one_epoch_simple(dataset: tf.data.Dataset,
|
|||||||
dtype=tf.float32)
|
dtype=tf.float32)
|
||||||
|
|
||||||
for x in dataset:
|
for x in dataset:
|
||||||
reconstruction_loss, x_decoded, z = _run_enc_dec_step_simple(encoder=encoder,
|
reconstruction_loss, x_decoded = _run_enc_dec_step_simple(encoder=encoder,
|
||||||
decoder=decoder,
|
decoder=decoder,
|
||||||
inputs=x,
|
inputs=x,
|
||||||
global_step=global_step)
|
global_step=global_step)
|
||||||
enc_dec_loss_avg(reconstruction_loss)
|
enc_dec_loss_avg(reconstruction_loss)
|
||||||
|
|
||||||
if int(global_step % train.LOG_FREQUENCY) == 0:
|
if int(global_step % train.LOG_FREQUENCY) == 0:
|
||||||
comparison = K.concatenate([x[:int(batch_size / 2)], x_decoded[:int(batch_size / 2)],
|
comparison = K.concatenate([x[:int(batch_size / 2)], x_decoded[:int(batch_size / 2)]], axis=0)
|
||||||
z[:int(batch_size / 2)]], axis=0)
|
|
||||||
grid = util.prepare_image(comparison.cpu(), nrow=int(batch_size / 2))
|
grid = util.prepare_image(comparison.cpu(), nrow=int(batch_size / 2))
|
||||||
summary_ops_v2.image(name='reconstruction',
|
summary_ops_v2.image(name='reconstruction',
|
||||||
tensor=K.expand_dims(grid, axis=0), max_images=1,
|
tensor=K.expand_dims(grid, axis=0), max_images=1,
|
||||||
@ -126,7 +125,7 @@ def _run_one_epoch_simple(dataset: tf.data.Dataset,
|
|||||||
|
|
||||||
def _run_enc_dec_step_simple(encoder: model.Encoder, decoder: model.Decoder,
|
def _run_enc_dec_step_simple(encoder: model.Encoder, decoder: model.Decoder,
|
||||||
inputs: tf.Tensor,
|
inputs: tf.Tensor,
|
||||||
global_step: tf.Variable) -> Tuple[tf.Tensor, tf.Tensor, tf.Tensor]:
|
global_step: tf.Variable) -> Tuple[tf.Tensor, tf.Tensor]:
|
||||||
"""
|
"""
|
||||||
Runs the encoder and decoder jointly for one step (one batch).
|
Runs the encoder and decoder jointly for one step (one batch).
|
||||||
|
|
||||||
@ -148,8 +147,4 @@ def _run_enc_dec_step_simple(encoder: model.Encoder, decoder: model.Decoder,
|
|||||||
summary_ops_v2.scalar(name='reconstruction_loss', tensor=reconstruction_loss,
|
summary_ops_v2.scalar(name='reconstruction_loss', tensor=reconstruction_loss,
|
||||||
step=global_step)
|
step=global_step)
|
||||||
|
|
||||||
input_shape = tf.shape(inputs)
|
return reconstruction_loss, x_decoded
|
||||||
z_reshaped = tf.reshape(z, [-1, input_shape[1], input_shape[2], 1])
|
|
||||||
z_concatenated = K.concatenate((z_reshaped, z_reshaped, z_reshaped), axis=3)
|
|
||||||
|
|
||||||
return reconstruction_loss, x_decoded, z_concatenated
|
|
||||||
|
|||||||
@ -161,17 +161,16 @@ def _train_one_epoch_simple(epoch: int,
|
|||||||
print("learning rate change!")
|
print("learning rate change!")
|
||||||
|
|
||||||
for x in dataset:
|
for x in dataset:
|
||||||
reconstruction_loss, x_decoded, z = _train_enc_dec_step_simple(encoder=encoder,
|
reconstruction_loss, x_decoded = _train_enc_dec_step_simple(encoder=encoder,
|
||||||
decoder=decoder,
|
decoder=decoder,
|
||||||
optimizer=enc_dec_optimizer,
|
optimizer=enc_dec_optimizer,
|
||||||
inputs=x,
|
inputs=x,
|
||||||
global_step_enc_dec=global_step_enc_dec,
|
global_step_enc_dec=global_step_enc_dec,
|
||||||
global_step=global_step)
|
global_step=global_step)
|
||||||
enc_dec_loss_avg(reconstruction_loss)
|
enc_dec_loss_avg(reconstruction_loss)
|
||||||
|
|
||||||
if int(global_step % LOG_FREQUENCY) == 0:
|
if int(global_step % LOG_FREQUENCY) == 0:
|
||||||
comparison = K.concatenate([x[:int(batch_size / 2)], x_decoded[:int(batch_size / 2)],
|
comparison = K.concatenate([x[:int(batch_size / 2)], x_decoded[:int(batch_size / 2)]], axis=0)
|
||||||
z[:int(batch_size/2)]], axis=0)
|
|
||||||
grid = util.prepare_image(comparison.cpu(), nrow=int(batch_size/2))
|
grid = util.prepare_image(comparison.cpu(), nrow=int(batch_size/2))
|
||||||
summary_ops_v2.image(name='reconstruction',
|
summary_ops_v2.image(name='reconstruction',
|
||||||
tensor=K.expand_dims(grid, axis=0), max_images=1,
|
tensor=K.expand_dims(grid, axis=0), max_images=1,
|
||||||
@ -194,8 +193,7 @@ def _train_enc_dec_step_simple(encoder: model.Encoder, decoder: model.Decoder,
|
|||||||
optimizer: tf.train.Optimizer,
|
optimizer: tf.train.Optimizer,
|
||||||
inputs: tf.Tensor,
|
inputs: tf.Tensor,
|
||||||
global_step: tf.Variable,
|
global_step: tf.Variable,
|
||||||
global_step_enc_dec: tf.Variable,
|
global_step_enc_dec: tf.Variable) -> Tuple[tf.Tensor, tf.Tensor]:
|
||||||
debug: bool) -> Tuple[tf.Tensor, tf.Tensor, tf.Tensor]:
|
|
||||||
"""
|
"""
|
||||||
Trains the encoder and decoder jointly for one step (one batch).
|
Trains the encoder and decoder jointly for one step (one batch).
|
||||||
|
|
||||||
@ -229,11 +227,8 @@ def _train_enc_dec_step_simple(encoder: model.Encoder, decoder: model.Decoder,
|
|||||||
optimizer.apply_gradients(zip(enc_dec_grads,
|
optimizer.apply_gradients(zip(enc_dec_grads,
|
||||||
encoder.trainable_variables + decoder.trainable_variables),
|
encoder.trainable_variables + decoder.trainable_variables),
|
||||||
global_step=global_step_enc_dec)
|
global_step=global_step_enc_dec)
|
||||||
input_shape = tf.shape(inputs)
|
|
||||||
z_reshaped = tf.reshape(z, [-1, input_shape[1], input_shape[2], 1])
|
|
||||||
z_expanded = K.concatenate((z_reshaped, z_reshaped, z_reshaped), axis=3)
|
|
||||||
|
|
||||||
return reconstruction_loss, x_decoded, z_expanded
|
return reconstruction_loss, x_decoded
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user