在为 1D CNN 设置 1 通道 ECG 数据输入大小时,我遇到了很大的困惑。
为了简单起见,数据结构如下:
500
段1.0, 2.0 or 3.0
100
原始心电图样本(1通道)即[1.53, 1.67, 1.56...]
我试图从this question调整输入形状,这意味着我的
(examples, time_steps, features)
将是(500, 100, 1)
因此我的输入形状可以是(100,1)
甚至(None, 1)
。但是,当我运行以下命令时:
# shape
# x_train shape: (500, 100)
# y_train shape: (500,)
model = Sequential()
model.add(Conv1D(filters=64, kernel_size=3, activation='relu', input_shape=(100, 1)))
model.add(Conv1D(filters=64, kernel_size=3, activation='relu'))
model.add(MaxPooling1D(pool_size=2))
model.add(Flatten())
model.add(Dense(100, activation='relu')) # Not sure if this line is necssary
model.add(Dense(3, activation='softmax')) # Converge to 3 outputs
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
调用
model.fit()
时出现以下错误:
ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 500, 1), found shape=(None, 100)
如果我然后用
(None, 500, 1)
替换形状并重新运行我在model.add(Dense(n_features, activation='relu'))
上得到这个错误:
The last dimension of the inputs to a Dense layer should be defined. Found None. Full input shape received: (None, None)
有什么解决办法吗?它取决于输入的形状吗?也许我误解了docs.