I am trying to train a binary image classifier on a an imbalanced dataset of images which are really small in dimensions(the largest dimension is 40*70). I am augmenting images by grayscale, rescaling and resizing to 48*48. My keras model is not learning at all. Can you suggest some technique using which I can improve the model or data? I figured out the problem. It was my data. Without knowingly I was doing single class classification while doing binary classification. Any advice what approach to be taken?


1 Answer 1


I wrote few notes on your implementation:

  • Classification on imbalanced data can be a problem. How imbalanced is your dataset? You can try to compensate by training your model by feeding balanced mini batches of data. You artificially build each batch so that classes are more or less equally represented, so that your classifier can learn from all of them.

  • I would change the last layers. I suggest you to use softmax activation at the output layer, and a crossentropy loss function that is specific for this task. The number of output nodes must be equal to the number of classes.

  • Adam optimizer is commonly referred to as the best algorithm for gradient descent.

  • MAE is a metric for regression tasks, it doesn't work for classification. You can use 'accuracy' instead.

  • $\begingroup$ It is a binary classifier. So, do I still use these suggestions? $\endgroup$
    – Jodh Singh
    Aug 2, 2019 at 13:13
  • $\begingroup$ In a binary classifier, you have 1 output node. And isn't sigmoid activation better for binary classification? $\endgroup$
    – Jodh Singh
    Aug 2, 2019 at 13:18
  • $\begingroup$ My experience tells me it works better with two output layers + softmax activation. Check this implementation $\endgroup$
    – Leevo
    Aug 2, 2019 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.