jiangqy / Customized-DataLoader-pytorch

Customized DataLoader for multi label dataset classification-pytorch implementation
64 stars 20 forks source link

loss starts out with 0.000 #1

Open kettenfett opened 6 years ago

kettenfett commented 6 years ago

Hello, I'm a beginner with python/pytorch. I just reconfigured the Customized-DataLoader for my data. I created test_img.txt, test_label.txt, ... and ran it. my data has only 2 classes. The Loss starts out with 0.000. Is there something wrong? Do you have any idea, what can cause this?

Thanks, for any help.

jiangqy commented 6 years ago

what's your loss function and net structure? pls provide more details or code.

kettenfett commented 6 years ago

Hello,

I did not change the loss function or the net structure. I now cloned it and added my changes to the code and the new images. https://github.com/philippHRO/Customized-DataLoader

I used make_label_and_filename_txt.py to generate the txt files.

My output is:

Number of train samples:  1500
Number of test samples:  400
Training Phase: Epoch: [ 0][ 0/ 3]      Iteration Loss: 0.000
Training Phase: Epoch: [ 1][ 0/ 3]      Iteration Loss: 0.000
Training Phase: Epoch: [ 2][ 0/ 3]      Iteration Loss: 0.000
Training Phase: Epoch: [ 3][ 0/ 3]      Iteration Loss: 0.000
Training Phase: Epoch: [ 4][ 0/ 3]      Iteration Loss: 0.000
Training Phase: Epoch: [ 5][ 0/ 3]      Iteration Loss: 0.000
Training Phase: Epoch: [ 6][ 0/ 3]      Iteration Loss: 0.000
Training Phase: Epoch: [ 7][ 0/ 3]      Iteration Loss: 0.000
Training Phase: Epoch: [ 8][ 0/ 3]      Iteration Loss: 0.000
jiangqy commented 6 years ago

Well, it's my mistake. Actually the MultiLabelMarginLoss is a sample-based loss rather than batch-based. Hence the loss.data[0] / train_labels.size(0) should be loss.data[0] in 'multi_label_classifier.py', line 97.

Furthermore, you can change output format '%.3f' to '%f' to verify the loss value.

kettenfett commented 6 years ago

I made the changes you suggested, as can be seen here: https://github.com/philippHRO/Customized-DataLoader/blob/master/multi_label_classifier.py

It's still showing zero loss.

kettenfett commented 6 years ago

Hey I got it to work. I switched to MSELoss and converted the labels to TorchFloat tensor.