Search code examples
python-3.ximage-processingchainer

Inference code for prediction in multi-class image classification


I am trying to take a single input image and predict its label. Training data image was converted to array and labels to int and made into a single dataset using DatasetMixin before feeding into classifier. So I have converted the image into array.

When I tried with the given code..this is the error... Expect: in_types[0].shape[1] == in_types[1].shape[1] * 1 Actual: 240 != 3

img = cv2.imread('C:/Users/Dell/Desktop/TEST IMAGES/MONOCYTE.jpeg')
plt.imshow(img)
plt.show()

img=np.array((img), dtype = np.float32)
img=img/255.0

x = Variable(np.asarray([img]))
y = model(x)
prediction = y.data.argmax(axis=1)

Solution

  • The details of the model is necessary for the accurate answer...

    But I guess that the model requires an array whose shape is (batch, channel, width, height), but the shape of the array you fed to model seems to be (width, height, channel).

    This may be the reason of the error message.