-
Notifications
You must be signed in to change notification settings - Fork 19.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keras training and validation accuracy always converges to 0.5 #13006
Comments
@Randryn0 can you provide a standalone code to reproduce the issue? The above code as it is not working as I found a typo and underfined variables. Thanks! |
Hello Randryn0 Even am facing the same issue now while doing sentimental analysis on movie review data. |
Closing this issue. Please open a new issue with a standalone code to reproduce the issue. Resolution will be faster with a standalone code. Another comment is, it looks more like a support issue. If you strongly thinks this is a bug, then post here. Otherwise, post it in stackoverflow. thanks! |
I also have this problem. |
I have the same problem! |
One has to change the last layer
to
When |
I also have this problem. Does anyone have a solution yet? I tried different optimizers and learning rates as well but the accuracy always converges to 0.5. |
I also set the last layer to have two nodes with activation='softmax' but it still doesn't work. |
When using gen_train.flow_from_directory('../data/train', shuffle=True, class_mode='binary') be sure to add class_mode='binary' to gen_train.flow_from_directory |
@khatbahusain : Thanks for the tip. changing the class_mode to binary helped me. The default seems to be categorical |
OMG! You are my lifesaver!!! I stuck with this problem for a week! |
Still I am getting val_acc 0.5 constantly. Can anyone confirm with using Sigmoid(last layer activation), binary_crossentropy(loss) and binary (class_mode) how many output neurons should I use in last layer for classifying one image into one of two classes(2 sub folders inside flow_from_directory) |
System information
I have used a model (provided here] that trains a model on two categories of pictures and then tries to classify them.
Furthermore, I force the network to use the same seeds when training so as to get comparable results. I also create and close the tf sessions as I have read that this may also cause problems.
Describe the current behaviour
Most of the time the test and validation accuracy converge around 0.5 and the loss stays at exactly the same value for every epoch. I can run the same code, without changing it, several times in a row and get this problem and only rarely do I get a run where the neural network is trained properly and rises to and above 0.9 accuracy for training and validation.
Describe the expected behaviour
For the same seeds the run should produce at least very similar results i.e. it should not be stuck around 0.5 accuracy.
Code to reproduce the issue
[Edit]
I've tried a different tutorial and I get the same result. The only changes I have done to the code is to change the image dimension to the size of my images, changed the image directories and to turn off Image Augmentation, as well as changed the number of images.
About half of my runs produced output such as this
while the other half produced
(the numbers were not always exactly the same).
I though that maybe I have bad images so I tried use images from other tutorials (like this) but I got the same results: about half or more of the runs are useless because they converge at 0.5 accuracy. What's going on?
The text was updated successfully, but these errors were encountered: