How to do prediction on numpy Image array

Hello there,

i am using fast.ai 2.4.1.

I have trained my segmentation model using fast.ai and I have done learn.save() to save model.
I am able to see results using learn.show_results() and learn.predict()

But, now, I am trying to integrate this model with other code , which is giving me numpy array image to do prediction on. How can I do that?

I dont want to save the file and run prediction on it.

what is the way forward?

Answering my own question:

if we do plt.imread() and pass into predict, it will not work. because learn.predict() expects numpy array to be uint8 tyope of RGB channels image. Dont use cv2.imread() also as the will be the channels to BGR, hence bad prediction. (unless you want to fix channels before sending it to learn.predict()). instead just do as:
img =np.asarray(Image.open(‘path_to_image’))
learn.predict(img)

this will work like charm.

1 Like