Deep learning ValueError:检查输入时出错:预期conv1d_1_输入具有形状(无,500000,3253),但获得具有形状(500000,3253,1)的数组

Deep learning ValueError:检查输入时出错:预期conv1d_1_输入具有形状(无,500000,3253),但获得具有形状(500000,3253,1)的数组,deep-learning,keras-layer,cnn,Deep Learning,Keras Layer,Cnn,我想用卷积神经网络训练我的数据,我已经重塑了我的数据: 这些是我使用的参数: 'x_train.shape'=(500000, 3253) 'y_train.shape', (500000,) 'y_test.shape', (20000,) 'y_train[0]', 97 'y_test[0]', 99 'y_train.shape', (500000, 256) 'y_test.shape', (20000, 256) 这就是我定义模型体系结构的方式: # 3. Define model

我想用卷积神经网络训练我的数据,我已经重塑了我的数据: 这些是我使用的参数:

'x_train.shape'=(500000, 3253)
'y_train.shape', (500000,)
'y_test.shape', (20000,)
'y_train[0]', 97
'y_test[0]', 99
'y_train.shape', (500000, 256)
'y_test.shape', (20000, 256)
这就是我定义模型体系结构的方式:

# 3. Define model architecture
model = Sequential()

model.add(Conv1D(64, 8, strides=1, padding='valid',
                        dilation_rate=1, activation=None, use_bias=True, kernel_initializer='glorot_uniform',
                        bias_initializer='zeros', kernel_regularizer=None, bias_regularizer=None,
                        activity_regularizer=None, kernel_constraint=None, bias_constraint=None, input_shape=x_train.shape))
# input_traces=N_Features   
# input_shape=(batch_size, trace_lenght,num_of_channels)            
model.add(MaxPooling1D(pool_size=2,strides=None, padding='valid'))
model.add(Flatten())
model.add(Dropout(0.5))
model.add(Dense(1, activation='relu'))

model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
print(model.summary())


model.fit(x_train, y_train, batch_size=100, epochs=500,verbose=2)
但我有两个错误: 1-

ValueError: Error when checking input: expected conv1d_1_input to have shape (None, 500000, 3253) but got array with shape (500000, 3253, 1)
2- 使用
model.fit()


如何解决此问题?

输入形状错误,对于NO,应为input_shape=(13253),对于TensorFlow,应为(3253,1)。输入形状不包括采样数

然后,您需要重塑数据以包括通道轴:

x_train = x_train.reshape((500000, 1, 3253))
或者,如果使用TensorFlow,则将通道标注移动到末端。在这些变化之后,它应该会起作用

input_shape = (3253, 1)
这必须是第一个卷积层的输入形状
Conv1D

model.fit()
出现错误,因为您尚未构建模型