0

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)
TulakHord
  • 422
  • 7
  • 15

1 Answers1

1

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.

Yuki Hashimoto
  • 1,013
  • 7
  • 19
  • The shape of the array is 9957, 3,60,80 where 9957 is the total no. of images. Can we consider 9957 as batchsize? If not how do we introduce batchsize into the array? – TulakHord Jan 04 '19 at 10:30
  • No, it cannot be the case (if you run your script given in this question), because it only feeds one image. It is true that IF the size of the array is (9957, 3, 60, 80), "9957" can be interpreted as the batch size, but usually the batch size is less than it (128 is usually used). – Yuki Hashimoto Jan 05 '19 at 04:05
  • I'm not able to change the shape to batchsize, channel, height, width. How can I remove 9957 and put batchsize in it's place? I have tried using np.newaxis but that gets me input shape = 1, 9957, 3, 60, 80. – TulakHord Jan 05 '19 at 13:58