ValueError: Error when checking input: expected conv3d_1_input to have shape (704, 11, 3, 1) but got array with shape (72000, 704, 11, 3)

ValueError: Error when checking input: expected conv3d_1_input to have shape (704, 11, 3, 1) but got array with shape (72000, 704, 11, 3)

我正在研究将图像提供给 3D 卷积网络。该图像是 704 x 11 x 3 图像,我收到以下错误。训练图像的数量为 72000,CNN 的输入形状为 (704,11,3,1).

ValueError: Error when checking input: expected conv3d_1_input to have shape (704, 11, 3, 1) but got array with shape (72000, 704, 11, 3)

下面是我用 keras 编写的代码,用于提供给网络。

x = cv2.imread(image_path)
print (x.shape)
x = np.reshape(x,(1, num_features))
data_x.append(x)
...

# After splitting to train and validation and test
...

train_x = data['train_x']
test_x = data['test_x']
validate_x = data['validate_x']

#Convert into float and normalize
train_x = train_x.astype('float32')
test_x = test_x.astype('float32')
validate_x = validate_x.astype('float32')
train_x = train_x.reshape(train_x.shape[0], 704, 11, 3).astype('float32')
test_x = test_x.reshape(test_x.shape[0], 704, 11, 3).astype('float32')
validate_x = validate_x.reshape(validate_x.shape[0], 704, 11, 3).astype('float32')
train_x = train_x/255
test_x = test_x/255
validate_x = validate_x/255
data['train_x'] = train_x
data['test_x'] = test_x
data['validate_x'] = validate_x

... 
train_x = np.expand_dims(train_x, axis=0)
validate_x = np.expand_dims(validate_x, axis=0)
test_x = np.expand_dims(test_x, axis=0)
...
model = Sequential()
model.add(Conv3D(8, kernel_size = (3,3,3),data_format="channels_last", 
 activation = 'linear', input_shape=(704,11,3,1), padding='same'))
....

尝试更改 axis:

# makes train_x: (?, 704, 11, 3, 1)
train_x = np.expand_dims(train_x, axis=-1)
...

另外根据错误信息,train_x实际上并没有被重塑,所以仔细检查这个操作是否真的被调用了。