# How to maintain accuracy with more classes?

I'm working on a CNN model (implemented by keras) that detects landmarks from images. Every landmark (for example Acropolis, Big Ben, Eiffel Tower etc) is as a separate class and is divided into own directory. The training dataset contains 1600 images, validation 400 images and test 500 images. The training process has 80 iterations.

I noticed that with two or three classes the accuracy is quite good (3 classes => accuracy: 0.8353) but by every next class it's getting to decrease.

Is it so that adding more classes increases features and complexity? What could be the solution for that? Adding more layers or data? I have tried to add more layers but it's rather worsened the result than made it better. Is it because of vanishing gradient? Adding more data is big problem because I just can't find more unique images. I also changed other config parameters (optimization algorithm, dropout rate etc) but with no result.

The used config parameters are:

NUMBER_OF_CLASSES = 4
BATCH_SIZE = 32
EPOCHS = 80
DROPOUT_RATE = 0.3
LOSS = 'categorical_crossentropy'
OPTIMIZER = 'rmsprop'
METRICS = ['accuracy']
CLASS_MODE = 'categorical'


And constructed model:

model = Sequential()
model.add(Conv2D(32, kernel_size=(3, 3), input_shape=input_shape))

--------------
Total params: 721,604
Trainable params: 719,620
Non-trainable params: 1,984


There can be multiple explenations.

But here are some:

Images in train test and valid that are poor for some classes are not representative in train (poperties of these objects are not to be found hence you cant predict on something that you did not atleast partially learn on)- covariate shift

You say adding data is problematic and I understand but just note that more data beats everything else by a mile. Seriously. Hence augment the data, A LOT!. And make sure that for every class properties are representative and to be found in every train test and valid set.

I can start talking about architecture but these are marginal benefits at this point, make sure you have this point right. Without that every discussion about architeture if futile.

I used Keras ImageDataGenerator for data augmentation. Isn't that enough?

train_datagen = ImageDataGenerator(
rescale=1. / 255,
rotation_range=20,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
vertical_flip=True)


What other methods/tools should I consider?

• Please edit your original question or ask a new question if you want to give more details or ask additional questions. Use an answer only if it's a solution to your question. – Erwan Dec 25 '19 at 22:20