3
$\begingroup$

I am working on a deep learning CNN project. The dataset contains more than 500 classes and the classes have different numbers of items (images). For example, some of the classes have 5 images and some of the classes have 10 and some of the classes have 20 images and some of the classes have more then 20 images.

Can I use this dataset to create the CNN model?

Should the number of the images in each class be the same number?

Note: I will use VGG to train the model.

$\endgroup$
2
  • $\begingroup$ Why are you using VGG?? That's an overkill $\endgroup$
    – Aditya
    Jun 29, 2018 at 13:09
  • $\begingroup$ Because I will not train the model from scratch $\endgroup$
    – N.IT
    Jul 1, 2018 at 21:32

2 Answers 2

2
$\begingroup$

Frankly, even 50 images will not be sufficient if you are going to create and use a CNN model. If you think you want more images for you model training, then go for data augmentation. It is a process of transforming an image by a small amount (be it height, width, rotation etc or any combination of these). In this way, an image and its augmented image will differ slightly. You can find relevant article here-

https://medium.com/nanonets/how-to-use-deep-learning-when-you-have-limited-data-part-2-data-augmentation-c26971dc8ced

To answer the part that should there be same number of images in each class, there should be approximately same number. This problem is a general problem while working on classification task and there are several ways to deal with it, including simulating the data (augmentation).

I would suggest that first create a separate test set, then on the remaining train set, use data augmentation and finally create the model.

EDIT

Using a pretrained convnet is also an option, as stated in a deep learning book-

A common and highly effective approach to deep learning on small image datasets is to use a pretrained network. A pretrained network is a saved network that was previously trained on a large dataset, typically on a large-scale image-classification task. If this original dataset is large enough and general enough, then the spatial hierarchy of features learned by the pretrained network can effectively act as a generic model of the visual world, and hence its features can prove useful for many different computer vision problems, even though these new problems may involve completely different classes than those of the original task. For instance, you might train a network on ImageNet (where classes are mostly animals and everyday objects) and then repurpose this trained network for something as remote as identifying furniture items in images.

$\endgroup$
4
  • $\begingroup$ Do you mean I have to increase the number of images in the classes that have low amount of images? $\endgroup$
    – N.IT
    Jun 29, 2018 at 12:57
  • 1
    $\begingroup$ Yeah, pretty much. If this does not work to your expectation, try creating more images for all classes (even for that which has highest number of images). $\endgroup$
    – Ankit Seth
    Jun 29, 2018 at 13:15
  • $\begingroup$ Should all classes have the same number of images ? $\endgroup$
    – N.IT
    Jun 29, 2018 at 14:20
  • 1
    $\begingroup$ Preferably approximately same number. (like 90, 100, 94, 101 etc). These numbers are just for approximation, not the exact quantity. $\endgroup$
    – Ankit Seth
    Jun 29, 2018 at 15:00
1
$\begingroup$

You have a very low amount of images to create a CNN from scratch. You may be able to train your model via transfer learning from a pre-trained model, but you still may have too small of a dataset.

See something like this: https://www.analyticsvidhya.com/blog/2017/06/transfer-learning-the-art-of-fine-tuning-a-pre-trained-model/

Basically, you can take an image model that has been trained on tons of images, and either use their weights to seed or (more likely) just retrain the fully connected dense layers.

$\endgroup$
3
  • $\begingroup$ But he has to first check if his image categories are in the pre-trained model or not. Even if one category is not present, he can't use that. $\endgroup$
    – Ankit Seth
    Jun 28, 2018 at 11:46
  • 1
    $\begingroup$ I don't see what that would need to be the case. We're essentially using the pre-trained CNN as a feature extractor, so as long as the images are somewhat similar to the original training set, it would still be useful. $\endgroup$
    – Andy M
    Jun 28, 2018 at 11:49
  • $\begingroup$ I will use vgg net to create the model $\endgroup$
    – N.IT
    Jun 29, 2018 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.