zhanghang1989 / zhanghang1989/PyTorch-Encoding

Potential Interface Inconsistency between SegmentationLosses and DataParallelCriterion

Open
#165 0 comments 0 reactions 0 assignees View on GitHub

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

This line

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.