I have a model trying to predict the class of image: cat or dog. I receive 95% accuracy in training. However when I try to predict a single image, I am stuck with almost constant output every time I run the model. There are some non-constant values, but they mostly look like catastrophic failure.
I read similar topics from forums but that hasn't helped, as it appears there is no particular solution for this problem...
I have tried the following:
- Changing epochs 5 to 15,20,30...
- Changing
lr
= 0.001 to 0.01, 0.0001... - I implemented with both dropout regularization model and batch normalization model...
- I changed testing pictures...
- Changing last activation layer from
softmax
totorch.sigmoid
... - Reducing batch size from 100 to 30, 75...
- Trying with a batch, which results with normal acc, loss and predictions.
- My dataset is scaled which is mentioned in forums as solution.
- My optim is Adam which is mentioned in forums as solution.
- Loading dataset with
torch.data.DataLoader
... - Sampling randomly...
- I saved and load the model, in case there are problems with that. However, I already checked that state_dict's are different...
- I re-prepared data which resulted the constant value to change otherwise (dog to cat), somehow? Idk if that's a coincidence though.
Infos:
Here is all my code with predictions in Jupyter Notebook, feel free to investigate. I am really tired of this solution. Any help is highly appreciated!
https://github.com/yusuftengriverdi/neural_networks/blob/master/CNN_Last.ipynb
Similar topics around the web:
https://discuss.pytorch.org/t/rnn-predicting-a-constant-output/40397/5
https://discuss.pytorch.org/t/cnn-does-not-predict-properly-does-not-converge-as-expected/43567
https://discuss.pytorch.org/t/making-a-prediction-with-a-trained-model/2193
https://github.com/keras-team/keras/issues/6447