You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
When we instantiate an instance of type class ContrastiveLoss we need to pass in the parameter for batch_size. This assumes that the batch size remains constant all through the training(which is not always the case).
Describe the solution you'd like
As we know and have fixed in the docs that the forward accepts inputs of shape B[F], why not pick up the Batch size dynamically in the forward. Is there a reason why it is not designed in that fashion?
I would be happy to put a pull request if it is okay.
@a-parida12 Please go ahead and send a PR, I feel we should make the dynamic part optional so that we don't break existing code for other users and keep the default dynamic_batch_size=False
We need insights from @wyli if it's okay for the optional idea :)
Thanks, @finalelement! I thought the majority of the losses from PyTorch don't require that the batch size be known and fixed so extending that to this too. But you are right we need to be backward compatible too.
How about I raise a "warning" when the batch_size parameter is set to let users know it is unnecessary ?
Also will wait for @wyli 's input and then begin the PR.
Activity
finalelement commentedon Sep 2, 2022
@a-parida12 Please go ahead and send a PR, I feel we should make the dynamic part optional so that we don't break existing code for other users and keep the default dynamic_batch_size=False
We need insights from @wyli if it's okay for the optional idea :)
a-parida12 commentedon Sep 3, 2022
Thanks, @finalelement! I thought the majority of the losses from PyTorch don't require that the batch size be known and fixed so extending that to this too. But you are right we need to be backward compatible too.
How about I raise a "warning" when the
batch_sizeparameter is set to let users know it is unnecessary ?Also will wait for @wyli 's input and then begin the PR.
a-parida12 commentedon Sep 3, 2022
Also tagging this discussion for the completeness of my motivation Project-MONAI/tutorials#624 (comment)
wyli commentedon Sep 6, 2022
yes please go ahead, would be great to automatically infer the batch size whenever possible.
Updated Contrastive Loss batch Size (#5093)
Updated Contrastive Loss batch Size (Project-MONAI#5093)