zhanghang1989 / zhanghang1989/PyTorch-Encoding
Potential Interface Inconsistency between SegmentationLosses and DataParallelCriterion
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2k
- Forks
- 448
- PR merge metrics
- No merged PRs in 30d
Description
First of all, thanks a lot for your excellent code! I found a potential bug in calculating segmentation loss.
If not using CUDA
self.criterion = DataParallelCriterion(self.criterion).cuda()
is not executed, and self.criterion is a SegmentationLosses object. When it calls the criterion at this position,
outputs = self.model(image)
loss = self.criterion(outputs, target)
wouldn't it cause error in this case?
def forward(self, *inputs):
...
pred1, se_pred, pred2, target = tuple(inputs)
Since it is trying to execute pred1, se_pred, pred2, target = (outputs, target).
In the case of using CUDA
self.criterion is a DataParallelCriterion object. It calls SegmentationLosses in a proper way
output = module(*(input + target), **kwargs)
Conclusion
There is interface inconsistency between SegmentationLosses and DataParallelCriterion. I think their calling should be different, e.g.
if args.cuda:
loss = self.criterion(outputs, target)
else:
loss = self.criterion(*(list(outputs) + [target]))
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with experiments/segmentation/train.py around the criterion setup and call, then compare encoding/nn/loss.py with encoding/parallel.py to trace the CPU and CUDA argument shapes. Reproduce segmentation training without CUDA and verify that the criterion interface works consistently in both modes without an argument-unpacking error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-vision, machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100