Python Keras Conv1d输入形状:检查输入时出错
我正在使用keras和TF后端构建一个简单的Python Keras Conv1d输入形状:检查输入时出错,python,tensorflow,keras,deep-learning,Python,Tensorflow,Keras,Deep Learning,我正在使用keras和TF后端构建一个简单的Conv1dnet。数据具有以下形状: train feature shape: (33960, 3053, 1) train label shape: (33960, 686, 1) 我使用以下工具构建模型: def create_conv_model(): inp = Input(shape=(3053, 1)) conv = Conv1D(filters=2, kernel_size=2)(inp) pool = M
Conv1d
net。数据具有以下形状:
train feature shape: (33960, 3053, 1)
train label shape: (33960, 686, 1)
我使用以下工具构建模型:
def create_conv_model():
inp = Input(shape=(3053, 1))
conv = Conv1D(filters=2, kernel_size=2)(inp)
pool = MaxPool1D(pool_size=2)(conv)
flat = Flatten()(pool)
dense = Dense(686)(flat)
model = Model(inp, dense)
model.compile(loss='mse', optimizer='adam')
return model
模型摘要:
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_1 (InputLayer) (None, 3053, 1) 0
_________________________________________________________________
conv1d_1 (Conv1D) (None, 3052, 2) 6
_________________________________________________________________
max_pooling1d_1 (MaxPooling1 (None, 1526, 2) 0
_________________________________________________________________
flatten_1 (Flatten) (None, 3052) 0
_________________________________________________________________
dense_1 (Dense) (None, 686) 2094358
=================================================================
Total params: 2,094,364
Trainable params: 2,094,364
Non-trainable params: 0
跑步时
model.fit(x=train_feature,
y=train_label_categorical,
epochs=100,
batch_size=64,
validation_split=0.2,
validation_data=(test_feature,test_label_categorical),
callbacks=[tensorboard,reduce_lr,early_stopping])
我得到以下非常常见的错误:
ValueError: Error when checking input: expected input_1 to have 3 dimensions, but got array with shape (8491, 3053)
我已经检查了几乎所有关于这个非常常见的问题的帖子,但我一直无法找到解决方案。我做错了什么?我不明白发生了什么事。形状(84913053)
来自哪里
任何帮助都将不胜感激,我无法让它消失。更改
验证\u数据=(测试\u功能,测试\u标签\u分类)
在模型中。将功能安装到
validation\u data=(np.expand\u dims(test\u feature,-1),test\u label\u category)
该模型需要shape(8491,3053,1)
,但在上述代码中,您提供了shape(8491,3053)
能否请您再次检查并打印培训和验证数据的形状,即打印(train_feature.shape)
和打印(test_feature.shape)
?进一步(这与错误无关),您应该使用validation\u split
或validation\u data
,而不是两者都使用。在model.fit()之前立即打印(train\u feature.shape,train\u label\u category.shape):(33960,3053,1)(33960,686)好的,关于测试数据,即test\u feature.shape
?请仔细阅读我的评论:我正在寻找测试数据形状,而不是培训形状。请运行print(test\u feature.shape)
。