I've recently started learning CNN's. I need a CNN that is specialized for insects detection. Dead insects will be put on a piece of paper / container, then images will be taken from a same distance, and are at same pixels.

I am expecting to prepare my own training datasets: - Thousands of images of a particular insect, let's say a housefly - Each image contains only one housefly - Consistent lighting for the photos taken

Then, I will start to train the CNN, save the model and so on. I'm not sure about the following:

  1. During operation of the model, will it still be able to detect the housefly if there are other insects in the image? (not covering the housefly of course)

  2. If I want my model to recognize housefly only, so the training datasets contain housefly only, true or false?

  3. If later I want my model to recognize 2 types of insects, housefly and ant, what type of datasets I need to prepare?

  4. I will eventually need to count the amount of houseflies in an image. Can anyone direct me to a correct path towards feasible methods?

  5. Does anyone has useful resources that explain on how to determine the suitable amount of convolutional layers (CL) and fully-connected layers (FCL)? The default seems to be 2 CL and 2 FCL, but I am wondering why not more than that?

  • $\begingroup$ Hello. We prefer that questions here are well focused and have can have verifiably 'right' answers without extended discussions, so I've removed information from your post that doesn't directly relate to your question. If you want to let other people know something about yourself, you can do so in your profile or talk on Computer Science Chat (when you have the reputation required to use chat) $\endgroup$
    – Discrete lizard
    Jan 28, 2018 at 16:44
  • $\begingroup$ That's a lot of questions. We usually prefer that you ask only 1 question per post. $\endgroup$
    – D.W.
    Jan 28, 2018 at 17:21
  • $\begingroup$ oh gosh, i think it's better to remove this post? it sounds inappropriate at here. I am sorry about that :( Sorry I am still new to this kind of things. Thanks @D.W. for replying. I appreciate :) $\endgroup$ Jan 29, 2018 at 2:58
  • $\begingroup$ There's no need to remove it. Once you get an answer, it lives on as a reference in case it is useful to others. And now you know, for when asking future questions. Hope you continue to participate on the site! $\endgroup$
    – D.W.
    Jan 29, 2018 at 4:18

1 Answer 1


The training set needs to have the same distribution of images as whatever you will be applying your classifier to. So, if you'll be running the classifier on some images of houseflies and some images of other insects (not house-flies), your training set needs to contain both kinds of images. If there are many other kinds of non-housefly images you'll be running the classifier on, the training set should contain images of those same kinds of insects, in a similar frequency to the frequency they'll occur when you use the classifier.

I encourage you to read about object classification vs object recognition vs object detection. See, e.g., https://stackoverflow.com/q/31750076/781723. The simplest kind of classifier takes an image of a single insect and outputs "housefly" or "not housefly". That kind of classifier will be trained on images of single insects -- and should only be expected to work correctly if you apply it to images of a single insect. However, you can also find techniques in the computer vision literature for recognizing the location of the insect in the image and dealing with multiple insects; read about object recognition and detection.

I'm not sure where you got the idea that the default is 2 convolutional layers followed by 2 fully connected layers, but there is no such default and no such rule. I'm not saying that's an unreasonable starting point, but there are no hard-and-fast rules that tell you how many layers to pick. Instead, you'll probably need to try several different possibilities and see how well they work. If you can find papers in the research literature that solve a similar problem, you can sometimes use them as guidance for a good network architecture, but if you're not aware of anything like that, you'll just have to experiment on your own.


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.