LCFCN icon indicating copy to clipboard operation
LCFCN copied to clipboard

Batch-aware loss function?

Open yassineAlouini opened this issue 3 years ago • 3 comments

As far as I my understanding goes, the lcfcn loss works with one sample per batch. Is that really the case?

If so, how hard would it be to adapt it to more than one sample per batch?

I have tried this code:

loss = torch.mean(
    torch.Tensor(
        [
            lcfcn_loss.compute_loss(points=points[i], probs=logits[i].sigmoid())
            for i in range(points.shape[0])
        ]
    )
)

Could that work? :thinking:

Thanks for any help!

yassineAlouini avatar Mar 25 '21 09:03 yassineAlouini

Hiya @yassineAlouini , what you suggested should work! It might be a bit slow, and the learning rate might need to be adjusted.

LCFCN does not work natively with batch sizes larger than one, mainly because the watershed algorithm does not support more than one image. If there is a Pytorch-based watershed method, then we could incorporate it and make LCFCN support larger batches.

Thanks for the nice, concise code in making the code support batches larger than 1.

IssamLaradji avatar Mar 29 '21 19:03 IssamLaradji

Indeed, watershed is probably the limiting part for now. I will have a look at a pytorch implementation and update with more details. Thanks for the quick feedback.

yassineAlouini avatar Apr 01 '21 07:04 yassineAlouini

I have found this: https://paperswithcode.com/paper/deep-watershed-transform-for-instance. Not sure how useful it could be, I probably need some exploration to see if we can extract the watershed part of it.

Here is a Pytorch implementation: https://github.com/timothyn617/watershed-transform

yassineAlouini avatar Apr 02 '21 08:04 yassineAlouini