I am reviewing 05_pet_breeds.ipynb from the fastai book and trying out some of the code snippet. When I went through the code snippet on Presizing, I get a randomness on data augmentation that I can’t explain.
Reproducing the Issue
from fastai2.vision.all import *
path = untar_data(URLs.PETS)
dblock1 = DataBlock(blocks=(ImageBlock(), CategoryBlock()),
get_y=parent_label,
item_tfms=Resize(460))
dls1 = dblock1.dataloaders([(path/'images'/'Ragdoll_202.jpg')]*100, bs=8)
dls1.train.get_idxs = lambda: Inf.ones
SIZE = 224
x,y = dls1.valid.one_batch()
_,axs = subplots(1, 2, figsize = (16, 8))
x1 = TensorImage(x.clone())
x1 = x1.affine_coord(sz = SIZE)
x1 = x1.rotate(draw = 30, p = 1.)
x1 = x1.zoom(draw = 1.2, p = 1.)
x1 = x1.warp(draw_x = -0.2, draw_y = 0.2, p = 1.)
tfms = setup_aug_tfms([Rotate(draw = 30, p = 1, size = SIZE),
Zoom(draw = 1.2, p = 1., size = SIZE),
Warp(draw_x=-0.2, draw_y=0.2, p=1., size = SIZE)])
x = Pipeline(tfms)(x)
#x.affine_coord(coord_tfm=coord_tfm, sz=size, mode=mode, pad_mode=pad_mode)
TensorImage(x[0]).show(ctx=axs[0])
TensorImage(x1[0]).show(ctx=axs[1]);
Here is what I got when execute the code:
There are 2 things I don’t understand:
- The transformation on left hand side (from batch transform) should align with that on right hand side (from manual transform), but it is not the case
- When I execute the code several times, I get different results. The randomness looks strange to me because (i) the data augmentation are all deterministic (rotation, zooming, warping all with p = 1), (ii) the sample is from validation set so Resize(460) should deterministically crop at center instead of at random place.
Could any fellows give me some clues on that?