I'm working with a video classification of 5 classes and using TimeDistributed CNN model in Google Colab platform. The train dataset contains 8 videos containing 75 frames each. The validation dataset contains 2 videos containing 75 frames each. The batch size I used is 64. So,in total I'm working with 10 videos.I compiled the model using Adam optimizer and categorical cross_entropy loss.After fitting the model with the dataset, I'm getting following error:
InvalidArgumentError: Can not squeeze dim[2], expected a dimension of 1, got 5
Here is my code I developed:
from tensorflow.keras.optimizers import Adam
train_generator = datagen.flow_from_directory(
'/content/drive/My Drive/New dataset/train',
target_size=(64, 64),
batch_size=batch_size,
class_mode='categorical', # this means our generator will only yield batches of data, no labels
shuffle=False,
classes=['class_a','class_b','class_c','class_d','class_e'])
validation_generator = datagen.flow_from_directory(
'/content/drive/My Drive/New dataset/validation',
target_size=(64, 64),
batch_size=batch_size,
class_mode='categorical', # this means our generator will only yield batches of data, no labels
shuffle=False,
classes=['class_a','class_b','class_c','class_d','class_e'])
model = tf.keras.models.Sequential([
tf.keras.layers.TimeDistributed(Conv2D(64, (3,3), padding='same', activation='relu'),input_shape=(75,64, 64, 3)),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(5, activation='softmax')
])
model.compile(loss='categorical_crossentropy',
optimizer=Adam(lr=0.0001),
metrics=['accuracy'])
history = model.fit_generator(
train_generator,
validation_data=validation_generator,
validation_steps=150//64,
shuffle=False,
steps_per_epoch=8,
epochs=5,
verbose=1)
The error that I got:
WARNING:tensorflow:From <ipython-input-11-a17136d736b1>:8: Model.fit_generator (from tensorflow.python.keras.engine.training) is deprecated and will be removed in a future version.
Instructions for updating:
Please use Model.fit, which supports generators.
Epoch 1/5
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
<ipython-input-11-a17136d736b1> in <module>()
6 steps_per_epoch=8,
7 epochs=5,
----> 8 verbose=1)
------------------------------------------^10 frames^----------------------------------------------
/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
58 ctx.ensure_initialized()
59 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
---> 60 inputs, attrs, num_outputs)
61 except core._NotOkStatusException as e:
62 if name is not None:
InvalidArgumentError: Can not squeeze dim[2], expected a dimension of 1, got 5
[[node categorical_crossentropy/remove_squeezable_dimensions/Squeeze (defined at <ipython-input-11-a17136d736b1>:8) ]] [Op:__inference_train_function_607]
Function call stack:
train_function
Can anyone tell me what is wrong in the code and how to fix it?