Why in binary classification of images with CNN the loss and accuracy graph are so unstable? I mean accuracy of validation test does not increase smoothly, it goes to 80%, then comes to 60%, then again goes to 84% and so on. Same is the case with train accuracy. Now how do I know that how many epochs is the optimal number?
There is no way to definitely note how many epochs is required. Your accuracy graphs may be unstable for several reasons such as -
- Irregular data distribution
- Faulty model
- Large batch size (as mentioned in the comments)
- Overfitting and underfitting (in this case im not too sure which one)
You can fix it through the following methods -
- Analyse your data well and see if one class is heavily grater than other.
- Make sure all duplicate images are removed.
- Try different models, start with pre-trained. Shouldn't take much compute power.
- Approach transfer learning (neural networks)
- Adjust learning rate (as mentioned above)
- General hyperparameter tuning.
if the dataset is from somewhere public, see the models and the approaches others have used. You might see where your model actually lacks.