BCEWithLogitsLoss is accepting labels of list

I have a dataset where each image can have 14 labels. So i have converted labels of each image to format [0,1,0,0,1,0,0,1,0,0,0,1,1,0] and trying to apply BCEWithLogitsLoss.
inputs should come from NN and target is 14 label list.

like below

def getitem(self, idx):
if torch.is_tensor(idx):
idx = idx.tolist()
img_path = self.img_list[idx][0]
image = Image.open(img_path).convert(‘RGB’)
if self.transform:
image = self.transform(image)
#sample = {‘img’: image,
# ‘label’: self.img_list[idx][1]}
#return sample
label = self.img_list[idx][1]
return image,label

############## Training function

outputs = model(inputs)
loss = criterion(outputs, labels) ----> error line

Kindly suggest how to train multi label classifier if i am doing wrong

Error Message is like below

51 outputs = model(inputs)
—> 52 loss = criterion(outputs, labels)
53
54 _, preds = torch.max(outputs, 1)

/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
720 result = self._slow_forward(*input, **kwargs)
721 else:
–> 722 result = self.forward(*input, **kwargs)
723 for hook in itertools.chain(
724 _global_forward_hooks.values(),

/usr/local/lib/python3.6/dist-packages/torch/nn/modules/loss.py in forward(self, input, target)
629 self.weight,
630 pos_weight=self.pos_weight,
–> 631 reduction=self.reduction)
632
633

/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in binary_cross_entropy_with_logits(input, target, weight, size_average, reduce, reduction, pos_weight)
2535 reduction_enum = _Reduction.get_enum(reduction)
2536
-> 2537 if not (target.size() == input.size()):
2538 raise ValueError(“Target size ({}) must be the same as input size ({})”.format(target.size(), input.size()))
2539

AttributeError: ‘list’ object has no attribute 'size’

I have solved it by converting the list of labels to tensor.

instead of this:

label = self.img_list[idx][1]

Used the below line

label = torch.tensor(self.img_list[idx][1] , dtype=torch.float32)