So I’m trying my hands on Convolution Neural Network and thought a more hands-on approach is the way to go with the rock paper scissors dataset
This is how the model has been built
model = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(filters=32,
kernel_size=3,
activation="relu",
input_shape=(200, 200, 3)),
tf.keras.layers.Conv2D(32, 3, activation="relu"),
tf.keras.layers.MaxPooling2D(pool_size=2, padding="valid"),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Conv2D(64, 3, activation="relu"),
tf.keras.layers.MaxPooling2D(pool_size=2, padding="valid"),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Conv2D(128, 3, activation="relu"),
tf.keras.layers.MaxPooling2D(pool_size=2, padding="valid"),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(256, activation="relu"),
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Dense(3, activation="softmax")
])
And this is the summary
Model: "sequential_1"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d_6 (Conv2D) (None, 198, 198, 32) 896
_________________________________________________________________
conv2d_7 (Conv2D) (None, 196, 196, 32) 9248
_________________________________________________________________
max_pooling2d_3 (MaxPooling2 (None, 98, 98, 32) 0
_________________________________________________________________
dropout_4 (Dropout) (None, 98, 98, 32) 0
_________________________________________________________________
conv2d_8 (Conv2D) (None, 96, 96, 64) 18496
_________________________________________________________________
max_pooling2d_4 (MaxPooling2 (None, 48, 48, 64) 0
_________________________________________________________________
dropout_5 (Dropout) (None, 48, 48, 64) 0
_________________________________________________________________
conv2d_9 (Conv2D) (None, 46, 46, 128) 73856
_________________________________________________________________
max_pooling2d_5 (MaxPooling2 (None, 23, 23, 128) 0
_________________________________________________________________
dropout_6 (Dropout) (None, 23, 23, 128) 0
_________________________________________________________________
flatten_1 (Flatten) (None, 67712) 0
_________________________________________________________________
dense_2 (Dense) (None, 256) 17334528
_________________________________________________________________
dropout_7 (Dropout) (None, 256) 0
_________________________________________________________________
dense_3 (Dense) (None, 3) 771
=================================================================
Total params: 17,437,795
Trainable params: 17,437,795
Non-trainable params: 0
_________________________________________________________________
The model has been compiled as such
model.compile(loss="categorical_crossentropy",
optimizer=tf.optimizers.Adam(),
metrics=['accuracy'])
and trained
history = model.fit(train_data, epochs=10, steps_per_epoch=20, validation_data = val_data, validation_steps=5, verbose=1)
But while training I get thrown this error
InvalidArgumentError: Input to reshape is a tensor with 3686400 values, but the requested shape requires a multiple of 67712
[[node sequential_1/flatten_1/Reshape (defined at tmp/ipykernel_17/154995288.py:1) ]] [Op:__inference_train_function_2119]
Function call stack:
train_function
What am I doing wrong? Any help is greatly appreciated