Unfamiliar Error when Running learn.fit()

I currently using fastai v0.7 and I am running it on Google Colab. By the way I am implementing the techniques taught in lesson 2, I encountered the following error when running learn.fit(). Does anyone have any idea on the cause?

HBox(children=(IntProgress(value=0, description=‘Epoch’, max=2, >style=ProgressStyle(description_width='initial…
epoch trn_loss val_loss accuracy
AttributeError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
55 try:
—> 56 return getattr(obj, method)(*args, **kwds)
57

AttributeError: ‘list’ object has no attribute ‘round’

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last)
in ()
----> 1 learn.fit(0.01, 2)

/usr/local/lib/python3.6/dist-packages/fastai/learner.py in fit(self, lrs, n_cycle, wds, **kwargs)
285 self.sched = None
286 layer_opt = self.get_layer_opt(lrs, wds)
–> 287 return self.fit_gen(self.model, self.data, layer_opt, n_cycle, **kwargs)
288
289 def warm_up(self, lr, wds=None):

/usr/local/lib/python3.6/dist-packages/fastai/learner.py in fit_gen(self, model, data, layer_opt, n_cycle, cycle_len, cycle_mult, cycle_save_name, best_save_name, use_clr, use_clr_beta, metrics, callbacks, use_wd_sched, norm_wds, wds_sched_mult, use_swa, swa_start, swa_eval_freq, **kwargs)
232 metrics=metrics, callbacks=callbacks, reg_fn=self.reg_fn, clip=self.clip, fp16=self.fp16,
233 swa_model=self.swa_model if use_swa else None, swa_start=swa_start,
–> 234 swa_eval_freq=swa_eval_freq, **kwargs)
235
236 def get_layer_groups(self): return self.models.get_layer_groups()

/usr/local/lib/python3.6/dist-packages/fastai/model.py in fit(model, data, n_epochs, opt, crit, metrics, callbacks, stepper, swa_model, swa_start, swa_eval_freq, **kwargs)
158
159 if epoch == 0: print(layout.format(*names))
–> 160 print_stats(epoch, [debias_loss] + vals)
161 ep_vals = append_stats(ep_vals, epoch, [debias_loss] + vals)
162 if stop: break

/usr/local/lib/python3.6/dist-packages/fastai/model.py in print_stats(epoch, values, decimals)
171 def print_stats(epoch, values, decimals=6):
172 layout = “{!s:^10}” + " {!s:10}" * len(values)
–> 173 values = [epoch] + list(np.round(values, decimals))
174 print(layout.format(*values))
175

/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py in round_(a, decimals, out)
3380 around : equivalent function; see for details.
3381 “”"
-> 3382 return around(a, decimals=decimals, out=out)
3383
3384

/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py in around(a, decimals, out)
3005
3006 “”"
-> 3007 return _wrapfunc(a, ‘round’, decimals=decimals, out=out)
3008
3009

/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
64 # a downstream library like ‘pandas’.
65 except (AttributeError, TypeError):
—> 66 return _wrapit(obj, method, *args, **kwds)
67
68

/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py in _wrapit(obj, method, *args, **kwds)
44 except AttributeError:
45 wrap = None
—> 46 result = getattr(asarray(obj), method)(*args, **kwds)
47 if wrap:
48 if not isinstance(result, mu.ndarray):

AttributeError: ‘float’ object has no attribute ‘rint’

Belows are my codes:

%reload_ext autoreload
%autoreload 2
%matplotlib inline
from fastai.imports import *
from fastai.transforms import *
from fastai.conv_learner import *
from fastai.model import *
from fastai.dataset import *
from fastai.sgdr import *
from fastai.plots import *
import matplotlib.pyplot as plt

PATH = ‘/content/selected_gd_data/’
sz = 224
arch = resnet34
tfms = tfms_from_model(resnet34,
sz,
aug_tfms = transforms_side_on,
max_zoom = 1.1)
import PIL
data = ImageClassifierData.from_paths(PATH,
tfms = tfms,
trn_name = ‘imgtrain’,
val_name = ‘imgval’)
size_d = {k: PIL.Image.open(PATH+k).size for k in data.trn_ds.fnames}
row_sz, col_sz = list(zip(*size_d.values()))
row_sz = np.array(row_sz)
col_sz = np.array(col_sz)
plt.hist(row_sz)
plt.hist(col_sz)

def get_data(sz, bs):
tfms = tfms_from_model(arch, sz, aug_tfms = transforms_side_on, max_zoom = 1.1)
data = ImageClassifierData.from_paths(PATH,
tfms = tfms,
trn_name = ‘imgtrain’,
val_name = ‘imgval’,
bs = bs)
return data if sz>300 else data.resize(340, ‘tmp’)
data = get_data(sz, 64)

learn = ConvLearner.pretrained(arch, data, precompute = True)
lrf = learn.lr_find(1e-6,1e1)
learn.sched.plot_lr()
learn.sched.plot()
learn.fit(0.01, 2)

3 Likes

Hello Alex,
I’m running lesson 14 enhance and I’m facing the same issue, which I never had, I didn’t found the solution yet.
My best guess is that some of the packages that fast.ai 0.7.0 depends on, have been updated and now it breaks as most of the dependencies are set in the form of package_name>=x.x.x

1 Like

Hi guys,

I am facing the exact same issue. I am just trying lesson 2 techniques in other Kaggle datasets. Please, publish here the solution if you find out.

Thank you,
Daniel

1 Like

I just got a similar error while running some code within Kaggle that worked yesterday. Based on all that I think Cesare is right in that some package was updated that doesn’t work with fastai 0.7.0. If I figure anything out I’ll post here as well.
Chris

I face the same issue trying to learn resnet34 on my own dataset.

I just hit this problem today.

I looking at the numpy release notes, version 1.16.0 was released just over a week ago.

Downgrading my install to numpy=1.15.1 resolved this issue with the learn.fit methods in fast.ai

2 Likes

This setup did it for me

!pip install Pillow==4.1.1
!pip install fastai==0.7.0 
!pip install torchtext==0.2.3
!pip install blosc

I’ve created a jupyter notebook locally and everything worked (fastai 0.7 I guess), afterwards uploaded notebook on kaggle and I got the same error. I tried to change numpy version but then I get a different error when importing fastai. I’m pretty sure this error is caused due to the wrong version of numpy, but can’t find a solution. Previously I tried 1.15.1 and 1.15.3 with the same outcome.
The stack trace is quite long so don’t want to upload it all, but before the part on the screenshot, statsmodel package is imported which imports numpy. The problem might be that kaggle has both conda and pip, whereas I checked that Collab only used pip. Also I checked in numpy repo that parameter _typestr was deleted in numpy 1.16.0

Would be great if I got the solution before 30th January bc that day the competition ends.

Facing the same issue!
Please reply if somebody has solved this, thanks in advance.

1 Like

I tried following the suggestions from Cesare:

!pip install Pillow==4.1.1
!pip install fastai==0.7.0
!pip install torchtext==0.2.3
!pip install blosc
But I am still getting the exact same error when I run learn.fit()
AttributeError: ‘list’ object has no attribute 'round
AttributeError: ‘float’ object has no attribute ‘rint’

Same here, for some notebooks it works, on some others trigger that error.
My choice is to go for the version 3 of the course :wink:

Installing numpy 1.15.1 solved the problem:

!pip intall numpy==1.15.1

Credit to: Error in learn.fit() lesson 1

2 Likes

I’m still facing the same issue. Any final solution that works?

Please may i know what was the pytorch version you used?

I got stuck on this too with the fastai/courses/dl2/carvana.ipynb notebook.

Following on what the other commenters have mentioned, I went into my fastai/environment.yml file and changed the two entries for numpy from just - numpy to - numpy=1.15.1. After that I ran the command conda env update -f environment.yml and that fixed this error.

2 Likes

This worked for me (I was running on cpu, and haven’t tried the gpu one):
conda env remove -y -n fastai-cpu (conda env remove -y -n fastai for the gpu version)
Then open fastai/environment-cpu.yml (fastai/environment.yml for the gpu version) and change the - numpy under dependencies to - numpy<=1.15.1 then save and redo the environment setup which is cd fastai then
conda env create -f environment-cpu.yml (for gpu version conda env create -f environment.yml) and then conda activate fastai-cpu. Now run jupyter notebook and things should work normal.

2 Likes

Thank you too mucn. I changed numpy=1.16.2 to numpy=1.15.1. So I solved the error “AttributeError: ‘float’ object has no attribute ‘rint’ ”

1 Like

hi all,
Did you finish running the file dl2/imdb.ipynb. can you share me the model output such as lm_last_ft, lm1, lm1_enc, clas_0, clas_1, clas_2 …
It took me a lot of days to run all of the fit() commands, please help me if you have these model files, thanks.

Hi blazjd,

Please did you find solution to this problem? I’m facing the same challenge now using colab. Non of the suggested solution here worked for me.

Regards

How I solved it: the rounding is happening in the model.py file at two places to make the printed output more readable. It seemed a luxury to me at the cost of the fit function failing. I removed the round off happening at the two places and it worked fine. Here are the two edits:

line 194, make it: values = [epoch] + list(values)

line 184, make it: ep_vals[epoch]=list(values)

Downgrading numpy as a solution doesn’t solve the problem entirely since then np.stack starts creating an issue. More so because one wouldn’t be sure where else an older numpy version shall throw errors.
Altering the source code was hence the only option.

4 Likes