gopalkrizna
gopalkrizna

Reputation: 826

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

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!

Upvotes: 5

Views: 17891

Answers (2)

ryou ro
ryou ro

Reputation: 11

    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])])

Upvotes: 1

Rose W.
Rose W.

Reputation: 126

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.

Upvotes: 11

Related Questions