python - CNN模型的训练精度总是为零?如何提高训练的准确性
问题描述
代码有效,但我在每个时期都收到了零的准确度值,尝试了谷歌和 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
任何可能的方法来提高上述问题的准确性,请帮助我
解决方案
推荐阅读
- html - 如何使用三角形中设置的 3 个点创建 svg 渐变,这些点混合在一起
- scala - TCP 服务器处理多个连接
- python - 烧瓶棉花糖嵌套模式不适用
- icons - 设置带有路径和图标索引的快捷方式图标
- actions-on-google - 无法编辑 Google 智能家居操作示例调用
- python - 同时枚举2个python字典的值?
- c++ - 变量重新定义不发出警告
- php - 如何通过使用 MongoDB 中的 Laravel 雄辩关系在关系字段上应用条件来获取数据?
- angular - withLatestFrom() 返回整个状态
- mysql - 如何优化我的查询在 mysql 中花费了太多时间