keras-team / keras

Deep Learning for humans
http://keras.io/
Apache License 2.0
61.66k stars 19.42k forks source link

Keras Not Learning with 3-Channel Images #14015

Closed katherinebrown539 closed 2 years ago

katherinebrown539 commented 4 years ago

System information

Context I’ve been doing image classification for a few years now, but I am by no means an expert. I’m working with 3 datasets: MNIST, Dogs vs. Cats , and Diabetic Retinopathy detection, converted to binary classification. I definitely hope this is an easy fix!

Describe the current behavior
When I train the neural network on a dataset with three channels (naturally, or converted from grayscale), it doesn’t train correctly, and produces two distinct behaviors depending on the value of the learning rate. If the learning rate is normal ( lr > 0.0001), training accuracy and validation accuracy hover around 50%, and training and validation loss hover around some value (and does not improve). When evaluated on the test set, the network guesses all 1s (same predicted probability greater than 0.5). If the learning rate is quite low (lr <= 0.0001), the neural network appears to train based on training and validation metrics; however, when evaluated on the test set, the network randomly guesses, and the accuracy is about 50%.

This happens on all three datasets when represented as 3-channel RGB images. I’m currently using a Keras Image Data Generator, but this also occurs manually converting the images into a NumPy X,y dataset to use Keras model.fit(). I was able to resolve the issue for MNIST by using 1 channel to represent the image, and train the model successfully, but I hope to avoid that for the other two datasets.

This occurs independently of hardware and OS as well, since I have also tested my code on a CentOS 7.7 machine that uses an NVIDIA K80 GPU.

Describe the expected behavior
What I expect to happen (particularly with the cats vs dogs and MNIST datasets) is the model to learn from the training data and be able to generalize to the test data reasonably well (90% accuracy). Similarly for the diabetic retinopathy data, but I’m okay with 80% accuracy.

Code to reproduce the issue
I've attached both the neural network code and data generator code. Create a data directory, and a subdirectory entitled "dogs-vs-cats" for dogs vs cats data or "DIABETIC_RETINOPATHY" to store the diabetic retinopathy data. The images are stored in a further subdirectory "train_kaggle2". The CSV dictionaries are in the same directory as "train_kaggle2". My source code is zipped. code.zip

Execute python VGG19_DR_Keras.py to execute the code

Other info / logs
I've attached the logs with learning rate of 0.01 and 0.0001 in 001.txt and 00001.txt, respectively. out_00001.txt out_001.txt

kumariko commented 3 years ago

@thekatiebr We are checking to see if you still need help on this issue, as you are using an older version of tensorflow(1.x) which is officially considered as end of life. We recommend that you upgrade to 2.6 which is latest stable version of TF and let us know if the issue still persists in newer versions. check link Thanks!

google-ml-butler[bot] commented 3 years ago

This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Thank you.

google-ml-butler[bot] commented 2 years ago

Closing as stale. Please reopen if you'd like to work on this further.