How to use correctly multilabel classification in pytorch

Hi guys, I have some csv file with structure

  img |class0|class1|class2|class3|class4|class5...
|-----|------|------|------|------|------|------
|path1|0     |0     |1     |0     |0     |1     
|path2|0     |1     |1     |0     |1     |0     
|path3|0     |0     |0     |1     |0     |0     
.................................................
.................................................
|pathn|1     |1     |0     |1     |0     |0     
|-----|------|------|------|------|------|------
class mydataset(Dataset):
...
def __getitem__(self,idx):
...
labels=np.array(self.labels.iloc[idx,1:])    
    return {'img':img,'labels':labels}

I am trying to use

n_classes=df.shape[0]-1
model = EfficientNet.from_pretrained('efficientnet-b1',num_classes=n_classes).to(device) 

with

loss = torch.nn.BCELoss()

but it doesn’t work, how to implement in my case multilabel classification?

What is the exact error you are getting in this case?

You might want to check that the datatype of labels is a torch tensor as expected.

The documentation shows a simple of example of input being passed to the loss function: BCELoss — PyTorch 1.9.0 documentation
although in your case you will likely also have a batch dimension.