Learner object has no attribute recorder!

Hi All,

Has anyone noticed any issue with learn.recorder?
My fastai version is 1.0.51 (using the one on kaggle).

And suddenly I’m getting attribute error : ‘Learner’ object has no attribute ‘recorder’

  1. while trying learn.recorder.plot()
  2. while using self.learn.recorder.add_metric_names([‘AUROC’])
  3. while learn.fit_one_cycle

— but, all these are likely related to a single issue only!

Has anyone faced something similar? Or is there certain changes that was made in the code base and hence this doesn’t work?

1 Like

Have you trained or done an lr_find() yet? I notice it will not show until you begin training to some degree (be it learning rate finding or actual training)

Hey! Yeah, it’s working. But, seems whenever I try to invoke learn.recorder it fails!

Weirdly, all the code I’m using was working fine till today morning, suddenly I’m getting these errors.

Even in my case I had exported a learner after find_lr and training and then again imported it from a path and ran the same code of learn.recorder.plot_losses still it gives an error of ‘no attribute named recorder’

After loading a learner exported from another script, I could not find attribute ‘recorder’ within that learner. Seems like the export function won’t export the the recorder?

1 Like

I just faced the same issue, I believe @linzzz your guess is correct.

1 Like

Anyone found solution for this yet? Encountered it a couple times today intermittently.

*After coming over here to type this post, I returned to my notebook, tried running my code again, and behold it worked this time! Very puzzling…

In case you appended ShowGraph(Learner) to callbacks, this is what is causing the problem (in my case).

Hi,

I don’t know if this is the right place to post this but I am getting the following error:

AttributeError: 'Learner' object has no attribute 'lr_find'

What could I be doing wrong? I see everyone using it with no issues. I am using Fastai 2

Hi sarvagya1991,

This is the first post I’ve seen mentioning this issue, so glad to hear I’m not alone.

It appears to lr_find functionality is available via the LRFinder callback, like this: learn.fit(20, cbs=LRFinder(num_it=100)).

There’s also a function fastai.callback.schedule called lr_find that provides the functionality i’m used to from earlier versions of fastai: lr_find(learner)

The documentation does indicate Learner still has a lr_find method, so I’m guessing it’s a bug that no one has found yet, or lr_find is somehow patched in Learner in a configuration different to mine

1 Like

The thing that confuses me is that other developers have used it in that way. So I don’t know how they didn’t get the error: Have a look at this.

Your solution did help me get rid of the error but would you be play with answering a follow-up error that I got? It’s probably related to DataLoader and mse loss function.

@sarvagya1991 we need more info than what you provided. learn.lr_find() exists. I’m not sure your imports but that import should come from fastai.callback.all

These were my imports:

import fastai
from fastai.data.core import DataLoaders
from fastai.basics import *
from fastai.vision.core import *
from fastai.vision.data import *
from fastai.vision.augment import *
from fastai.vision import models
from fastai.vision.learner import Learner
from fastai.vision import models

Now, it’s this:

import fastai
from fastai.basics import *
from fastai.vision.core import *
from fastai.vision.data import *
from fastai.vision.augment import *
from fastai.vision import models
from fastai.vision import models
from fastai.callback.schedule import lr_find

I am also facing one more error. My custom dataloader is defined as follows:

class data_gen(torch.utils.data.Dataset):
    def __init__(self, files):
        
        self.files = files
        
        
    def __getitem__(self, i):
        
        file1 = self.files[i]
        
        tmp = np.load(file1, allow_pickle=True)
        
        img = tmp['x']
        img = np.reshape(img,(1,img.shape[0], img.shape[1]))
        img = torch.from_numpy(img).float()
        
        return img

    def __len__(self): 
        
        return len(self.files)

When I define a DataLoader:

train_ds = data_gen(X_train)
test_ds = data_gen(X_test)
dls = DataLoaders.from_dsets(train_ds, test_ds, bs=batch_size, device='cuda:0')
learn = Learner(dls=dls,model=m,loss_func=F.mse_loss)
lr_find(learn)

I get the following error:

RuntimeError: Expected 4-dimensional input for 4-dimensional weight [64, 1, 7, 7], but got 3-dimensional input of size [1, 512, 512] instead

So, in the data_gen definition, I changed the shape of the image to (1, 1, 512, 512), which got rid of the error but I got another error:

TypeError: mse_loss() takes from 2 to 5 positional arguments but 16 were given

What do you suggest?

That’s part of the issue. Importing in fastai v2 looks like:

from fastai.vision.all import *

Each have a .all, so most likely you’re not getting the fix to actually bring in Learn.lr_find (I understand you’re wanting to import absolutes, but fastai wasn’t built to work like that really)

Otherwise I have no idea, that’s a whole seperate issue unrelated to this thread. You should open a new topic for it.

This is interesting. I don’t know why I didn’t find this in the documentation. Moreover, I didn’t it in any of the blogs that use FastAI. Thank you.

I’ll do that. Thanks.

You should look at blogs that use the newest version of the library. All of mine do :wink:

1 Like

Yeah. Already signed up for your tutorial session.

I got that error, too - AttributeError: 'Learner' object has no attribute 'lr_find'. I’m not sure why it happened, but restarting the runtime in Colab and running the code again fixed it for me.

Can anyone please help me? while using learn.fit_sgdr , it gives an error of
AttributeError: ‘Learner’ object has no attribute ‘fit_sgdr’
I have used this package for installation
!pip install -U object-detection-fastai

from object_detection_fastai.helper.wsi_loader import *

from object_detection_fastai.loss.RetinaNetFocalLoss import RetinaNetFocalLoss

from object_detection_fastai.models.RetinaNet import RetinaNet

from object_detection_fastai.callbacks.callbacks import BBMetrics, PascalVOCMetricByDistance, PascalVOCMetric, PascalVOCMetricByDistance
if I try using fastai --upgrade it asks for restarting the runtime which is obvious, but I’m not able to use both in same notebook.
i need the object detection package for the earlier part of code for loading the MIDOG 2021 data , I cant use any other option for that .
but I need to use sgdr training too which I am not able to perform in jupyter notebook.
All suggestions are welcome .

@muellerzr could you please help me with the above problem