Closed feitiandemiaomi closed 5 years ago
Please print the shape of outputs
and target
. And what's the classes value in your target?
torch.Size([6, 2, 512, 512]) torch.Size([6, 2, 512, 512])
I change 'self.criterion = MixSoftmaxCrossEntropyOHEMLoss(aux=args.aux, aux_weight=args.aux_weight, ignore_index=-1).to(args.device)' into 'self.criterion = MixSoftmaxCrossEntropyLoss()' it can work, why ?
OHEM loss is for cityscapes.
null
If you use deep supervision, please set aux=True
.
yeah ,now my training is set aux=True ,I will observe the result, looks like the loss value don't drop.
Perhaps the format of the target is wrong, whose shape should be [6, 512, 512]
with value 0
and 1
.
the target shape include the number of classes, because I find the inital training's output is [12,19,512,512]
Target should be single channel.
yes, I change three channel into singel with the value 0 and 1
Does the training process converge?
No, the loss value 0.4 ~0.9 , I'm trying to modify the lr
Try to increase the learning rate.
@Tramac If I choose 'self.criterion = MixSoftmaxCrossEntropyLoss( )' , should I add ignore_index=-2 or other values than 0,1 ?
@feitiandemiaomi ,@Tramac
Hi,I meet the same problem,I want to train myself dataset which have binary masks
.
Then I used self.criterion = MixSoftmaxCrossEntropyLoss( )
instead of self.criterion = MixSoftmaxCrossEntropyOHEMLoss
.
And set aux=True
. However,the shape of outputs
and target
are torch.Size([4, 2, 768, 768]) torch.Size([768, 768])
,is this normal?And how to set the ignore_index
?Can you give some advice? Thank you!
@Tramac @BorisTestov @prianchoI try to use the coco dataset and only include two classes person and background , when I train ,the errors are follows:
_File "train.py", line 203, in
trainer.train()
File "train.py", line 139, in train
loss = self.criterion(outputs, targets)
File "/home/data/anaconda3/envs/caffe2_py36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in call
result = self.forward(*input, kwargs)
File "/home/data/code/Fast-SCNN-pytorch/utils/loss.py", line 120, in forward
return super(MixSoftmaxCrossEntropyOHEMLoss, self).forward(inputs)
File "/home/data/code/Fast-SCNN-pytorch/utils/loss.py", line 96, in forward
return self.criterion(predict, target)
File "/home/data/anaconda3/envs/caffe2_py36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in call
result = self.forward(input, kwargs)
File "/home/data/anaconda3/envs/caffe2_py36/lib/python3.6/site-packages/torch/nn/modules/loss.py", line 942, in forward
ignore_index=self.ignore_index, reduction=self.reduction)
File "/home/data/anaconda3/envs/caffe2_py36/lib/python3.6/site-packages/torch/nn/functional.py", line 2056, in cross_entropy
return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction)
File "/home/data/anaconda3/envs/caffe2_py36/lib/python3.6/site-packages/torch/nn/functional.py", line 1873, in nll_loss
ret = torch._C._nn.nll_loss2d(input, target, weight, _Reduction.get_enum(reduction), ignoreindex)
RuntimeError: weight tensor should be defined either for all or no classes at /pytorch/aten/src/THCUNN/generic/SpatialClassNLLCriterion.cu:27
Do you have any suggestion or solution? I don't know how to slove it.