tkuanlun350 / Tensorflow-SegNet

Implement slightly different caffe-segnet in tensorflow
MIT License
368 stars 164 forks source link

Binary classification #20

Open sevamoo opened 6 years ago

sevamoo commented 6 years ago

Thanks for the great work. With CamVid data set I get the results as expected. However, I am working with images with binary labels. Every thing except the number of classes is the same as the CamVid, but it always turns to 100% accuracy for class 0 and 0% percent for class 1. This means the model doesn't learn anything, except one fixed guess. I write my images with two distinct pixel values of 0 and 1 within one channel. I don't understand if the problem is from my data set (i.e. the way I write the images) or some parameters that I need to change in the code. Any help would be appreciated a lot. @tkuanlun350 Best Vahid

tkuanlun350 commented 6 years ago

Hi, You need to change final classification layer output channel and the global variable (image w, h ,c) inside Inputs.py. But seems you can run the code, I think above change is correct.

Your image is binary image (0-1) ? so what is your label image ? If your data is imbalance, we may need to change the median-weighted loss function as well.

sevamoo commented 6 years ago

Hi, Yes, I think I can test the code with other data sets. My input images are RGB and output binary. I balanced the data also and played with different weight values in the loss. Even if I get .9 weight to class 1 still it only gives class 0. I think there is an issue with the softmax output. I even have similar results with U-Net. Always, one label (only 0). My guess is that it might be because of my image resolution, but then I would expect at least some from the other class. Would appreciate any hint or tip.

gaexp251546 commented 6 years ago

@sevamoo
@tkuanlun350 Hi, thanks for your excellent code! I meet the same problem . class 0's accuracy is 0 class 1's accuracy is 1 My label data is binary image(0,1)

Would appreciate any hint or tip.

geekyspartan commented 6 years ago

Anyone able to solve this issue? I am struggling to make this code work for Binary classification.

tkuanlun350 commented 6 years ago

Sorry, due to various reason I only have very limited time to maintain. You can train only one image to see that if the network can overfit (changing loss weight as well, applying huge penalty to loss weight should force the model to predict other class). If training on one image still fail, there may be some bugs in the code :( You can send me a small portion of data to help me debugging if the data is not sensitive.

geekyspartan commented 6 years ago

Hey, Sorry, I missed this mail.

I have created a repo to test this, it has images and everything needed to do the testing. Repo link: https://github.com/geekyspartan/Tensorflow-segnet-binary

Command to run: python main.py --log_dir=SegNet/ --image_dir=SegNet/CamVid/train.txt --val_dir=SegNet/CamVid/val.txt --batch_size=5

On 29 March 2018 at 03:21, Tseng Kuan Lun notifications@github.com wrote:

Sorry, due to various reason I only have very limited time to maintain. You can train only one image to see that if the network can overfit (changing loss weight as well, applying huge penalty to loss weight should force the model to predict other class). If training on one image still fail, there may be some bugs in the code :( You can send me a small portion of data to help me debugging if the data is not sensitive.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tkuanlun350/Tensorflow-SegNet/issues/20#issuecomment-377146339, or mute the thread https://github.com/notifications/unsubscribe-auth/AJmKCfCv99dQl-o7OWFmIXNITkR8oqihks5tjIt-gaJpZM4Pl23q .

-- Anurag Arora

mathildor commented 6 years ago

It could have something to do with the initializer. Initializing the network properly can be the difference between the network converging or diverging and giving results as the ones you get. I was able to solve this issue by using Xavier or Variance scale initializer. I have an implementation of SegNet where these initializers, as well as several optimizers, have been implemented so that you can easily test if this is the issue.

https://github.com/mathildor/TF-SegNet

geekyspartan commented 6 years ago

Does it work for binary classification also?

mathildor commented 6 years ago

Yes, the dataset that I have trained it on has only two classes, and it works well :)

geekyspartan commented 6 years ago

Thank you, I will check it.

On 22 April 2018 at 02:49, Mathilde Ørstavik notifications@github.com wrote:

Yes, the dataset that I have trained it on has only two classes, and it works well :)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tkuanlun350/Tensorflow-SegNet/issues/20#issuecomment-383359745, or mute the thread https://github.com/notifications/unsubscribe-auth/AJmKCR0CVGzS0FEshrOq3cyFYtMhhr1Qks5trCf-gaJpZM4Pl23q .

-- Anurag Arora

ruoyuyang1991 commented 6 years ago

@geekyspartan Do you solve the binary classification problem? I just meet the same problem , the accuracy is always 0% and 100% for two classes. Thanks a lot.

geekyspartan commented 6 years ago

Hey,

Actually, I am using my own customized code for this purpose. Will try the new "https://github.com/mathildor/TF-SegNet" code in a couple of days.