代码运行时报错,无法处理,请求帮助
x_train, y_train = generateds(train_path, train_txt)
x_test, y_test = generateds(test_path, test_txt)
x_train = x_train.astype('float32')
x_test = x_test.astype('float32')
x_train, x_test = x_train / 255.0, x_test / 255.0 # 归一化,将每一个像素缩放到0-1之间
print("x_train.shape", x_train.shape)
x_train = x_train.reshape(x_train.shape[0],256,256,3)
x_test = x_test.reshape(x_test.shape[0],256,256,3)
print("x_train.shape", x_train.shape)
报错信息:
x_train.shape (22046, 256, 256)
Traceback (most recent call last):
File "D:\ningyupeng\pythonProject\Graduation Project V1.0\xunlian.py", line 68, in
x_train = x_train.reshape(x_train.shape[0],256,256,3)
ValueError: cannot reshape array of size 1444806656 into shape (22046,256,256,3)
因为
1444806656/256/256=22046
所以
你要么将
x_train = x_train.reshape(x_train.shape[0],256,256,3)
改为
x_train = x_train.reshape(x_train.shape[0],256,256,1)
要么在
x_train = x_train.reshape(x_train.shape[0],256,256,3)
之前,确保x_train的size是1444806656*3而不是1444806656