How to read image from buffer using Keras?

Viewed 68

Image will be generated with matplotlib then saved to buffer afterwards read from buffer with OpenCV, I would like to perform this with keras

    fig = ax.get_figure()
    
    buf = io.BytesIO()      #buffer
    fig.savefig(buf)        #saving image in buf
    buf.seek(0)
    img_arr = np.frombuffer(buf.getvalue(), dtype=np.uint8)
    buf.close()

    img = cv2.imdecode(img_arr, 1)  #reading image form buffer

Desired method

    img = tf.keras.preprocessing.image.load_img(img_arr,  )
    image_arr = keras.preprocessing.image.img_to_array(img)
0 Answers
Related