python - ValueError:无法将大小为 6744500 的数组重塑为形状 (574,1,64,47)
问题描述
我正在使用来自 sklearn 的 fetch_lfw_people 来识别面部,但是当我 trat to reshape II 得到这个错误 ValueError: cannot reshape array of size 6744500 into shape (574,1,64,47)
但是对于我拥有的数据它似乎是正确的参数,是
我知道的文档文档的图像大小 574 *1*64*47 不是 6744500 而是我拥有的数据
lfw_people = fetch_lfw_people(min_faces_per_person=200, resize=1)
X = lfw_people.data
y = lfw_people.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25)
X_train = X_train.reshape(X_train.shape[0], 1, 64, 47).astype('float32')
X_test = X_test.reshape(X_test.shape[0], 1, 64, 47).astype('float32')
解决方案
尝试这个:
获取有关图像大小的信息:
In [46]: print(lfw_people.images.shape)
(766, 125, 94)
即整个数据集有766张图片。每张图片都有形状:(125, 94)
重塑:
In [47]: X_train = X_train.reshape((X_train.shape[0],) + lfw_people.images.shape[1:])
结果:
In [48]: X_train.shape
Out[48]: (574, 125, 94)
推荐阅读
- c# - 您如何随机选择文本文件中的一行,将其显示在标签上并从列表中删除?
- javascript - 试图将 MySQL 查询的结果放入 JavaScript 数组
- angular - 当我加载有关服务的数据时,mat-table 中的过滤器不起作用
- rust - 不知道如何使用 nom 的 dbg_dmp
- php - 与许多数组相交的最佳方法
- javascript - 视频数组无法在最后一个视频播放时获取下一个按钮以从数组中的第一个视频开始再次播放
- ansible - Ansible 值来自 aws secrets manager
- tizen - Tizen 原生 UI 创建
- windows - 如何在 Windows 批处理上重写这个 bash 命令?
- api - 资源是rest api的强制性条件吗?