所以,我有一个脚本,它应该把一个数字转换成一个数组,这样我就可以输入我的AI了。但是我用的一本书告诉我,要这样做:
img_array = scipy.misc.imread("picofannumber.png", flatten = True)
img_data = 255.0 - img_array.reshape(784)所以,不工作,我想我的库太过时了,因为那是行不通的。所以我现在用这个:
img_array = imageio.imread("picofannumber.png", as_gray = True)
img_data = 255.0 - img_array.reshape(784) 但我的问题是:
ValueError:无法将大小为361928的数组整形为形状(784,)
我也试过
img_array = imageio.imread("picofannumber.png", as_gray = True)
img_data = 255.0 - img_array.reshape(28,28) 但同样的错误也不起作用。
发布于 2020-07-21 00:36:01
所以对于所有刚刚偶然发现这篇文章的人来说:
img_array.reshape(784)只调整“numpy数组”的大小,不调整图片的大小。
更新后的(工作)代码:
import imageio
from PIL import Image
Image.open("picofannumber.png").resize((28,28),Image.LANCZOS).save("picofannumber.png")
img_array = imageio.imread("picofannumber.png", as_gray=True)
img_data = 255.0 - img_array.reshape(784)https://stackoverflow.com/questions/63005667
复制相似问题