LIVIAETS / boundary-loss

Official code for "Boundary loss for highly unbalanced segmentation", runner-up for best paper award at MIDL 2019. Extended version in MedIA, volume 67, January 2021.
https://doi.org/10.1016/j.media.2020.101851
MIT License
647 stars 97 forks source link

Does einsum really make the code easier to understand #43

Closed milesial closed 3 years ago

milesial commented 3 years ago

Hey,

I see that in the code for the loss you use the einsum multipled = einsum("bkwh,bkwh->bkwh", pc, dc).

Also in the README, you explain that for 3D we need to change it to multipled = einsum("bkxyz,bkxyz->bkxyz", pc, dc).

What is the point of using einsums if the underlying op is just pc * dc?

HKervadec commented 3 years ago

Hello,

I kept the einsum both for consistency with the rest of the code, and also to automatically document the code: it describes exactly the shape of each tensors used, and will error if fed something with a different shape.

I find it much easier to follow, especially when coming back to the codebase after a while.

See also this older issue: https://github.com/LIVIAETS/boundary-loss/issues/3#issuecomment-450499897

Best,

Hoel

milesial commented 3 years ago

Ok, it makes sense, thanks!