# Data augmentation based on the class type in the CNN model

I would like to use CNN model to classify images but some classes in my dataset have low amount of data.

Can I apply data augmentation based on the number of the images in the class?

For example, the classes that contain 10 images will be 50 after augmentation that means the number of images is increased 500%, and the classes that contain 20 images will be increased 250% to be 50 images and the classes that contains 30 images will be increased 166% to be 50 images.

So, I would like to increase the data based on the number of images in the class.

Try under/ or oversampling and aditionally use data augmentation for your input data.

• Should I apply oversampling on the training batches and testing batches or I can apply it only on testing batches? How can I make oversampling manually?!!
– N.IT
Jul 16 '18 at 20:47

I would not use data augmentation to only some classes. Maybe this brings a bias in your data set.

I would use weighted examples. So if the network sees a class that has less example, the gradient is amplified. Additionally you should be be pass at least one example of each class at one batch (if your number of classes allow it).

• What is weighted examples? How can I pass at least one example of each class at one batch?
– N.IT
Jul 17 '18 at 8:30
• With examples I meant training data. Sorry that was not correct. Here are two useful links: [1], [2]. Concerning the one example per batch I assume you use keras, since you tagged it. In Keras you can use the fit_generator, where you can write you own batch generator. [1]: stackoverflow.com/questions/45867942/… [2]: reference.wolfram.com/language/tutorial/…
– Lau
Jul 17 '18 at 8:49