PyTorch-adapt Multi-label classifications #100
-
Hi Kevin, I have a multi-label classification problem, and I wanted to use PyTorch-adapt. I wrote a code for four hooks, but the model weights do not change. Is there something I need to change in hooks for multi-label classifications to work? Best regards, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You need to change An alternative is to "monkey patch" the init function of import torch
from pytorch_adapt.hooks import CLossHook
def init_modifier(method):
def modify(self, *args, **kwargs):
method(self, *args, **kwargs)
self.loss_fn = torch.nn.BCEWithLogitsLoss()
return modify
CLossHook.__init__ = init_modifier(CLossHook.__init__) Then every hook that uses You might get a type error during training with from pytorch_adapt.hooks.classification import BCEWithLogitsConvertLabels |
Beta Was this translation helpful? Give feedback.
You need to change
CLossHook
's loss function totorch.nn.BCEWithLogitsLoss
. The hook you're using should allow you to pass in a customc_hook
or something like that. I can help more with this if you tell me which hook you're using.An alternative is to "monkey patch" the init function of
CLossHook
:Then every hook that uses
CLossHook
will now be usingtorch.nn.BCEWithLogitsLoss
.You might get a type error du…