0
votes

I want to design CNN for dataset that have 300 classes. I have tested with following model for two classes. It gives good accuracy.

model = Sequential([
Conv2D(16, 3, padding='same', activation='relu', input_shape=(IMG_HEIGHT, IMG_WIDTH ,3)),
MaxPooling2D(),
Conv2D(32, 3, padding='same', activation='relu'),
MaxPooling2D(),
Conv2D(64, 3, padding='same', activation='relu'),
MaxPooling2D(),
Flatten(),
Dense(512, activation='relu'),
Dense(1, activation='sigmoid')
])

But I'm increasing number of classes as 5, accuracy decreases around to 0.2. How can I design CNN architecture for 300 classes?

1
What is you 5 classes classifier exactly? Maybe you stick with independent binary units instead of a softmax? - dedObed
This is not a programming question, you could start by looking at neural net architectures for the ImageNet dataset (1000 classes) - Dr. Snoopy
Also, you can try various pre-trained models like VGG and Inception via tf.keras.applications module. - Shubham Panchal

1 Answers

0
votes

In order to perform a training on a dataset of more than 2 classes, you need to use the categorical_crossentropy loss and the softmax activation layer for your last Dense layer.

The number of neurones of your last Dense will determine the number of classes you want to predict, so if you have 300 classes it will look like that :

[...]
MaxPooling2D(),
Flatten(),
Dense(512, activation='relu'),
Dense(300, activation='softmax')
])

Moreover, the more classes you have, the tougher it will get for the model to learn the features of each ones. So you will need to increase its width (more filter), its depth (more convolutional blocs) or it's resolution (bigger inputs).

A good start for designing CNN models, it's to look at the VGG architecture and its convolutionnal blocs.

Hope it will help you to have some intuitions.