'float' object has no attribute 'rint' while calling fit()

(Emil) #1

When I try to run

fit(net, md, n_epochs=1, crit=loss, opt=opt, metrics=metrics)

it gives me the error

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/anaconda3/envs/fastai-cpu/lib/python3.6/site-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)
<ipython-input-19-ea399f592f0a> in <module>
----> 1 fit(net, md, n_epochs=1, crit=loss, opt=opt, metrics=metrics)

~/study/fastai/courses/ml1/fastai/model.py in fit(model, data, n_epochs, opt, crit, metrics, callbacks, stepper, swa_model, swa_start, swa_eval_freq, visualize, **kwargs)
    173             else:
    174                 print(layout.format(*names))
--> 175                 print_stats(epoch, [debias_loss] + vals, visualize)
    176             prev_val = [debias_loss] + vals
    177             ep_vals = append_stats(ep_vals, epoch, [debias_loss] + vals)

~/study/fastai/courses/ml1/fastai/model.py in print_stats(epoch, values, visualize, prev_val, decimals)
    188 def print_stats(epoch, values, visualize, prev_val=[], decimals=6):
    189     layout = "{!s:^10}" + " {!s:10}" * len(values)
--> 190     values = [epoch] + list(np.round(values, decimals))
    191     sym = ""
    192     if visualize:

~/anaconda3/envs/fastai-cpu/lib/python3.6/site-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 

~/anaconda3/envs/fastai-cpu/lib/python3.6/site-packages/numpy/core/fromnumeric.py in around(a, decimals, out)
   3005 
   3006     """
-> 3007     return _wrapfunc(a, 'round', decimals=decimals, out=out)
   3008 
   3009 

~/anaconda3/envs/fastai-cpu/lib/python3.6/site-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 

~/anaconda3/envs/fastai-cpu/lib/python3.6/site-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'
0 Likes

(Emil) #2

The problem lies in the file
fastai/courses/ml1/fastai/model.py line number 190 in function print_stats

Just change it to

values = np.array(values, dtype=np.float)

This is problem is present in more than one place. Just replace the problem causing variable with it numpy’s float format .

0 Likes