Customized-DataLoader-pytorch icon indicating copy to clipboard operation
Customized-DataLoader-pytorch copied to clipboard

loss starts out with 0.000

Open kettenfett opened this issue 7 years ago • 5 comments

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.

kettenfett avatar Mar 05 '18 17:03 kettenfett

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

jiangqy avatar Mar 06 '18 02:03 jiangqy

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

kettenfett avatar Mar 06 '18 09:03 kettenfett

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.

jiangqy avatar Mar 06 '18 11:03 jiangqy

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 avatar Mar 06 '18 12:03 kettenfett

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

kettenfett avatar Mar 15 '18 15:03 kettenfett