#on loading model with, Path having export.pkl file.
learn = load_learner(Path)
#on executing pet_classification.py and saving service
service = NormAbnormClassification.pack(export=learn)
saved_path = service.save()
I am getting following error on trying to predict result for an image.png file. File is of dimension 256x256 and model was also trained on same dimension file.
RuntimeError Traceback (most recent call last)
in
1 service = load(saved_path)
2
----> 3 print(service.predict(data.get(0)))
~/Richesh/AfterOctober2018/Notebooks/RnDNotebooksAndPythonScripts/normAbnormClassifier.py in predict(self, image)
11 def predict(self, image):
12 #result = self.artifacts.pet_classifer.predict(image)
---> 13 result = self.artifacts.export.predict(image)
14 return str(result)
~/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/basic_train.py in predict(self, item, return_x, batch_first, with_dropout, **kwargs)
369 "Return predicted class, label and probabilities for item
."
370 batch = self.data.one_item(item)
--> 371 res = self.pred_batch(batch=batch, with_dropout=with_dropout)
372 raw_pred,x = grab_idx(res,0,batch_first=batch_first),batch[0]
373 norm = getattr(self.data,'norm',False)
~/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/basic_train.py in pred_batch(self, ds_type, batch, reconstruct, with_dropout, activ)
348 activ = ifnone(activ, _loss_func2activ(self.loss_func))
349 with torch.no_grad():
--> 350 if not with_dropout: preds = loss_batch(self.model.eval(), xb, yb, cb_handler=cb_handler)
351 else: preds = loss_batch(self.model.eval().apply(self.apply_dropout), xb, yb, cb_handler=cb_handler)
352 res = activ(preds[0])
~/anaconda3/envs/fastai/lib/python3.6/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
~/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
539 result = self._slow_forward(*input, **kwargs)
540 else:
--> 541 result = self.forward(*input, **kwargs)
542 for hook in self._forward_hooks.values():
543 hook_result = hook(self, input, result)
~/anaconda3/envs/fastai/lib/python3.6/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
~/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
539 result = self._slow_forward(*input, **kwargs)
540 else:
--> 541 result = self.forward(*input, **kwargs)
542 for hook in self._forward_hooks.values():
543 hook_result = hook(self, input, result)
~/anaconda3/envs/fastai/lib/python3.6/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
~/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
539 result = self._slow_forward(*input, **kwargs)
540 else:
--> 541 result = self.forward(*input, **kwargs)
542 for hook in self._forward_hooks.values():
543 hook_result = hook(self, input, result)
~/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/nn/modules/conv.py in forward(self, input)
343
344 def forward(self, input):
--> 345 return self.conv2d_forward(input, self.weight)
346
347 class Conv3d(_ConvNd):
~/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/nn/modules/conv.py in conv2d_forward(self, input, weight)
340 _pair(0), self.dilation, self.groups)
341 return F.conv2d(input, weight, self.bias, self.stride,
--> 342 self.padding, self.dilation, self.groups)
343
344 def forward(self, input):
RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.cuda.HalfTensor) should be the same