Applying Individual Transforms from `get_transforms`

get_transforms creates a list of transforms. I want to check the transforms that I have created using get_transforms by applying each them individually to the same image using apply_tfms. However it seems that it is just applying all of them anyway when I try this.
Here are my transforms:

get_transforms(flip_vert=False, max_warp=0.0, max_rotate=360, max_lighting=0.0, max_zoom=1.15)

[RandTransform(tfm=TfmCrop (crop_pad), kwargs={'row_pct': (0, 1), 'col_pct': (0, 1), 'padding_mode': 'reflection'}, p=1.0, resolved={'row_pct': 0.15663206811390784, 'col_pct': 0.5780825513563352, 'padding_mode': 'reflection'}, do_run=True, is_random=True, use_on_y=True),
 RandTransform(tfm=TfmPixel (flip_lr), kwargs={}, p=0.5, resolved={}, do_run=True, is_random=True, use_on_y=True),
 RandTransform(tfm=TfmAffine (rotate), kwargs={'degrees': (-360, 360)}, p=0.75, resolved={'degrees': 280.6319932696381}, do_run=True, is_random=True, use_on_y=True),
 RandTransform(tfm=TfmAffine (zoom), kwargs={'scale': (1.0, 1.15), 'row_pct': (0, 1), 'col_pct': (0, 1)}, p=0.75, resolved={'scale': 1.0291329472876456, 'row_pct': 0.8337403533326125, 'col_pct': 0.8612715133552968}, do_run=False, is_random=True, use_on_y=True)]

Here is my code for attempted to apply them individually and plot:

fig, axes = plt.subplots(ncols=5, figsize=(15, 3))

for j in range(5):
    ax = axes[j]
    img = data.train_ds[6][0].apply_tfms(tfms[0][1])
    img.show(ax=ax)

I expected this to just do a horizontal flip.
Here is the output from that code:

Ah. I just now figured out that every time I get the image it has a transform applied to it from the transforms I passed to the data bunch.

data.train_ds[6][0] # this is different every time

This is the source of my confusion.

For anyone else who has this problem: a quick fix is to remove tfms argument from the transform part of your datablock and then use my plotting code above. Remember to put tfms back it comes to training though.

Randomness is the key point of data augmentation: if you don’t randomize, you’re pre-processing :wink:

Take a look at this If you want to see and tune your transformations:

1 Like