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

[Fix] update build loss api #3587

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
--fix=update build loss api
  • Loading branch information
xiexinch committed Mar 8, 2024
commit a5e0629ac12e3d187c3cb6fce8761d7724ab2e45
6 changes: 3 additions & 3 deletions mmseg/models/decode_heads/decode_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from mmengine.model import BaseModule
from torch import Tensor

from mmseg.registry import MODELS
from mmseg.structures import build_pixel_sampler
from mmseg.utils import ConfigType, SampleList
from ..builder import build_loss
from ..losses import accuracy
from ..utils import resize

Expand Down Expand Up @@ -140,11 +140,11 @@ def __init__(self,
self.threshold = threshold

if isinstance(loss_decode, dict):
self.loss_decode = build_loss(loss_decode)
self.loss_decode = MODELS.build(loss_decode)
elif isinstance(loss_decode, (list, tuple)):
self.loss_decode = nn.ModuleList()
for loss in loss_decode:
self.loss_decode.append(build_loss(loss))
self.loss_decode.append(MODELS.build(loss))
else:
raise TypeError(f'loss_decode must be a dict or sequence of dict,\
but got {type(loss_decode)}')
Expand Down
3 changes: 1 addition & 2 deletions mmseg/models/decode_heads/enc_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from mmseg.registry import MODELS
from mmseg.utils import ConfigType, SampleList
from ..builder import build_loss
from ..utils import Encoding, resize
from .decode_head import BaseDecodeHead

Expand Down Expand Up @@ -128,7 +127,7 @@ def __init__(self,
norm_cfg=self.norm_cfg,
act_cfg=self.act_cfg)
if self.use_se_loss:
self.loss_se_decode = build_loss(loss_se_decode)
self.loss_se_decode = MODELS.build(loss_se_decode)
self.se_layer = nn.Linear(self.channels, self.num_classes)

def forward(self, inputs):
Expand Down
5 changes: 2 additions & 3 deletions mmseg/models/decode_heads/vpd_depth_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from mmseg.registry import MODELS
from mmseg.utils import SampleList
from ..builder import build_loss
from ..utils import resize
from .decode_head import BaseDecodeHead

Expand Down Expand Up @@ -184,11 +183,11 @@ def __init__(

# build loss
if isinstance(loss_decode, dict):
self.loss_decode = build_loss(loss_decode)
self.loss_decode = MODELS.build(loss_decode)
elif isinstance(loss_decode, (list, tuple)):
self.loss_decode = nn.ModuleList()
for loss in loss_decode:
self.loss_decode.append(build_loss(loss))
self.loss_decode.append(MODELS.build(loss))
else:
raise TypeError(f'loss_decode must be a dict or sequence of dict,\
but got {type(loss_decode)}')
Expand Down