Spaces:
Running
on
Zero
Running
on
Zero
File size: 735 Bytes
4893ce0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
"""
Criteria Builder
Author: Xiaoyang Wu ([email protected])
Please cite our work if the code is helpful to you.
"""
from pointcept.utils.registry import Registry
LOSSES = Registry("losses")
class Criteria(object):
def __init__(self, cfg=None):
self.cfg = cfg if cfg is not None else []
self.criteria = []
for loss_cfg in self.cfg:
self.criteria.append(LOSSES.build(cfg=loss_cfg))
def __call__(self, pred, target):
if len(self.criteria) == 0:
# loss computation occur in model
return pred
loss = 0
for c in self.criteria:
loss += c(pred, target)
return loss
def build_criteria(cfg):
return Criteria(cfg)
|