Training with an imbalanced data-set
I recently tried to train using a training set in which there was a different number of training images for each category. This results in a bias for the category with the largest number of training examples. For instance, if there are 10 times as many "cat" images as there are "dog" images, the bias would be in favor of classifying each test image as "cat". I found that I needed to make each batch of the SGD solver more balanced, by making it equally likely to read a "cat" image as a "dog" image. I did this by counting the frequency of each label in the dataset, and including a random variable in the data_layer which randomly skips images in each iteration, if their label is more frequent than the average. So I created a new data_layer which takes into acount this random sampling method, and found that it helps reduce the bias. I wonder if this issue has been addressed before, and whether I should make a PR to include this new balanced_data_layer in caffe.
I think this is a nice feature, but it should not be a new type of layer. Instead I think this should be a parameter for the existing data layers. For example it can be implemented with a file name parameter that links to a file with skip probabilities for each label.
That's also an option. Although I'm not saving the label probabilities to a file, but calculating them once in the LayerSetup call.
I don't know if it's the case but I'm wondering, would re-using images from small classes very often cause over-fitting for those classes?
Some other ideas to solve this problem are discussed in "Neural Network Classification and Prior Class Probabilities" http://link.springer.com/chapter/10.1007%2F3-540-49430-8_15
Please ask usage questions on the caffe-users list. Thanks!