ChamferDist类的__call__函数:
@LOSSES.register_module
class ChamferDist(BaseLoss):
def __call__(self, pointset1, pointset2):
'''
calculate the chamfer distance between two point sets.
:param pointset1 (B x N x 3): torch.FloatTensor
:param pointset2 (B x N x 3): torch.FloatTensor
:return:
'''
dist1, dist2 = chamfer_func(pointset1, pointset2)[:2]
loss = self.weight * ((torch.mean(dist1)) + (torch.mean(dist2)))
return loss
chamferDistLoss = LOSSES.get('ChamferDist', 'Null')
loss, _ = chamferDistLoss(v, gt_pc)
TypeError: init() takes from 1 to 2 positional arguments but 3 were given
调用类的__call__方法,该方法不是静态方法,需要用类的实例来调用,而不能直接用类名调用。
上面的代码第一行得到的是类名,没有加括号得到类的实例,应该改成:
chamferDistLoss = LOSSES.get('ChamferDist', 'Null')()
loss, _ = chamferDistLoss(v, gt_pc)