How to load an image and show the image using keras?

后端 未结 2 1194
耶瑟儿~
耶瑟儿~ 2021-02-18 23:41
%matplotlib inline
from keras.preprocessing import image

import matplotlib.pyplot as plt
import numpy as np
img = np.random.rand(224,224,3)
plt.imshow(img)
plt.show()

         


        
2条回答
  •  别那么骄傲
    2021-02-19 00:07

    This question is kind of old, but there is a very comfortable way to display images:

    tf.keras.preprocessing.image.array_to_img(image[0]).show()
    

    Your image has to have 3 dimensions (if its in a batch as normally, just take desired_element). Works fine on EagerTensors or numpy arrays.

提交回复
热议问题