I am trying to apply data augmentation for a binary image classification problem in the following way as mentioned in tensorflow docs: https://www.tensorflow.org/tutorials/images/classification#data_augmentation
My model is this:
Sequential([
data_augmentation,
layers.experimental.preprocessing.Rescaling(1./255),
layers.Conv2D(16, 3, padding='same', activation='relu'),
layers.MaxPooling2D(),
layers.Dropout(0.2),
layers.Conv2D(32, 3, padding='same', activation='relu'),
layers.MaxPooling2D(),
layers.Dropout(0.2),
layers.Conv2D(64, 3, padding='same', activation='relu'),
layers.MaxPooling2D(),
layers.Flatten(),
layers.Dense(128, activation='relu'),
layers.Dropout(0.5),
layers.Dense(1, activation='sigmoid')
])
When my data augmentation layer is like this, the model compiles without error:
data_augmentation = keras.Sequential(
[
layers.experimental.preprocessing.RandomFlip("horizontal",
input_shape=(150,
150,
3)),
layers.experimental.preprocessing.RandomRotation(0.2),
layers.experimental.preprocessing.RandomZoom(0.2)
]
)
If I try to introduce RandomHeight()
and/or RandomWidth()
in my augmentation layer, I receive the following error when creating the model:
ValueError: The last dimension of the inputs to `Dense` should be defined. Found `None`.
Any idea as to why this is happening and how to resolve it?