1

I created a code that classifies brain MRI images into 4 classes of cancer varieties. I trained the model successfully and when I tried to create a conversion algo to convert testing images to evaluate them, I ran into a reshaping error as the following:

prediction = []
original = []
image = []
count = 0

for item in range(len(test)):

  img= PIL.Image.open(test['Image'].tolist()[item])
  img = img.resize((256,256))
  image.append(img)
  print(image[item])
  img = np.asarray(img, dtype= np.float32)
  img = img / 255
  img = img.reshape(-1,256,256,3) #ERROR HERE
  predict = model.predict(img)
  print(predict)
  predict = np.argmax(predict)
  prediction.append(labels[predict])
  original.append(test['Label'].tolist()[item])

the error:

`<ipython-input-48-747eee3f839e> in <module>
     14   img = np.asarray(img, dtype= np.float32)
     15   img = img / 255
---> 16   img = img.reshape(-1,256,256,3)
     17   predict = model.predict(img)
     18   print(predict)

ValueError: cannot reshape array of size 65536 into shape (256,256,3)`

All help is appreciated.

Khaled
  • 11
  • 1

0 Answers0