简体   繁体   English

提高 CNN 中的验证准确性

[英]increase validation accuracy in CNN


Below is my code to classify 2 kind of classes.下面是我对 2 种类进行分类的代码。
The accuracy increase gradually till reach about 87%.准确率逐渐提高,直到达到 87% 左右。
The problem is validation accuracy stuck between 0.5 and 0.6.问题是验证准确度停留在 0.5 和 0.6 之间。
I know it is over fitting problem.我知道这是过拟合问题。
I tried to manipulate the number of parameters, but still got same problem.我试图操纵参数的数量,但仍然遇到同样的问题。
Any idea about how the model can be improved?关于如何改进模型的任何想法?
Thanks so much非常感谢

from keras.models import Sequential
from keras.layers import Conv2D, Dropout, Activation
from keras.layers import MaxPooling2D
from keras.layers import Flatten
from keras.layers import Dense
import matplotlib.pyplot as plt
from keras.preprocessing.image import ImageDataGenerator


classifier = Sequential()

classifier.add(Conv2D(16, (3, 3), input_shape = (110, 110, 3)))
classifier.add(Activation('relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))

classifier.add(Conv2D(32,(3,3))) 
classifier.add(Activation('relu'))
classifier.add(MaxPooling2D(pool_size =(2,2)))

classifier.add(Conv2D(64,(3,3))) 
classifier.add(Activation('relu'))
classifier.add(MaxPooling2D(pool_size =(2,2)))

classifier.add(Flatten())

classifier.add(Dense(64))
classifier.add(Activation('relu'))
classifier.add(Dropout(0.5))
classifier.add(Dense(1))
classifier.add(Activation('sigmoid'))
classifier.compile(optimizer = 'rmsprop', loss = 'binary_crossentropy', metrics = ['accuracy'])

train_datagen = ImageDataGenerator(rescale = 1./255,
shear_range = 0.2,
zoom_range = 0.2,
horizontal_flip = True)

test_datagen = ImageDataGenerator(rescale = 1./255)

training_set = 
train_datagen.flow_from_directory('/home/ccc/Downloads/Compressed/CNN/AD/train',
target_size = (110, 110),
batch_size = 10,    #10
class_mode = 'binary')

test_set = test_datagen.flow_from_directory('/home/ccc/Downloads/Compressed/CNN/AD/test',
target_size = (110, 110),
batch_size =6,  # 6
class_mode = 'binary')

hist = classifier.fit_generator(training_set,
steps_per_epoch = 1160,
epochs = 50,
validation_data = test_set,
validation_steps = 300)

plt.plot(hist.history['accuracy'])
plt.plot(hist.history['val_accuracy'])
plt.title('Model accuracy')
plt.ylabel('Accuracy')
plt.xlabel('Epoch')
plt.legend(['Train', 'Val'], loc='upper left')
plt.show()

Add few more layers.Start with high learning rate and slowly decrease your learning rate.添加更多层。从高学习率开始,然后慢慢降低学习率。 Try different optimizers.尝试不同的优化器。 I recommend to use transfer learning technique for more validation accuracy.我建议使用迁移学习技术来获得更高的验证准确性。

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

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