1

I'm running a convolutional neural network (this one) on a bunch of my own image data, with shape (no. of channels, height, width) = (3, 30, 30). I have 76960 training samples, 19240 testing samples, and there are 39 classes. The last few blocks of code are:

# Train the model using Stochastic grad descent + momentum
sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
cnn.compile(loss='categorical_crossentropy',
             optimizer=sgd,
             metrics=['accuracy'])


batch_size = 128
nb_epoch = 50

cnn.fit(x_train, y_train,
        batch_size = batch_size,
        nb_epoch = nb_epoch,
        validation_data=(x_test, y_test),
       shuffle=True)

Training loss and accuracy change over the epochs, but validation accuracy only changes from the 1st to the 2nd epoch (from 0.3387 to 0.3357), and then it stays at 0.3357 all the way.

I've tried varying batch size (32, 128 or 256), learning rate (from 1e-6 to 0.1, in multiplying by 10 along the way) and tried with or without data normalization (the basic mean shift, and division by s.d.). None of these have worked.

Community
  • 1
  • 1
AndreyIto
  • 954
  • 1
  • 14
  • 35
  • Do you test another classifiers? if yes, what the best accuracy you get according to different classifier? – Masoud Aug 26 '16 at 11:54
  • How are your classes balanced? Any class that has more samples than the others? – Dr. Snoopy Aug 26 '16 at 13:30
  • 1. Yes, I've tried other classifiers. 2. No, 2 of the classes are severely over-represented, taking up about 34% and 35% of the total population. However, note that my question isn't really "how to get method X to classify my data accurately". I'm not sure that the labels I've been given are even correct, so a failure to classify could still be an accurate result that reflects reality. I'm just worried about the technical error. – AndreyIto Aug 27 '16 at 04:46
  • Are you still working on this issue? do you add regularizers on each layer? – xueliang liu Nov 14 '16 at 07:35

1 Answers1

7

It is no coincidence that the percent accuracy you're getting stuck on (33.5%) is the same as the percentage of examples that fall into the dominant class (you stated "about 34%" - it's almost surely 33.5%).

The problem is that you aren't normalizing your image data. If your pixel values are between 1 and 255, your model will forever get stuck predicting the same class every time. To confirm this is happening, use model.predict(x_train) and see what your model is predicting. I'll bet it's exactly uniform, and that it's always the class that makes up 34% of your data.

To fix this problem, just normalize your data - divide x_train by 255 before you start training the model.

x_train = x_train/255.0
charlesreid1
  • 4,360
  • 4
  • 30
  • 52