How to upload image and show image using keras?

%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()

img_path = "image.jpeg"
img = image.load_img(img_path, target_size=(224, 224))
print(type(img))

x = image.img_to_array(img)
print(type(x))
print(x.shape)
plt.imshow(x)

I have code that should print an image. But it shows the image in the wrong channels. What am I missing here?

+4
source share
1 answer

This is an image scaling issue. The input to imshow () expects it to be in the range 0-1, while you pass it the input of the range [0-255]. Try viewing it as:

plt.imshow(x/255.)
+3
source

Source: https://habr.com/ru/post/1680479/


All Articles