I have been trying to modify this DCGAN made in a tutorial from TensorFlow. I would like it to produce a graph displaying the training loss of the generator and discriminator over time. To start off, I tried to simply print the loss of the generator each epoch like this:
def train_step(images):
noise = tf.random.normal([BATCH_SIZE, noise_dim])
with tf.GradientTape() as gen_tape, tf.GradientTape() as disc_tape:
generated_images = generator(noise, training=True)
real_output = discriminator(images, training=True)
fake_output = discriminator(generated_images, training=True)
gen_loss = generator_loss(fake_output)
disc_loss = discriminator_loss(real_output, fake_output)
print(gen_loss) #What I added
The output is given as:
Tensor("binary_crossentropy/weighted_loss/value:0", shape=(), dtype=float32)
When I try to convert this to a numpy array by saying print(gen_loss.numpy()) I get the following error: AttributeError: 'Tensor' object has no attribute 'numpy'. I have tried the solutions mentioned here, but had no luck.
Does anyone know how I could visualize the training loss in this case?