【发布时间】:2021-01-18 13:05:55
【问题描述】:
我正在尝试通过from tensorflow.keras.preprocessing import image 导入图像。我的图像是我在纸上写的手写数字,然后我通过手机从其中拍照,然后将其大小更改为 28*28:
我使用了以下代码:
img_width, img_height = 28, 28
img = image.load_img('rgb_seven.jpeg', target_size=(img_width, img_height))
img_tensor = image.img_to_array(img)
img_tensor.shape
形状结果是:
(28, 28, 3)
似乎图像被加载为 3D 数组。我需要一个二维数组,所以我这样做了:
x_image = img_tensor.reshape(len(img_tensor),-1)
x_image.shape
结果是:
(28, 84)
为什么是 84?我需要 28,因为我想将其展平以作为输入层插入。
什么问题?
【问题讨论】:
标签: python python-3.x tensorflow keras deep-learning