【发布时间】:2020-01-28 04:56:18
【问题描述】:
在 MNIST 数据分类期间,我无法从自己上传自定义图像并给出 ValueError 无法将大小为 2352 的数组重新整形为 (1,28,28,1)
import numpy as np
from google.colab import files
from tensorflow.keras.preprocessing import image
import matplotlib.pyplot as plt
uploaded = files.upload()
for fn in uploaded.keys():
path = '/content/' + fn
img = image.load_img(path, target_size =(28, 28))
x = image.img_to_array(img)
x = np.expand_dims(x, axis = 0)
images = np.vstack([x])
print(images.shape)
images = images.reshape(1, 28, 28, 1)
print(images.shape)
classes = model.predict(images, batch_size = 10)
Capture.PNG(image/png) - 8252 bytes, last modified: 1/26/2020 - 100% done
Saving Capture.PNG to Capture (1).PNG
(1, 28, 28, 3)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-156-810149b1d6fd> in <module>()
13 images = np.vstack([x])
14 print(images.shape)
---> 15 images = images.reshape(1, 28, 28, 1)
16 print(images.shape)
17 classes = model.predict(images, batch_size = 10)
ValueError: cannot reshape array of size 2352 into shape (1,28,28,1)
【问题讨论】:
标签: python deep-learning