Problem using aug_transforms for data augmentation

Hello. I’m a new user of fastai. I’ve searched for similar questions but still failed to solve the problem.

My problem was the code for data augmentation successfully ran, but appeared to have no effect on my images.

I tried to implement the data augmentation technique of lesson3-head-nose on my own dataset (CT medical images in png format, regression task to predict coordinate). The following code successfully ran. However, the demonstration from show_batch is exactly the same as my original input. Does anyone have idea? Thanks a lot.

dblock = DataBlock(blocks=(ImageBlock, PointBlock),
               get_items=repeat_image_slice,
               splitter=RandomSplitter(),
               get_y=get_cor)

tfms = aug_transforms(max_rotate=20, max_zoom=1.5, max_lighting=0.5, max_warp=0.4, p_affine=1., p_lighting=1.)

dls = dblock.dataloaders(data_dir, path=data_dir, bs=3, batch_tfms=[*tfms, Normalize.from_stats(*imagenet_stats)])

dls.show_batch(max_n=3, figsize=(8,6))

Aug_transforms also doesn’t work on the code of the previous lesson (lesson 3 in the tutorial of fastai v1). The function appeared to be incompatible with the new version of fastai. Also, there seems to be no equivalent functions in fastai v2.

Sure. IIRC show_batch may use the validation rather than the training dataset, which may lead to your discrepancy. I’d suggest trying:

dls[0].show_batch() (this can also be written as dls.train) to see the augmentation done by aug_transforms to the training dataset. Anything that affects Affine (such as rotation, brightness, etc are not done on the validation set)

1 Like

Thanks a lot for your reply! I’ve tried the method you suggested. However, the result was the same. I duplicated one of my images, and the augmentation had no effect on the images.
BTW, could you kindly provide some examples of data augmentation for images in the new version? It would be a great help to me.
I’ve scanned through the notebooks for the new lessons. (https://course.fast.ai/start_colab) However, only resize and normalize are introduced and used in the new lessons. The data augmentation tools applied in the v1 lessons wasn’t applied in the new version on the same datasets.

You could check this Image Augmentation. Written about 5 months ago so is version 2 but there may be some changes in the code. Maybe because you do not have a ‘batch_tfms’

I got the same problem, and after trying the solutions provided here, it didn’t work…but restarting my notebook session in kaggle, and running all the code there fixed the problem