'TensorFlow keras - unable to augment images

I am doing my best to augment some images using TensorFlow but am not producing the expected results. I have seen this exact code being run by others to produced rotated, flipped and augmented images.

data_augmentation = keras.Sequential([
    layers.RandomFlip("horizontal"),
    layers.RandomRotation(0.01),
    layers.RandomZoom(0.01),
    layers.RandomTranslation(height_factor=(-0.05, 0.05), width_factor=(-0.05, 0.05)),
    layers.RandomContrast(0.05)
  ])

fig = plt.figure(figsize=[20, 25])
for i in range(10):
    for j in range(10):
        ax = fig.add_subplot(10, 10, i*10 + (j + 1))
        augmented_image = data_augmentation(tf.expand_dims(train_X[i,:,:,:],0))
        plt.imshow(augmented_image[0])
        plt.axis("off")

The train_X data is 3 channel rgb image data. The code throws no errors yet does not produce the result expected that has been demonstrated on other machines.

train_X data

un-augmented output

same code working with a different data set

I am running version 2.8.0 of TensorFlow. I have restarted my PC, VS code, my jupyter notebook and still it is not working as intended. Is there some issue with my machine? As I mentioned before this exact code works for others.

Any help would be appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source