title: Training works but prediction produces constant values (cnn with pytorch)
body: <p>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.</p>
  <p>I read similar topics from forums but that hasn't helped, as it appears there is no particular solution for this problem...</p>
  <p>I have tried the following:</p>
  <ul>
  <li>Changing epochs 5 to 15,20,30...</li>
  <li>Changing <code>lr</code> = 0.001 to 0.01, 0.0001...</li>
  <li>I implemented with both dropout regularization model and batch
  normalization model...</li>
  <li>I changed testing pictures...</li>
  <li>Changing last activation layer from <code>softmax</code> to <code>torch.sigmoid</code>...</li>
  <li>Reducing batch size from 100 to 30, 75...</li>
  <li>Trying with a batch, which results with normal acc, loss and
  predictions.</li>
  <li>My dataset is scaled which is mentioned in forums as solution.</li>
  <li>My optim is Adam which is mentioned in forums as solution.</li>
  <li>Loading dataset with <code>torch.data.DataLoader</code>...</li>
  <li>Sampling randomly...</li>
  <li>I saved and load the model, in case there are problems with that.
  However, I already checked that state_dict's are different...</li>
  <li>I re-prepared data which resulted the constant value to change
  otherwise (dog to cat), somehow? Idk if that's a coincidence though.</li>
  </ul>
  <p>Infos:</p>
  <blockquote>
  <p>Dataset :
  <a href="https://download.microsoft.com/download/3/E/1/3E1C3F21-ECDB-4869-8368-6DEBA77B919F/kagglecatsanddogs_3367a.zip" rel="nofollow noreferrer">https://download.microsoft.com/download/3/E/1/3E1C3F21-ECDB-4869-8368-6DEBA77B919F/kagglecatsanddogs_3367a.zip</a></p>
  </blockquote>
  <p>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!</p>
  <blockquote>
  <p><a href="https://github.com/yusuftengriverdi/neural_networks/blob/master/CNN_Last.ipynb" rel="nofollow noreferrer">https://github.com/yusuftengriverdi/neural_networks/blob/master/CNN_Last.ipynb</a></p>
  </blockquote>
  <blockquote>
  <p>Similar topics around the web:</p>
  </blockquote>
  <p><a href="https://discuss.pytorch.org/t/rnn-predicting-a-constant-output/40397/5" rel="nofollow noreferrer">https://discuss.pytorch.org/t/rnn-predicting-a-constant-output/40397/5</a></p>
  <p><a href="https://discuss.pytorch.org/t/cnn-does-not-predict-properly-does-not-converge-as-expected/43567" rel="nofollow noreferrer">https://discuss.pytorch.org/t/cnn-does-not-predict-properly-does-not-converge-as-expected/43567</a></p>
  <p><a href="https://discuss.pytorch.org/t/making-a-prediction-with-a-trained-model/2193" rel="nofollow noreferrer">https://discuss.pytorch.org/t/making-a-prediction-with-a-trained-model/2193</a></p>
  <p><a href="https://datascience.stackexchange.com/questions/46779/predict-gives-the-same-output-value-for-every-image-keras">https://datascience.stackexchange.com/questions/46779/predict-gives-the-same-output-value-for-every-image-keras</a></p>
  <p><a href="https://github.com/keras-team/keras/issues/6447" rel="nofollow noreferrer">https://github.com/keras-team/keras/issues/6447</a></p>
  <p><a href="https://stackoverflow.com/questions/62708433/pytorch-model-prediction-fail-for-single-item">PyTorch model prediction fail for single item</a></p>
  <p><a href="https://stackoverflow.com/questions/53273786/having-trouble-with-cnn-prediction">Having trouble with CNN prediction</a></p>