该代码有效,但是我在每个时期都收到了零的准确性值,尝试了google和stackoverflow的许多想法和建议,但没有任何帮助
from numpy import array
from numpy import reshape
import numpy as np
def model_CNN(X_train,Y_train,X_test,Y_test):
model = Sequential()
model.add(Conv1D(filters=512, kernel_size=32, padding='same', kernel_initializer='normal', activation='relu', input_shape=(256, 1)))
model.add(Conv1D(filters=512, kernel_size=32, padding='same', kernel_initializer='normal', activation='relu'))
model.add(Dropout(0.2)) # This is the dropout layer. It's main function is to inactivate 20% of neurons in order to prevent overfitting
model.add(Conv1D(filters=256, kernel_size=32, padding='same', kernel_initializer='normal', activation='relu'))
model.add(Dropout(0.2))
model.add(Conv1D(filters=256, kernel_size=32, padding='same', kernel_initializer='normal', activation='relu'))
model.add(Flatten())
optimizer = keras.optimizers.SGD(lr=0.001, momentum=0.5 )
model.compile(loss='mean_squared_error', optimizer=optimizer,metrics=['accuracy'])
convolutional_model = model.fit(X_train, Y_train, epochs=5,batch_size=256,verbose = 1, validation_data=(X_test, Y_test))
这是我的价值观的形状:
(426, 29, 1) (426, 1)
(143, 29, 1) (143, 1)
我已经收到了这样的输出:
Epoch 1/5
WARNING:tensorflow:Model was constructed with shape (None, 256, 1) for input Tensor("conv1d_48_input:0", shape=(None, 256, 1), dtype=float32), but it was called on an input with incompatible shape (None, 29, 1).
WARNING:tensorflow:Model was constructed with shape (None, 256, 1) for input Tensor("conv1d_48_input:0", shape=(None, 256, 1), dtype=float32), but it was called on an input with incompatible shape (None, 29, 1).
2/2 [==============================] - ETA: 0s - loss: 66.5119 - accuracy: 0.0000e+00WARNING:tensorflow:Callbacks method `on_train_batch_end` is slow compared to the batch time (batch time: 0.0449s vs `on_train_batch_end` time: 0.0872s). Check your callbacks.
WARNING:tensorflow:Model was constructed with shape (None, 256, 1) for input Tensor("conv1d_48_input:0", shape=(None, 256, 1), dtype=float32), but it was called on an input with incompatible shape (None, 29, 1).
2/2 [==============================] - 0s 216ms/step - loss: 66.5119 - accuracy: 0.0000e+00 - val_loss: 11.4075 - val_accuracy: 0.0000e+00
Epoch 2/5
2/2 [==============================] - 0s 142ms/step - loss: 20.7915 - accuracy: 0.0000e+00 - val_loss: 5.1864 - val_accuracy: 0.0000e+00
Epoch 3/5
2/2 [==============================] - 0s 140ms/step - loss: 11.4995 - accuracy: 0.0000e+00 - val_loss: 3.5993 - val_accuracy: 0.0000e+00
Epoch 4/5
2/2 [==============================] - 0s 145ms/step - loss: 8.5100 - accuracy: 0.0000e+00 - val_loss: 2.9013 - val_accuracy: 0.0000e+00
Epoch 5/5
2/2 [==============================] - 0s 139ms/step - loss: 7.1619 - accuracy: 0.0000e+00 - val_loss: 2.4821 - val_accuracy: 0.0000e+00
任何可以提高上述问题准确性的方法,请帮助我