Search code examples
pythontensorflowkerastensorboard

Keras: cannot access training images inside on_batch_end callback


I am training a CNN using Keras with TensorFlow backend, using imgaug for image augmentation.

I am also using Tensorboard to visualize training progress and results.

Since imgaug is applying (random) transformations to the input images, I would like to send (some of) the augmented images over to Tensorboard, so that I can visualize them and verify that everything is correct (eg: to check if I am applying too large translations, or blurring the images too much).

For this I created a custom Keras callback and am trying to input my logic in the on_batch_end method. I can send images to tensorboard alright, but can't find where I can access the augmented input images. Any tips on how to achieve this?

Thanks in advance


Solution

  • Better to do that outside training by simply getting images from your generator.

    If it's a regular generator:

    for i in range(numberOfBatches):
        x,y = next(generator)
        #plot, print, etc. with the batches    
    

    If it's a keras.utils.Sequence:

    for i in range(len(generator)):
        x,y = generator[i]
        #plot, print, etc. with the batches