Hi all, can someone help with this. I am getting the following error:
NameError: name ‘calc_loss’ is not defined
Full error:
NameError Traceback (most recent call last)
in
5 learn = cnn_learner(data, models.squeezenet1_0)
6 learn.load(‘stage-2’)
----> 7 classify = ClassificationInterpretation.from_learner(learn, tta=True)
8 correct = (classify.pred_class==classify.y_true).sum()
9 print (f’Validation set - correctly classified: {correct} incorrectly: {len(classify.y_true)-correct}\n’)c:\pillview\nih\fastai\fastai\vision\learner.py in _cl_int_from_learner(cls, learn, ds_type, tta)
113 def _cl_int_from_learner(cls, learn:Learner, ds_type:DatasetType=DatasetType.Valid, tta=False):
114 “Create an instance ofClassificationInterpretation
.tta
indicates if we want to use Test Time Augmentation.”
–> 115 preds = learn.TTA(ds_type=ds_type, with_loss=True) if tta else learn.get_preds(ds_type=ds_type, with_loss=True)
116 return cls(learn, *preds, ds_type=ds_type)
117c:\pillview\nih\fastai\fastai\vision\tta.py in _TTA(learn, beta, scale, ds_type, with_loss)
39 final_preds = predsbeta + avg_preds(1-beta)
40 if with_loss:
—> 41 return final_preds, y, calc_loss(final_preds, y, learn.loss_func)
42 return final_preds, y
43NameError: name ‘calc_loss’ is not defined
Within tta.py here is the code
def _TTA(learn:Learner, beta:float=0.4, scale:float=1.35, ds_type:DatasetType=DatasetType.Valid, with_loss:bool=False) -> Tensors:
“Applies TTA to predict onds_type
dataset.”
preds,y = learn.get_preds(ds_type)
all_preds = list(learn.tta_only(scale=scale, ds_type=ds_type))
avg_preds = torch.stack(all_preds).mean(0)
if beta is None: return preds,avg_preds,y
else:
final_preds = predsbeta + avg_preds(1-beta)
if with_loss:
return final_preds, y, calc_loss(final_preds, y, learn.loss_func)
return final_preds, yLearner.TTA = _TTA
Any ideas on what may be causing this?
thanks