I wanted to use the data augmentations pipeline of fast.ai in some other repository which didn't use fast.ai. Here are examples to use the aug_transforms
.
Apply on a batch:
from fastai.vision.all import *
for batch, labels in train_loader:
break
fastai_transforms_train = aug_transforms(mult=3, size=768)
fast_batch = TensorImage(batch).float()
for tfm in fastai_transforms_train: fast_batch = tfm(fast_batch, split_idx=0)
Apply on a single image:
def fastai_transforms(self, img):
img = TensorImage(img).permute(2, 0, 1)[None].float() / 255
for tfm in self.fastai_transforms_train: img = tfm(img, split_idx=0)
img = img[0].permute(1, 2, 0) * 255
img = PIL.Image.fromarray(img.byte().numpy())
return img