# Improve test accuracy for TensorFlow CNN

I'm trying to use Tensorflow for signal classification. The signals are either normal or high-risk signals. For this purpose, I used convolutional neural networks. The length of signals are 685 and the architecture is:

• Convolution layer with 27 channels and 1 by 16 window size and stride 1.
• Max pooling layer with 1 by 2 window size and stride 2.
• Convolution layer with 14 channels and 1 by 32 window size and stride 1.
• Max pooling layer with 1 by 2 window size and stride 2.
• Convolution layer with 4 channels and 1 by 32 window size and stride 1.
• Max pooling layer with 1 by 2 window size and stride 2.
• Convolution layer with 3 channels and 1 by 10 window size and stride 1.
• Max pooling layer with 1 by 2 window size and stride 2.
• Fully connected layer with 20 neurons and dropout layer.
• Fully connected layer with 10 neurons and dropout layer.
• And finally Soft max layer.

After training the network using AdamOptimizer with learning rate 0.001 with 150000 signals the training accuracy is near 95 percent (batch training with 16 batch size is used), however testing accuracy using 20000 new signals is almost 50 percent. Since there is just 2 classes, this accuracy is no better than random guess.

model="conv1d-27-16-1,maxpool-2,conv1d-14-32-1,maxpool-2,conv1d-4-32-1,maxpool-2,conv1d-3-10-1,maxpool-2,full-20,full-10,softmax"

cnn=CNN_1D(model,input_size=685,n_classes=2,num_epochs=20,batch_size=16,dropout=0.75)
cnn.build_model()
cnn.training(validation_set='all')


How can I improve the testing accuracy in my network?

This is clearly a case of overfitting, since your validation error is way bigger than your training error. Having understood that overfitting is your problem, there are many ways you can address this problem:

I can see that you are already doing dropout, so setting the dropout higher should help. Moreover, you can try using dropout in more layers, not just the two last ones. If setting the dropout rate higher and setting more layers with dropout does not work, then this probably means that your training and validation data do not come from the same distribution. You can study statistical properties of your training data and validation and study if they come from the same distribution.

Extra comment: if there are just two classes, why don't you use a sigmoid activation function in the last layer?

• Is it better to use sigmoid activation function?
– H.H
Apr 26 '18 at 4:54
• When there are just two output classes it is the most generally used approach. Apr 26 '18 at 5:33
• I saw this post: stackoverflow.com/a/41409315/6485602
– H.H
Apr 26 '18 at 6:33
• I disagree, as with sigmoid you will have just one output layer that gives you a number between 0 and 1, which will be the probability of class 1. The probability of class 0 can be computed as 1 minus the probability of class 1. Apr 26 '18 at 6:51
• Yes that's much more reasonable. Thank you so much.
– H.H
Apr 26 '18 at 6:56