Is there an easy way (via transforms or otherwise) to scale image data from the range of 0 to 1 (the default) to -1 to 1?
In pure pytorch, using functional transforms, that would look something like this:
import torchvision.transforms.functional as TF from PIL import Image image = Image.open('path_to_image.png') image_tensor = TF.to_tensor(TF.resize(image, 256)) * 2 - 1
I think adding a custom transform could do the trick. Something like this maybe?
@transforms def rescale(x:TensorImage): return (x - x.min()) / (x.max() - x.min())
Then add this as batch_tfms to the DataLoader. Maybe the convenience functions like, ImageDataLoaders.from_XXX will not work with this and you have to build a DataBlock first, then creating DataLoaders from it.
batch_tfms
ImageDataLoaders.from_XXX
DataBlock
DataLoaders