TypeError: unsupported operand type(s) for +: 'float' and 'list'

(Lucas Goulart Vazquez) #1

I’m having this problem when trying to run any kind of model:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-c4a511932645> in <module>()
----> 1 learner.fit(1e-3, 15)

/home/quazar/programming/machine_learning/libs/fastai/fastai/learner.py in fit(self, lrs, n_cycle, wds, **kwargs)
    250         self.sched = None
    251         layer_opt = self.get_layer_opt(lrs, wds)
--> 252         return self.fit_gen(self.model, self.data, layer_opt, n_cycle, **kwargs)
    253 
    254     def warm_up(self, lr, wds=None):

/home/quazar/programming/machine_learning/libs/fastai/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, all_val, **kwargs)
    197         n_epoch = sum_geom(cycle_len if cycle_len else 1, cycle_mult, n_cycle)
    198         return fit(model, data, n_epoch, layer_opt.opt, self.crit,
--> 199             metrics=metrics, callbacks=callbacks, reg_fn=self.reg_fn, clip=self.clip, all_val=all_val, **kwargs)
    200 
    201     def get_layer_groups(self): return self.models.get_layer_groups()

/home/quazar/programming/machine_learning/libs/fastai/fastai/model.py in fit(model, data, epochs, opt, crit, metrics, callbacks, stepper, all_val, **kwargs)
    133 
    134         if not all_val:
--> 135             vals = validate(stepper, data.val_dl, metrics)
    136             if epoch == 0: print(layout.format(*names))
    137             print_stats(epoch, [debias_loss] + vals)

/home/quazar/programming/machine_learning/libs/fastai/fastai/model.py in validate(stepper, dl, metrics)
    181         loss.append(to_np(l))
    182         res.append([f(preds.data,y) for f in metrics])
--> 183     return np.average(loss, 0, weights=batch_cnts).tolist() + np.average(np.stack(res), 0, weights=batch_cnts).tolist()
    184 
    185 def get_prediction(x):

TypeError: unsupported operand type(s) for +: 'float' and 'list'

I used %debug and saw that np.average(loss, 0, weights=batch_cnts).tolist() is not returning a list

ipdb> np.average(loss, 0, weights=batch_cnts).tolist()
0.6887356958389282
ipdb> np.average(np.stack(res), 0, weights=batch_cnts).tolist()
[0.8080000014305114]

I’m using numpy 1.14.2

0 Likes

(Jeremy Howard (Admin)) #2

Looks like you need to git pull.

1 Like

(Lucas Goulart Vazquez) #3

Thanks! I was doing git pull but the remote was set to a outdated fork of mine, sorry :sweat_smile::sweat_smile:

0 Likes

(jacob lawrence ) #4

I have similar issue of "Unsupported Operand type(s) for *: ‘None type’ and ‘int’ in Conv_learner.py file.

I have installed fastai=0.7.0 which was installed using pip and I am running the code in a separate virtual enviornment.
To this situation how could i git pull to fix the issue

0 Likes