我正在尝试创建一个keras CNN来预测我的ECG数据。我的x_train的形状像640,3498,1,y_train的形状像640,2(具有to_categorical 2类),我正在尝试构建模型。
X_train:
[[[ 3.96889100e-12]
[ 2.96721687e-12]
[ 3.76118701e-12]
...
[ 4.50912277e-12]
[ 4.10963106e-12]
[ 4.28550483e-12]]
[[-3.28395026e-12]
[-1.30043687e-12]
[ 1.66892740e-12]
...
[ 0.00000000e+00]
[ 0.00000000e+00]
[ 0.00000000e+00]]
[[-3.71662156e-11]
[-3.47206950e-11]
[-3.72873674e-11]
...
[-3.59975902e-11]
[-3.60138075e-11]
[-3.74937527e-11]]
y_train:
[[1. 0.]
[0. 1.]
[1. 0.]
[1. 0.]
[1. 0.]
[1. 0.]
[0. 1.]
[0. 1.]
[1. 0.]
[0. 1.]]
我正在使用的代码是这样:
ctivation = 'relu'
model = Sequential()
model.add(Conv1D(filters=64, kernel_size=5, padding='same', kernel_regularizer=l2(0.01), bias_regularizer=l2(0.01),
kernel_initializer='normal', activation=activation, input_shape=X_train_dfm.shape[1:]))
model.add(MaxPool1D(pool_size=2))
model.add(Conv1D(filters=64, kernel_size=5, padding='same', kernel_regularizer=l2(0.01), bias_regularizer=l2(0.01),
kernel_initializer='normal', activation=activation))
model.add(MaxPool1D(pool_size=2))
model.add(Conv1D(filters=32, kernel_size=5, padding='same', kernel_regularizer=l2(0.01), bias_regularizer=l2(0.01),
kernel_initializer='normal', activation=activation))
model.add(MaxPool1D(pool_size=2))
model.add(Conv1D(filters=32, kernel_size=5, padding='same', kernel_regularizer=l2(0.01), bias_regularizer=l2(0.01),
kernel_initializer='normal', activation=activation))
model.add(MaxPool1D(pool_size=2))
model.add(Flatten())
model.add(Dense(2, activation='softmax'))
adam = keras.optimizers.Adam(lr=0.01)
model.compile(optimizer = adam, loss = 'categorical_crossentropy', metrics=['accuracy'])
model.summary()
期望值为整数0-1。但是,所有这些预测都是在〜-0.4和0.5之间浮动。
我尝试了10个测试数据。那就是我得到的
[[0.4986445 0.50135547]
[0.4986445 0.50135547]
[0.4986445 0.50135547]
[0.4986445 0.50135547]
[0.4986445 0.50135547]
[0.4986445 0.50135547]
[0.4986445 0.50135547]
[0.4986445 0.50135547]
[0.4986445 0.50135547]
[0.4986445 0.50135547]]
val_loss, val_accuracy : [0.6938661336898804, 0.5062500238418579]
请帮助我,我一个星期就卡住了。任何帮助将不胜感激!