A lot of torchvision.transforms are a simple class with a __call__ method as seen here 4. You could thus implement a custom class using this template or you could alternatively also use transforms.Lambda 6, which would accept your custom function.