Torchvision functional transforms with Compose

Hi Everyone, I am working with the ImageNet dataset. As a part of the experiments, I want to shift the input images right by 10 pixels (among other affine transforms).

I can’t use torchvision.transforms.RandomAffine because I want deterministic transformations. So I’m left with torchvision.transforms.functional.affine.

Any idea how I could plug it in as a part of a pipeline made with transforms.Compose?

From what I see in the codebase, it seems easy enough by wrapping affine inside a class and call it inside __call__. Is this the right way to go about this or are there better ways to do this?

Your suggestion should work. Alternatively you could use transforms.Lambda to warp your functional transformation.

1 Like