If I have the dataset as two arrays X and y as images and labels, both are numpy arrays. I want to apply transforms (like those from models given by the pretrainedmodels package), how can apply them on my data, especially as the way as datasets.ImageFolder.

My numpy arrays are converted from PIL Images, and I found how to convert numpy arrays to dataset loaders here.

Thanks @yvanscher. But it seems that transforms accept img as input, not tensors. See the pil_loader function and DatasetFolder.__getitem__ method here.

Now I decide to save the PIL image in the numpy arrays, without converting to numpy array with np.array(img). Then I might be able to use transform, and then TensorDataset and DataLoader ā¦

import numpy as np
from torchvision import transforms
X = np.random.randint(low=0, high=255, size=(32,32,3), dtype=np.unit8) # an image in ndarray format
your_transforms = transforms.Compose([transforms.CenterCrop(10),transforms.ToTensor(),]) # a set of transformations
if isinstance(X, np.ndarray):
your_transforms.transforms.insert(0, transforms.ToPILImage())

Now given what you found on the other page, we can do this: