Data Science Asked by paul95 on December 10, 2020
I make small CNN from scratch to classify barcodes. I have two classes: one for images with barcodes and second for all what isn’t barcodes (items, animals, landscape, furniture, people). I got good training accuaracy (80%+ after 50 epochs) but my validation accuracy is constant and around 50% and it is my main problem. I am aiming in around 80% for validation accuracy. I use some technique as dropout, decrease number of parameters, data augmentation, etc. My train set is 480 images (240 – barcodes, 240 the rest) and my validation set is 120 (6060). What should I do to achieve about 80% accuracy on the validation set. I use keras and tensorflow framework. Here my CNN:
model = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(224, 224, 1), padding='same'),
tf.keras.layers.MaxPool2D(3, 3),
tf.keras.layers.BatchNormalization(),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Conv2D(64, (3, 3), activation='relu'),
tf.keras.layers.MaxPool2D(2, 2),
tf.keras.layers.BatchNormalization(),
tf.keras.layers.Conv2D(128, (3, 3), activation='relu'),
tf.keras.layers.MaxPool2D(2, 2),
tf.keras.layers.BatchNormalization(),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Conv2D(128, (3, 3), activation='relu'),
tf.keras.layers.MaxPool2D(2, 2),
tf.keras.layers.BatchNormalization(),
tf.keras.layers.Conv2D(64, (3, 3), activation='relu'),
tf.keras.layers.MaxPool2D(2, 2),
tf.keras.layers.BatchNormalization(),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(256, activation='relu'),
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Dense(1, activation='sigmoid')
])
model.compile(loss='binary_crossentropy', optimizer="adam", metrics=
['accuracy'])
Answered by Reinstate Monica on December 10, 2020
Adding more things to what @Solomonoff'sSecret have mentioned:
model.add(Dense(64, input_dim=64, kernel_regularizer=regularizers.l2(0.01), activity_regularizer=regularizers.l1(0.01)))
keras.layers.GlobalMaxPooling2D(data_format=None)
Try different optimizer like SGD
Try removing the last dropout, which is just before the softmax. I think it's forcing your network to a very large extent to generalize.
Wild guess, accuracy in validation of 50% suggest model is predicting almost everything as a single class. Check quality of the image in the validation set and try to compare it with the training one. Use Cross-validation here instead.
Answered by shivam shah on December 10, 2020
I used transfer learning technique and as pre-trained network I chose InceptionV3. It was good idea. In addition I gathered more dataset (800/200). My validation accuracy is above 80 % now.
Answered by paul95 on December 10, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP