Cnn_learner doesn't give a object with a fit_one_cycle method

So I am going through the lesson Part 1 at https://www.youtube.com/watch?v=XfoYk_Z5AkI

And going through the pet image classification exercise he has and using the latest version of fastai 1.0.51 I couldn’t find a fit_one_cycle method in the Learner class returned from cnn_learner

Here is his code

learn = cnn_learner(data, models.resnet34, metrics=error_rate)
learn.fit_one_cycle(4)

==output ==
Total time: 01:46

|epoch|train_loss|valid_loss|error_rate|
|1| 1.409939| 0.357608| 0.102165|
|2| 0.539408| 0.242496| 0.073072|
|3| 0.340212| 0.221338| 0.066306|
|4| 0.261859| 0.216619| 0.071042|

Whereas in my code I had to do

learn = cnn_learner(data, models.resnet34)
learn.fit(4)
==output==
epoch train_loss valid_loss time
0 0.846043 0.363760 01:14
1 0.729383 0.299239 01:16
2 0.663945 0.264982 01:26
3 0.663611 0.259634 01:27

which the results are worse. I think this might be because I used a batch size of 8 when using the ImageDataBunch method instead of 64 like he did(which Idk how that’d affect it, I’d love an explanation), but can’t confirm that it isn’t because of fit vs fit_one_cycle

I did below

data = ImageDataBunch.from_name_re(pets_pth, fnames, pat, ds_tfms=get_transforms(), size=224, bs=8)

due to GPU constraints.

Anyhow, which could it be? Also what happened to fit_one_cycle?

It’s pretty usual if your reproduction’s result are a little bit different. Even if you rerun the same code, you might see the results are different as well. So don’t worry.
fit_one_cycle is a learning method inspired by one cycle policy, a special way to find good learning rate. you might be willing to read this: Finding Good Learning Rate and The One Cycle Policy.

1 Like

Ah okay, thanks for the assurance
Also, I’ll check it out, but in the meantime, do you know if
fit
now does what
fit_one_cycle
used to do? Because as pointed out, there is no fit_one_cycle method anymore in the Learner returned from cnn_learner

These two lines of code work fine to me (my fastai library is also the latest version).
Could you please paste the error messages?

Funnily enough, if I run it it works fine but I get the error from Pycharm saying, “unresolved reference for fit_one_cycle for class Learner”. And if I go to the source code for the Learner class, there is indeed no fit_one_cycle method, however if I do a grep, I can see that it actually does give the Learner class a fit_one_cycle method by doing

grep -R “fit_one_cycle”
train.py:def fit_one_cycle(learn:Learner, cyc_len:int, max_lr:Union[Floats,slice]=defaults.lr,
train.py:Learner.fit_one_cycle = fit_one_cycle

Essentially this is binding the method at a different time, very similar to doing something like Path.ls = lambda x: listdir(x)

I think this may be caused by a conflict with other third-party libraries.
Try to write code in jupyter notebook and only import fastai next time.

Ah, so everythings fine, its just an annoying warning in the ide, but really alls well~ thanks for walking through with this, i should have searched for the dynamic binding of the method first

1 Like