简体   繁体   English

如何提高这个 CNN Model 的准确性?

[英]How to increase the accuracy of this CNN Model?

I have tried many combinations in the values for this model.我在这个 model 的值中尝试了很多组合。

  1. Can 2D Convolutions be used instead of 1D for the following case?对于以下情况,可以使用 2D 卷积代替 1D 吗?
  2. How can accuracy be improved for the training dataset?如何提高训练数据集的准确性?

shape of original dataset: (343889, 80)原始数据集的形状:(343889, 80)

shape of - training dataset: (257916, 80)训练数据集的形状:(257916, 80)

shape of - training Labels: (257916,) shape of - training 标签:(257916,)

shape of - testing dataset: (85973, 80)形状 - 测试数据集:(85973, 80)

shape of - testing Labels: (85973,)形状 - 测试标签:(85973,)

The model is model 是

inputShape = (80,1,)
model = Sequential()
model.add(Input(shape=inputShape))
model.add(Conv1D(filters=80, kernel_size=30, activation='relu'))
model.add(MaxPooling1D(40))
model.add(Dense(60))
model.add(Dense(9))
model.compile(optimizer='adam', loss='binary_crossentropy',
              metrics=['accuracy'])

Model's summary模型的总结

Model: "sequential_11"
_________________________________________________________________
 Layer (type)                Output Shape              Param #   
=================================================================
 conv1d_11 (Conv1D)          (None, 51, 80)            2480      
                                                                 
 max_pooling1d_9 (MaxPooling  (None, 1, 80)            0         
 1D)                                                             
                                                                 
 dense_8 (Dense)             (None, 1, 60)             4860      
                                                                 
 dense_9 (Dense)             (None, 1, 9)              549       
                                                                 
=================================================================
Total params: 7,889
Trainable params: 7,889
Non-trainable params: 0
_________________________________________________________________

The training is given below.培训如下。

Epoch 1/5
8060/8060 [==============================] - 56s 7ms/step - loss: -25.7724 - accuracy: 0.0015
Epoch 2/5
8060/8060 [==============================] - 44s 5ms/step - loss: -26.7578 - accuracy: 0.0011
Epoch 3/5
8060/8060 [==============================] - 43s 5ms/step - loss: -26.7578 - accuracy: 0.0011

You can try a couple of things to adjust your model performance.您可以尝试一些方法来调整您的 model 性能。

  • Firstly Try Using Conv2D layers首先尝试使用 Conv2D 图层
  • Modify kernel size to (3,3)修改kernel大小为(3,3)
  • Change optimiser to SGD and loss to Sparse Categorical Crossentropy Try the following, run the model for a longer epoch and let's see how that goes.将优化器更改为 SGD,并将损失更改为稀疏分类交叉熵尝试以下操作,运行 model 更长的时间,让我们看看结果如何。

Since you want to classify something, your model is not doing so (at least not directly).既然你要分类,你的 model 并没有这样做(至少没有直接这样做)。

The problems I can see at first sight are:我第一眼看到的问题是:

  • You use no activation functions (especially in the last layer)您不使用激活函数(尤其是在最后一层)
  • You use 9 output neurons, but binary crossentropy loss.您使用 9 个 output 个神经元,但使用二元交叉熵损失。

First of all, in your shoes, I would revise the classification problems with neural.network.首先,站在你的立场上,我会用 neural.network 修改分类问题。

About your model, a starting point could be this edit关于您的 model,起点可能是此编辑

inputShape = (80,1,)
model = Sequential()
model.add(Conv1D(filters=80, kernel_size=30, activation='relu', input_shape = inputShape))
model.add(MaxPooling1D(40))
model.add(Dense(60), activation='relu') # note activation function
model.add(Dense(9), activation='softmax') # note activation function
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy',
              metrics=['accuracy']) # note the loss function

I am not saying this is going to solve your problem (without knowing data it is impossible) but it is a start, then you have to work on fighting overfitting, hyperparameters tuning, etc.我并不是说这会解决你的问题(不知道数据是不可能的)但这是一个开始,然后你必须努力解决过度拟合、超参数调整等问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM