Possible bug in fastai library file transform.py

Hi whille trying to run the follwing code I am getting runtime errors
from fastai.transforms import *
train_len = len(list(open(label_csv)))-1

transforms_pt = [RandomRotateZoom(9, 0.18, 0.1), RandomLighting(0.05, 0.1), RandomDihedral()]
tfms=tfms_from_model(f_model, sz, aug_tfms=transforms_pt, pad=sz//12)

val_idx = get_cv_idxs(train_len)
data = ImageClassifierData.from_csv(path, 'train-jpg', f'{path}train_v2.csv', bs, tfms, suffix='.jpg', val_idxs=val_idx, test_name='test-jpg')
lr=0.2
lrs=[lr/9, lr/3, lr]
learn = ConvLearner.pretrained(f_model, data, metrics=metrics)
        
learn.fit(lr, 3, cycle_len=1, cycle_mult=2)

~/fastai/courses/dl1/fastai/transforms.py in zoom_cv(x, z)
17 def zoom_cv(x,z):
18 if z==0: return x
—> 19 r,c,*_ = im.shape
20 M = cv2.getRotationMatrix2D((c/2,r/2),0,z+1.)
21 return cv2.warpAffine(x,M,(c,r))

NameError: name ‘im’ is not defined

In the definition of zoom_cv, does replacing all instances of x with im, fix things?

So, like:

def zoom_cv(im,z):
    if z==0: return im
    r,c,*_ = im.shape
    M = cv2.getRotationMatrix2D((c/2,r/2),0,z+1.)
    return cv2.warpAffine(im,M,(c,r))

Looks like some other functions might be affected too (e.g. stretch_cv).

1 Like

Also dihedral function is complaining about unresolved reference to self (the function below stretch_cv).
We should be able to get rid of self for that one.

That sounds right.

May be a pull request or two are in order?

I think there are versions of nearly all transforms with ‘XY’ suffixes. These are the ones you should use. @yinterian is working on removing the redundant old ones and getting rid of the suffixes.

2 Likes