ERROR: Invalid Index to Scalar (same as in yr 2018)

Hi, after a fresh install, following the Installation manual, i keep hitting this error. When it comes to missing libraries that is still in the scope of knowledge for a beginner like me, however this is seriously puzzling me to no end. Please help

The code block that triggers the error:

data = ImageClassifierData.from_paths(PATH, tfms=tfms_from_model(arch, sz))
learn = ConvLearner.pretrained(arch, data, precompute=True), 2)

The error:

IndexError Traceback (most recent call last)
2 data = ImageClassifierData.from_paths(PATH, tfms=tfms_from_model(arch, sz))
3 learn = ConvLearner.pretrained(arch, data, precompute=True)
----> 4, 2)

~/Coding/Fast.Ai/fastai/courses/dl1/fastai/ in fit(self, lrs, n_cycle, wds, **kwargs)
300 self.sched = None
301 layer_opt = self.get_layer_opt(lrs, wds)
–> 302 return self.fit_gen(self.model,, layer_opt, n_cycle, **kwargs)
304 def warm_up(self, lr, wds=None):

~/Coding/Fast.Ai/fastai/courses/dl1/fastai/ 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)
247 metrics=metrics, callbacks=callbacks, reg_fn=self.reg_fn, clip=self.clip, fp16=self.fp16,
248 swa_model=self.swa_model if use_swa else None, swa_start=swa_start,
–> 249 swa_eval_freq=swa_eval_freq, **kwargs)
251 def get_layer_groups(self): return self.models.get_layer_groups()

~/Coding/Fast.Ai/fastai/courses/dl1/fastai/ in fit(model, data, n_epochs, opt, crit, metrics, callbacks, stepper, swa_model, swa_start, swa_eval_freq, visualize, **kwargs)
162 if not all_val:
–> 163 vals = validate(model_stepper, cur_data.val_dl, metrics, epoch, seq_first=seq_first, validate_skip = validate_skip)
164 stop=False
165 for cb in callbacks: stop = stop or cb.on_epoch_end(vals)

~/Coding/Fast.Ai/fastai/courses/dl1/fastai/ in validate(stepper, dl, metrics, epoch, seq_first, validate_skip)
241 loss.append(to_np(l))
242 res.append([to_np(f(datafy(preds), datafy(y))) for f in metrics])
–> 243 return [np.average(loss, 0, weights=batch_cnts)[0]] + list(np.average(np.stack(res), 0, weights=batch_cnts))
245 def get_prediction(x):

IndexError: invalid index to scalar variable.

So far, tried installing torch 1.4.0 and torchvision 0.5.0 … error is still present…

UPDATE: I removed the [0] in the code on line 243 in and the code seems to run now, since I’m a noob not sure, but was thinking it may have been refering to an iteration over single values already, hence the [0] would toss an error …again…not sure. Now line 243 looks like:

return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))

Is it fixed now…but why?

1 Like