ValueError:无法将大小为6744500的数组重塑为形状(574,1,64,47)

时间:2018-05-20 15:50:27

标签: python scikit-learn

我正在使用sklearn中的fetch_lfw_people来识别面部,但是当我重新整形时我得到了这个错误ValueError: cannot reshape array of size 6744500 into shape (574,1,64,47)但是对于我拥有的数据看起来像是正确的参数,是图像大小说文档doc 我知道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')

1 个答案:

答案 0 :(得分:0)

试试这个:

获取有关图片大小的信息:

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)