How to do prediction on numpy Image array

Hello there,

i am using 2.4.1.

I have trained my segmentation model using and I have done 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(‘path_to_image’))

this will work like charm.

1 Like