When I download the dataset for resnet model, the data file shows me 33 classes for training and 6 classes for validation. But when I compile it, it reports the class number is wrong. Like the following code:
resnet_model = Sequential()
pretrained_model = tf.keras.applications.ResNet50(include_top=False,
input_shape=(224,224,3),
pooling='avg',
classes = 33,
weights = 'imagenet')
for layer in pretrained_model.layers:
layer.trainable=False
resnet_model.add(pretrained_model)
resnet_model.add(Flatten())
#resnet_model.add(Dense(512,activation='relu'))
resnet_model.add(Dense(33,activation='softmax'))
resnet_model.compile(optimizer=Adam(learning_rate=0.001),loss='categorical_crossentropy',metrics=['accuracy'])
epochs = 3
history= resnet_model.fit(
trains_ds,
validation_data=val_ds,
epochs=epochs)
The error shows: Shapes (None, 33) and (None, 6) are incompatible
Do I have to have the same classes number for training dataset and validation dataset? If I got 33 classes for training and 6 classes for validation, I need to create another 27 classes pictures for validation dataset. Then I can fit it, is that right?