harryhan618 / SCNN_Pytorch

Pytorch implementation of "Spatial As Deep: Spatial CNN for Traffic Scene Understanding"
MIT License
250 stars 68 forks source link

RuntimeError: all elements of input should be between 0 and 1 #52

Closed Ashokcharu closed 3 years ago

Ashokcharu commented 4 years ago

I'm training using CULane, I had my own dataset (300 images) and I got this below Error. I'm not sure, I think the problem is in avg loss setup. Below I haded my error and loss values. Please check and give your suggestion

Train Epoch: 0
  0% 0/12 [00:00<?, ?it/s]
Its coming here inside if seg_gt is not None and exist_gt is not None:
loss in seg =>> 1.0 tensor(0.6974, grad_fn=<BinaryCrossEntropyBackward>) 0.1
loss_seg =>>>>> tensor(1.5938, grad_fn=<NllLoss2DBackward>)
Thebatch loss: 1.664:   8% 1/12 [02:50<31:17, 170.65s/it]check lr 0.0064

Its coming here inside if seg_gt is not None and exist_gt is not None:
loss in seg =>> 1.0 tensor(0.6923, grad_fn=<BinaryCrossEntropyBackward>) 0.1
loss_seg =>>>>> tensor(0.0165, grad_fn=<NllLoss2DBackward>)
Thebatch loss: 0.086:  17% 2/12 [05:25<27:39, 165.95s/it]check lr 0.009600000000000001

Its coming here inside if seg_gt is not None and exist_gt is not None:
loss in seg =>> 1.0 tensor(0.6919, grad_fn=<BinaryCrossEntropyBackward>) 0.1
loss_seg =>>>>> tensor(0.0005, grad_fn=<NllLoss2DBackward>)
Thebatch loss: 0.070:  25% 3/12 [08:00<24:23, 162.63s/it]check lr 0.0128

Its coming here inside if seg_gt is not None and exist_gt is not None:
loss in seg =>> 1.0 tensor(0.6763, grad_fn=<BinaryCrossEntropyBackward>) 0.1
loss_seg =>>>>> tensor(5.7504e-06, grad_fn=<NllLoss2DBackward>)
Thebatch loss: 0.068:  33% 4/12 [10:36<21:24, 160.55s/it]check lr 0.016

Its coming here inside if seg_gt is not None and exist_gt is not None:
loss in seg =>> 1.0 tensor(0.6609, grad_fn=<BinaryCrossEntropyBackward>) 0.1
loss_seg =>>>>> tensor(1.3436e-08, grad_fn=<NllLoss2DBackward>)
Thebatch loss: 0.066:  42% 5/12 [13:11<18:33, 159.05s/it]check lr 0.019200000000000002

Its coming here inside if seg_gt is not None and exist_gt is not None:
loss in seg =>> 1.0 tensor(0.6342, grad_fn=<BinaryCrossEntropyBackward>) 0.1
loss_seg =>>>>> tensor(5.2403e-15, grad_fn=<NllLoss2DBackward>)
Thebatch loss: 0.063:  50% 6/12 [16:05<16:21, 163.57s/it]check lr 0.0224

Its coming here inside if seg_gt is not None and exist_gt is not None:
loss in seg =>> 1.0 tensor(0.6021, grad_fn=<BinaryCrossEntropyBackward>) 0.1
loss_seg =>>>>> tensor(0., grad_fn=<NllLoss2DBackward>)
Thebatch loss: 0.060:  58% 7/12 [18:39<13:23, 160.64s/it]check lr 0.0256

Its coming here inside if seg_gt is not None and exist_gt is not None:
loss in seg =>> 1.0 tensor(0.5840, grad_fn=<BinaryCrossEntropyBackward>) 0.1
loss_seg =>>>>> tensor(0., grad_fn=<NllLoss2DBackward>)
Thebatch loss: 0.058:  67% 8/12 [21:15<10:36, 159.13s/it]check lr 0.028800000000000003

Its coming here inside if seg_gt is not None and exist_gt is not None:
loss in seg =>> 1.0 tensor(0.5324, grad_fn=<BinaryCrossEntropyBackward>) 0.1
loss_seg =>>>>> tensor(0., grad_fn=<NllLoss2DBackward>)
Thebatch loss: 0.053:  75% 9/12 [23:49<07:52, 157.59s/it]check lr 0.032

Traceback (most recent call last):
  File "train.py", line 242, in <module>
    main()
  File "train.py", line 232, in main
    train(epoch)
  File "train.py", line 90, in train
    seg_pred, exist_pred, loss_seg, loss_exist, loss = net(img, segLabel, exist)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/parallel/data_parallel.py", line 149, in forward
    return self.module(*inputs, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/content/drive/My Drive/SCNN/lane_train/model.py", line 47, in forward
    loss_exist = self.bce_loss(exist_pred, exist_gt)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/loss.py", line 530, in forward
    return F.binary_cross_entropy(input, target, weight=self.weight, reduction=self.reduction)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py", line 2526, in binary_cross_entropy
    input, target, weight, reduction_enum)
RuntimeError: all elements of input should be between 0 and 1
Thebatch loss: 0.053:  75% 9/12 [24:38<08:12, 164.32s/it]
harryhan618 commented 3 years ago

It seems ground truth you provided has value other than 0 and 1.