How to convert images to Variable

train_dataset = dsets.CIFAR100(root=’…/…/data/’,
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?

u need to use, u can check it here

In general,i use 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

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. 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.