ValueError:无法将大小为3800的数组重塑为形状(3800,224,224,3)

时间:2019-11-11 04:34:19

标签: python-3.x machine-learning image-processing

我的代码是:

A = np.concatenate((folder[0], folder[1], folder[2], folder[3], folder[4], folder[5],
folder[6], folder[7], folder[8], folder[9], folder[10], folder[11]))

label = np.ones(4750,dtype = int)
label[0:263] = 0
label[263:653] = 1
label[653:940] = 2
label[940:1551] = 3
label[1551:1772] = 4
label[1772:2247] = 5
label[2247:2901] = 6
label[2901:3122] = 7
label[3122:3638] = 8
label[3638:3869] = 9
label[3869:4365] = 10
label[4365:4750] = 11

data,Label = shuffle(A,label,random_state=0)
train_data = [data, Label]
X,Y = [train_data[0],train_data[1]]

X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=1)

x_test, x_val, y_test, y_val = train_test_split(X_test, Y_test, test_size=0.2, random_state=1)



print(X_train.shape)

输出:(3800,268203)

print(f'train size: {X_train.shape}, val size: {x_val.shape}, test size: {X_test.shape}')

输出:火车尺寸:(3800,268203),val尺寸:(760,299,299,3),测试尺寸:(950,268203)

X_train = X_train.reshape((X_train.shape[0],299, 299, 3))

x_val = x_val.reshape((x_val.shape[0],299, 299, 3))

x_test = x_test.reshape((x_test.shape[0],299, 299, 3))

当我使用np.zero而不是X_train.reshape时,它正在工作,但是在构建模型后出现错误。 现在我得到的错误是:

   ValueError                                Traceback (most recent call last)
<ipython-input-79-bbe4db2d4820> in <module>
      3 X_val = X_val.reshape((X_val.shape[0],299,299,3))
      4 
----> 5 X_test = X_test.reshape((x_test.shape[0],299,299,3))

ValueError: cannot reshape array of size 254792850 into shape (760,299,299,3)

请帮助我解决这个问题。

0 个答案:

没有答案