DataLoader TypeError: img should be PIL Image. Got <class 'numpy.ndarray'>

I have .npy dataset file and It works fine when transform=None.
But when I apply transform=transform_train,
TypeError: img should be PIL Image. Got <class 'numpy.ndarray'> occurs.
How can I fix it?

import numpy as np
import os

class CIFAR10:
    def __init__(self, root='/database', split="l_train", transform=None):
        self.dataset = np.load(os.path.join(root, "cifar10", split + ".npy"), allow_pickle=True).item()
        self.transform = transform

    def __getitem__(self, idx):
        image = self.dataset["images"][idx]
        label = self.dataset["labels"][idx]
        # print(type(image)) # <class 'numpy.ndarray'>
        if self.transform is not None:
            image = self.transform(image)
        return image, label

    def __len__(self):
        return len(self.dataset["images"])

transform_train = transforms.Compose([
    transforms.Normalize(mean, std)
trainset_x = CIFAR10(split='l_train', transform=transform_train)

Pytorch transform accept PIL Image, Tensor image or batch of tensor images as input.

Reference: torchvision.transforms — Torchvision master documentation

Maybe you can add this to your code, test whether it works:

from PIL import Image

image = Image.fromarray(self.dataset["images"][idx]