I am taking part in a Multi-Label Classification problem I have created my complete training and validation pipleline but I can’t train because of this error:
ValueError: Target size (torch.Size([16, 19])) must be the same as input size (torch.Size([16, 432]))
I am using the nn.BCEWithLogitsLoss() loss function.
Here is my dataset class:
class HPADataset(Dataset):
    def __init__(self, train_df, train_dir, transform=None):
        self.df = train_df
        self.train_path = train_dir
        self.transform = transform
        self.filter = ['blue', 'yellow', 'red']
        
    def __len__(self):
        return len(self.df)
    
    def __getitem__(self, item):
        name = self.df.ID[item]
        img = [cv2.imread(os.path.join(self.train_path, f'{name}_{filter_}.png'), cv2.IMREAD_GRAYSCALE) for filter_ in self.filter]
        img = np.stack(img, axis=-1)
        target = self.df.Label[item]
        target = encode_label(target)
        
        if self.transform:
            img = self.transform(image=img)
            img = img["image"]
#             img = np.transpose(img, )
            
        return {
            "image": torch.tensor(img, dtype=torch.float32),
            "target": target
        }

The data looks like this:

and I have encoded the labels to look like this:
tensor([1., 0., 0., 0., 0., 1., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]) (Essentially a one-hot encoding)
It would be great if someone could help me.
Thanks