Open Israh-Abdul opened 2 weeks ago
Hi @Israh-Abdul @mehtamansi29
Some possibilities are:
This can happen if the network output does not have the expected shape for binary classification.
The model output needs to have two final activation units for each class. It would be possible to add a dense layer with softmax activation at the end of the network to ensure an output compatible with class_mode='categorical' of the ImageDataGenerator.
The error can also arise from the margin_loss loss function. It would have the loss for two classes and that y_true and y_pred have the same shape.
Hi @Israh-Abdul ,
Thanks for the report. In order for us to be able to debug this, we'll need a few more details:
keras.config.disable_traceback_filtering()
at the beginning.Ideally, you would put the whole code in a colab or gist that runs and reproduces the error.
My hunch is that the labels don't have the right shape.
Thanks!
I'm building a capsule network in TensorFlow for binary classification using a custom CapsuleLayer. My model and associated components are as follows:
When training, I receive this error: ValueError: Cannot squeeze axis=-1, because the dimension is not 1.
I've set class_mode='categorical' in the ImageDataGenerator flow: train_generator = train_datagen.flow_from_directory(train_dir, target_size=(224, 224), color_mode='grayscale', batch_size=64, class_mode='categorical') I am using this model to classify an image dataset into 2 classes. Please help!