Tramac / Fast-SCNN-pytorch

A PyTorch Implementation of Fast-SCNN: Fast Semantic Segmentation Network
Apache License 2.0
381 stars 93 forks source link

Semantic segmentation for binary masks (2 class: background/persono) #12

Closed feitiandemiaomi closed 5 years ago

feitiandemiaomi commented 5 years ago

@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.

Tramac commented 5 years ago

Please print the shape of outputs and target. And what's the classes value in your target?

feitiandemiaomi commented 5 years ago

torch.Size([6, 2, 512, 512]) torch.Size([6, 2, 512, 512])

feitiandemiaomi commented 5 years ago

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 ?

Tramac commented 5 years ago

OHEM loss is for cityscapes.

feitiandemiaomi commented 5 years ago

null

Tramac commented 5 years ago

If you use deep supervision, please set aux=True.

feitiandemiaomi commented 5 years ago

yeah ,now my training is set aux=True ,I will observe the result, looks like the loss value don't drop.

Tramac commented 5 years ago

Perhaps the format of the target is wrong, whose shape should be [6, 512, 512] with value 0 and 1.

feitiandemiaomi commented 5 years ago

the target shape include the number of classes, because I find the inital training's output is [12,19,512,512]

Tramac commented 5 years ago

Target should be single channel.

feitiandemiaomi commented 5 years ago

yes, I change three channel into singel with the value 0 and 1

Tramac commented 5 years ago

Does the training process converge?

feitiandemiaomi commented 5 years ago

No, the loss value 0.4 ~0.9 , I'm trying to modify the lr

Tramac commented 5 years ago

Try to increase the learning rate.

feitiandemiaomi commented 5 years ago

@Tramac If I choose 'self.criterion = MixSoftmaxCrossEntropyLoss( )' , should I add ignore_index=-2 or other values than 0,1 ?

yanzhou-li commented 3 years ago

@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!