minmax
November 27, 2022, 4:21am
1
I have loaded the resnet50’s transformations from the weights
resnet_50_weights = ResNet50_Weights.IMAGENET1K_V2
resnet_50_model = resnet50(weights=resnet_50_weights)
resnet_50_transformations = resnet_50_weights.transforms()
However I would like to add another transformation to this, say transforms.RandomRotation(15, expand=True)
How would I add this. Using Compose threw an error
ptrblck
November 27, 2022, 9:34pm
2
It seems to work for me:
resnet_50_weights = models.resnet.ResNet50_Weights.IMAGENET1K_V2
resnet_50_transformations = resnet_50_weights.transforms()
trans = transforms.Compose([
resnet_50_transformations,
transforms.RandomRotation(15, expand=True)
])
x = torch.randn(3, 224, 224)
ref = resnet_50_transformations(x)
out = trans(x)
plt.imshow(ref.permute(1, 2, 0).numpy())
plt.imshow(out.permute(1, 2, 0).numpy())
Output:
ref
:
out
: