-1

I am working on a CNN model for multi-class image classification, while both loss and accuracy show flatline and values stay almost same. Could you please help have a look if any mistakes made and much appreciate if any advice? thanks a lot in advance.

Loss and accuracy:

Input data

(X_train.shape, X_test.shape, y_train.shape, y_test.shape) (24296, 32, 32, 1) (6075, 32, 32, 1) (24296, 6) (6075, 6)

X_train:

y_train:

y_train

CNN code

model

model = Sequential()
model.add(Conv2D(16, (2,2), activation = 'relu', input_shape = (32,32,1)))
model.add(MaxPooling2D((2,2)))
model.add(Conv2D(32, (2,2), activation = 'relu'))
model.add(MaxPooling2D((2,2)))
model.add(Conv2D(64, (2,2), activation = 'relu'))
model.add(MaxPooling2D((2,2)))
model.add(Conv2D(128, (2,2), activation = 'relu')) 
model.add(MaxPooling2D((2,2)))
model.add(Flatten())
model.add(Dense(100, activation = 'relu'))
model.add(Dense(6, activation = 'softmax'))

compile

model.compile(loss = 'categorical_crossentropy',
              optimizer = optimizers.RMSprop(learning_rate=0.001),
              metrics = ['accuracy'])

early stopping and fit

es = EarlyStopping(patience = 5, verbose=2)
history = model.fit(X_train, y_train,
                    validation_split = 0.2,
                    callbacks=[es],
                    epochs=100,
                    batch_size=64)

I checked the community, tried different optimizer (adam, sgd and RMSprop), parameters like learning rate and also different layers, but similar result.I expect the loss drop and accuracy increase, no flatline.

desertnaut
  • 57,590
  • 26
  • 140
  • 166

1 Answers1

0

For what I can see the model is not learning, it's returning the same predictions for all inputs.

  • Is it 6 classes you're trying to predict? model.add(Dense(6, activation = 'softmax'))
  • Is your dataset big enough? Without enough parameters to represent your data the model will have high loss.
  • Also, when is your model supposed to stop? are you monitoring val_accuracy or val_loss and the training phase is terminating when these metrics stops increasing or decreasing?
  • Did you One-Hot-Encode your targets so to use categorical_crossentropy ? Otherwise try sparse_categorical_crossentropy?
cla.cif
  • 1
  • 1
  • 6