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

后端 未结 2 1195
耶瑟儿~
耶瑟儿~ 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-18 23:53

    This is a image scaling issue. The input to the imshow() expects it to be in the 0-1 range, while you are passing it a [0-255] range input. Try to view it as:

    plt.imshow(x/255.)
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题