I have image classification model on trained on dataiku which is efficinet B4.
Now I want to use it pickle file to make prediction on image but I am unable to make predictions.
What is the image format that pred = pickle_model.get_predictor() , pred.predict() wants :
Preprocessing function
import cv2
from PIL import Image
import numpy as np
import pickle
def preprocess_image(image_path, target_size=(380, 380)):
img = cv2.imread(image_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.resize(img, target_size)
img_array = np.array(img)
img_array = img_array / 255.0
img_batch = np.expand_dims(img_array, axis=0)
return img_batch
code for prediction
image1 = preprocess_image(test_image)
Model loading
def load_model(pickle_path):
with open(pickle_path, 'rb') as f:
model = pickle.load(f)
return model
model = load_model('model.pkl')
pred = model.get_predictor()
logits = pred.predict(image1)
ERROR:dataiku.doctor.deephub.deephub_torch_datasets:couldn’t get item at index 0
Traceback (most recent call last):
File “/home/utshav/dataiku-dss-11.3.2/python/dataiku/doctor/deephub/deephub_torch_datasets.py”, line 35, in getitem
return self._getitem(idx)
File “/home/utshav/dataiku-dss-11.3.2/python/dataiku/doctor/deephub/deephub_torch_datasets.py”, line 131, in _getitem
row = self.get_row(idx)
File “/home/utshav/dataiku-dss-11.3.2/python/dataiku/doctor/deephub/deephub_torch_datasets.py”, line 140, in get_row
return self.df.iloc[idx]
AttributeError: ‘numpy.ndarray’ object has no attribute ‘iloc’
I am expecting a way to make prediction using pickle file I don’t where I am wrong I have tried so many ways but getting nowhere