ShichenLiu / SoftRas

Project page of paper "Soft Rasterizer: A Differentiable Renderer for Image-based 3D Reasoning"
MIT License
1.2k stars 156 forks source link

IoU loss #85

Closed YanhaoZhang closed 3 years ago

YanhaoZhang commented 3 years ago

Hi, thanks a lot for releasing the code. I am trying to use the image rendering and IoU loss as proposed in demo_deform.py. May I know the size of the two inputs of this function, i.e., predict and target? Are they [B, H, W] or [H, W]? Thanks a lot.


    def neg_iou_loss(predict, target):
        dims = tuple(range(predict.ndimension())[1:])
        intersect = (predict * target).sum(dims)
        union = (predict + target - predict * target).sum(dims) + 1e-6
        return 1. - (intersect / union).sum() / intersect.nelement()
ShichenLiu commented 3 years ago

Hi,

I suppose they are [B, H, W]. Since we compute dims as tuple(range(predict.ndimension())[1:]), I think the purpose of [1:] here is to remove the batch dimension. You can also verify this by printing the tensor shape while calling the function. Actually, it can be any shape starting with the batch dimension, e.g. [B, N], [B, 1, H, W], etc.

YanhaoZhang commented 3 years ago

@ShichenLiu Got it. Thanks a lot for your prompt reply. Now I understand it. :+1: