How to convert images to Variable

train_dataset = dsets.CIFAR100(root=’…/…/data/’,
train=True,
transform=transform,
download=True)
images, labels = train_dataset[0]

images = Variable(image.cuda()) # error!
labels = Variable(label.cuda())
outputs = resnet(images)
loss = criterion(outputs, labels)

I want to convert it to a net inputs, and calc net’s gradients
How to convert image to Variable?
thanks

u need to use torch.utils.data.DataLoader, u can check it here

In general,i use torch.utils.data.DataLoader to load image, but i have to filter some images with images dataset. how to filter some images what i don’t to use with torch.utils.data.DataLoader?
thanks

I don’t know how to do it with dataloader, maybe u need to do it by yourself, u need to write a function to filter the images.

Make sure your transform contains torchvision.transforms.ToTensor.

torch.utils.data.DataLoader is not neccessary, just rewrite your dsets.CIFAR100's __getitem__ and `len`` to filter some images.

thanks, sometime,i find pytorch data type converting is diffcult :slight_smile:

thank you, i have used some other way to do it.