After training and exporting the model, when I am loading the export.pkl file and trying get a prediction for an image I am getting this error.
AttributeError Traceback (most recent call last)
in ()
1 img = open_image(r"D:\image_5.jpg")
----> 2 learn.predict(img)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\fastai\basic_train.py in predict(self, item, **kwargs)
363 “Return predicted class, label and probabilities for item
.”
364 batch = self.data.one_item(item)
–> 365 res = self.pred_batch(batch=batch)
366 pred,x = grab_idx(res,0),batch[0]
367 norm = getattr(self.data,‘norm’,False)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\fastai\basic_train.py in pred_batch(self, ds_type, batch, reconstruct)
343 cb_handler = CallbackHandler(self.callbacks)
344 xb,yb = cb_handler.on_batch_begin(xb,yb, train=False)
–> 345 preds = loss_batch(self.model.eval(), xb, yb, cb_handler=cb_handler)
346 res = _loss_func2activ(self.loss_func)(preds[0])
347 if not reconstruct: return res
~\AppData\Local\Continuum\anaconda3\lib\site-packages\fastai\basic_train.py in loss_batch(model, xb, yb, loss_func, opt, cb_handler)
24 if not is_listy(xb): xb = [xb]
25 if not is_listy(yb): yb = [yb]
—> 26 out = model(*xb)
27 out = cb_handler.on_loss_begin(out)
28
~\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\nn\modules\module.py in call(self, *input, **kwargs)
487 result = self._slow_forward(*input, **kwargs)
488 else:
–> 489 result = self.forward(*input, **kwargs)
490 for hook in self._forward_hooks.values():
491 hook_result = hook(self, input, result)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\nn\modules\container.py in forward(self, input)
90 def forward(self, input):
91 for module in self._modules.values():
—> 92 input = module(input)
93 return input
94
~\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\nn\modules\module.py in call(self, *input, **kwargs)
487 result = self._slow_forward(*input, **kwargs)
488 else:
–> 489 result = self.forward(*input, **kwargs)
490 for hook in self._forward_hooks.values():
491 hook_result = hook(self, input, result)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\nn\modules\container.py in forward(self, input)
90 def forward(self, input):
91 for module in self._modules.values():
—> 92 input = module(input)
93 return input
94
~\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\nn\modules\module.py in call(self, *input, **kwargs)
487 result = self._slow_forward(*input, **kwargs)
488 else:
–> 489 result = self.forward(*input, **kwargs)
490 for hook in self._forward_hooks.values():
491 hook_result = hook(self, input, result)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\nn\modules\activation.py in forward(self, input)
48 @weak_script_method
49 def forward(self, input):
—> 50 return F.threshold(input, self.threshold, self.value, self.inplace)
51
52 def extra_repr(self):
~\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\nn\modules\module.py in getattr(self, name)
533 return modules[name]
534 raise AttributeError("’{}’ object has no attribute ‘{}’".format(
–> 535 type(self).name, name))
536
537 def setattr(self, name, value):
AttributeError: ‘ReLU’ object has no attribute ‘threshold’
– Also, I am getting this warning when I am loading the export.pkl file.
AppData\Local\Continuum\anaconda3\lib\site-packages\torch\serialization.py:434: SourceChangeWarning: source code of class ‘torch.nn.modules.loss.CrossEntropyLoss’ has changed. you can retrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True
and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
– Does anyone know how to resolve this issue?