'training argument error issue in GaussianNoise
I am facing issue while generating noise in mnist dataset using GaussianNoise from tensorflow keras.
from tensorflow.keras.datasets import mnist
(X_train, y_train), (X_test, y_test) = mnist.load_data()
from tensorflow.keras.layers import GaussianNoise
sample = GaussianNoise(0.15)
sample(X_test[0:2],training=True )
TypeError: Exception encountered when calling layer "gaussian_noise_7" (type GaussianNoise).
Cannot convert 0.0 to EagerTensor of dtype uint8
Call arguments received: • inputs=tf.Tensor(shape=(2, 28, 28), dtype=uint8) • training=True
When I removed the training then error is eliminated but image is as such without any noise as function is inferring image as such without adding any noise.
Please help in sorting this issue.
Thanks !!!
Solution 1:[1]
It is indeed a bit confusing how the documentation of the GaussianNoise layer deals with the boolean call parameter training. As this layer is intended to be a preprocessing layer (e.g. augmentation), it will only be active at training time. Meaning that when you are inferring with a trained model, it won't add noise to your input.
I would suggest using such a layer only at defining the model if you really need it as preprocessing. Here you can find info about using Keras layers as preprocessing. If you just want to add noise to an image, use openCV.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nicolas Perez de Olaguer |
