Unfamiliar Error when Running learn.fit()

(AlexLau) #1

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)

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)
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)
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)
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))

/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)

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

/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)

/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,
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)

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.fit(0.01, 2)

Error in learn.fit() lesson 1
(Cesare) #2

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

(Daniel) #3

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,

(Chris Uberti) #4

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.

(Dmitriy Startsev) #5

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

(Gordon McGregor) #6

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

(Cesare) #7

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.

(Himanshu Jhamb) #9

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

(David P Eisenberg) #10

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’

(Cesare) #11

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:

(Pankaj Joshi) #12

Installing numpy 1.15.1 solved the problem:

!pip intall numpy==1.15.1

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