Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support multiple losses during training #818

Merged
merged 15 commits into from
Sep 24, 2021
Prev Previous commit
Next Next commit
Fixing loss_ prefix
  • Loading branch information
MengzhangLI committed Sep 22, 2021
commit 4dba853c0974baf2c816b870bd708dda1d29493a
2 changes: 1 addition & 1 deletion tests/test_models/test_heads/test_decode_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,4 @@ def test_decode_head():
loss = head.losses(seg_logit=inputs, seg_label=target)
assert 'loss_ce' in loss
assert 'loss_1' in loss
assert 'loss_2' in loss
assert 'loss_2' in loss
13 changes: 9 additions & 4 deletions tests/test_models/test_losses/test_lovasz_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ def test_lovasz_loss():

# reduction should be 'none' when per_image is False.
with pytest.raises(AssertionError):
loss_cfg = dict(type='LovaszLoss', loss_type='multi_class',
loss_name='loss_lovasz')
loss_cfg = dict(
type='LovaszLoss',
loss_type='multi_class',
loss_name='loss_lovasz')
build_loss(loss_cfg)

# test lovasz loss with loss_type = 'multi_class' and per_image = False
loss_cfg = dict(type='LovaszLoss', reduction='none', loss_weight=1.0,
loss_name='loss_lovasz')
loss_cfg = dict(
type='LovaszLoss',
reduction='none',
loss_weight=1.0,
loss_name='loss_lovasz')
lovasz_loss = build_loss(loss_cfg)
logits = torch.rand(1, 3, 4, 4)
labels = (torch.rand(1, 4, 4) * 2).long()
Expand Down