Proposal to add "np.rot90" to data aug

Open Issue:

Basically would like a data aug transform thats like np.rot90(…) A discrete rotation only transform resulting in 0, 90, 180, 270.

I don’t want to use dihedral for some images because the reflected version is not valid. This applies to text in quite a few languages. And even if it is harmless, it may still be wasteful since you are diluting the training set with unrealistic samples. You may have to use TTA to take advantage but that drag down the inference side.

Please give me any feedback to if this will be general useful enough to be added the library. And also if the name “rot90_affine” is appropriate.

Code sample how to add this yourself is at

1 Like

Here’s for shear, not sure if this is widely desired.

def _shear(degrees:uniform):
    "Shear image by `degrees`."
    shear = degrees * math.pi / 180
    return [[1., -sin(shear), 0.],
            [0., cos(shear), 0.],
            [0., 0., 1.]]

shear = TfmAffine(_shear)

tfms = [shear(degrees=(-20., 20.))]
[get_sample_image().apply_tfms(tfms, size=224, padding_mode='zeros').show(ax=ax) 
 for i, ax in enumerate(plt.subplots(rows, cols, figsize = (width, height))[1].flatten())


Oh shear isn’t in our affine transforms? Then that’s because I forgot, I had implemented it.
You can definitely put it in a PR!

Sorry, not clear what you said. Did you say you have already implemented? I could have missed this from reading the docs.

Note: depending on your image, a gaussian blur + shear can be a pretty good approx with out of focus motion blurring.

Yes I had, but apparently I forgot to package it because it’s not in fastai.