AttributeError: 'Compose' object has no attribute 'Compose' (in Pytorch 0.2.1)

Question:

This is the block of code where am getting this error:

train_transforms = transforms.Compose([transforms.RandomRotation(30),
                                       transforms.RandomResizedCrop(224),
                                       transforms.RandomHorizontalFlip(),
                                       transforms.ToTensor(),
                                       transforms.Normalize([0.5, 0.5, 0.5], 
                                                            [0.5, 0.5, 0.5])])

I’ve tried updating my torchvision but had no luck!

Asked By: gopalkrizna

||

Answers:

The problem is that you have a variable called transforms after from torchvision import transforms which has a compose of a certain type. This override the transform you import from the torchvison. Therefore when you run the above code it calls the transforms which is a variable not the one from torchvision module.

It is advisable to rename the variable or if you are using jupyter notebook run the cell where you import transforms before running the cell with the code above.

Answered By: Rose W.
    train_transforms = torchvision.transforms.Compose([torchvision.transforms.RandomRotation(30), enter code here                                      torchvision.transforms.RandomResizedCrop(224),                                       torchvision.transforms.RandomHorizontalFlip(),
                                   torchvision.transforms.ToTensor(),
                                   torchvision.transforms.Normalize([0.5, 0.5, 0.5], 
                                                        [0.5, 0.5, 0.5])])
Answered By: ryou ro
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.