RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #2 'target' in call to _thnn_nll_loss_forward

Hi, I am trying to solve a computer vision problem but I am encountering this error:
RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #2 'target' in call to _thnn_nll_loss_forward

I am using crossentropyloss. Here is my dataset class:

class CassavaDataset(Dataset):

    def __init__(self, df, root, transform=None):

        self.df= df

        self.root = root

        self.transform = transform

    def __len__(self):

        return self.df.shape[0]

    def __getitem__(self, idx):

        img_name = self.df.image_id[idx]

        target = self.df.label[idx]

        img_path = self.root + str(img_name)

        image = cv2.imread(img_path)

        image = image[:, :, ::-1]

        if self.transform:

            image = self.transform(image=image)["image"]

        

        return {

            "image": torch.tensor(image, dtype=torch.float32),
            "target": torch.tensor(target, dtype=torch.long)

        }

If someone can help me it would be great!
Thanks.

@ptrblck Can you please help this is urgent.
Thanks

As the error message explains, the target tensor for nn.CrossEntropyLoss should be a LongTensor, while apparently a FloatTensor is passed.
The custom Dataset looks correct, so I assume the target is either generated in another code snippet or transformed after being returned by the Dataset.__getitem__.