Transforms.compose seems not work


(One Taken) #1

I wrote this code to transform image:

import torchvision.transforms as trasnfroms
import PIL.Image as Image

mean = [0.485, 0.456, 0.406]
std = [0.229, 0.224, 0.225]
transform = transforms.Compose([transforms.resize(size=256),
transforms.RandomCrop(size=224),
transforms.to_tensor(),
transorms.normalize(mean=mean,std=std)])

img = Image.open(imgname)
tensor = transform(img)

It seems no problem. And this code raise a type error:

TypeError: resize missing 1 required positional argument: 'img'

What’s wrong?
I can’t find the errors.


(One Taken) #2

Sorry, I find the bugs.
the code should be as follows:

transform = transforms.Compose([transforms.Resize(256),
transforms.RandomCrop(224),
transforms.ToTensor(),
transforms.Normalize(mean, std)])