Manually running RandomResizeCrop

I’m using code from Data augmentation in computer vision | fastai, trying to manually run some transforms to see how they look with my data and to play with some of the options.

When I run the code below I get a grid of 9 images, but they are all identical. No cropping or resizing, no random erasing, also no error messages. If I uncomment the brightness code I do get randomly brightened/darkened images, so that seems to be working.

I can use the technique from 02_production_experiment.ipynb where I create a new DataBlock and dataloader each time, then show a batch, but that is slower and more indirect and doesn’t explain why the code from the documentation doesn’t work. Edited: Actually, even this doesn’t seem to work for RandomErasing.

h = TensorImage(img1[None].expand(3, *img1.shape).clone())
tfm = RandomResizedCrop(64,p=0.5)
#tfm = RandomErasing(p=1., max_count=6)
_,axs = plt.subplots(3,3,figsize=(12,12))
for ax in axs.flatten():
    #h2 = h.brightness(p=1.0)
    #cropped = h2[0]
    cropped = tfm(img1)
    show_image(cropped, ctx=ax);

img1 is:
(fastai.torch_core.TensorImage, torch.Size([3, 256, 256]))

fastai v2.5.3

Any suggestions would be appreciated.

You need to set split_idx=0. See the docs for more details and examples.

1 Like