Cascade Object Detector: Unable to generate a sufficient number of negative samples

Hi, I am using the cascade object detector. I'm currently using the training image labeler to draw a bounding box around the ROI. However, when I run the command, trainCascadeObjectDetector, it only includes the positive images which I've provided in the training labeler and it will use the positive images to generate negative samples.
Also, I have this error message. "Cannot find enough samples for training."
"Unable to generate a sufficient number of negative samples for this stage. Consider reducing the number of stages, reducing the false alarm rate or adding more negative images."
May I know how do I train my negative images to include in the cascade object detector? I have my own set of negative images that I wish to include into my training sets. Thanks!

 Accepted Answer

Hi Leonard,
Negative images are images that do not contain the objects that you are trying to detect. They should, however, contain backgrounds that are typically associated with your objects of interest. So if you are trying to detect stop signs, the negative images should be pictures of streets and roads with no stop signs in them.
The Training Image Labeler app does not directly produce the negative images. The simplest thing is to capture of find them yourself. If that is difficult, then you can take the output of the Training Image Labeler app, and fill the regions corresponding to the bounding boxes with zeros or random noise.

12 Comments

Hi Dima,
I do have my own set of negative images which I would like to include in my training set however, I do not know how to include them in.
trainCascadeObjectDetector takes a parameters called negativeImages. It can either be a cell array containing the file names of the negative images, or it can be a directory where the negative images are stored.
Do I include negative image into the Training Image Labeler?
No, because you do not need to label anything in the negative images. You just need to tell trainCascadeObjectDetector where they are.
How do I resolve "Unable to generate a sufficient number of negative samples" issue? I have added more negative images into the folder but it is still giving the same problem. Currently, I have 600 positive and 1100 negative samples. Below is my code:
%%Load data
% Training image labeler (ROI)
load('trainingImage.mat');
data = positiveInstances;
% Positive images folder
imDir = 'C:\Users\MATLAB\Photos\Training\Positive';
addpath(imDir);
% Negative images folder
negativeFolder = 'C:\Users\MATLAB\Photos\Training\Negative';
trainCascadeObjectDetector (train image):
trainCascadeObjectDetector('output.xml',data,...
negativeFolder,'FalseAlarmRate',0.2,'NumCascadeStages',15,...
'TruePositiveRate',0.995,'FeatureType','Haar');
What kind of objects are you trying to detect? What do your negative images look like?
In the mean time try increasing the FalseAlarmRate to 0.5. If that doesn't work, try decreasing the NegativeSamplesFactor to 1.5.
Also note that there is difference between "negative samples" and "negative images". What you are providing to the function are negative images, which should be large. The function generates the negative samples automatically from the negative images.
I am trying to detect wheelchairs. My negative images are background of hospitals without any wheelchairs.
If I were to increase my FalseAlarmRate to 0.5, wouldn't it have a higher false positive?
I would think detecting wheelchairs would be hard... You may have to train multiple detectors (side view, front view, etc.).
Increasing FalseAlarmRate is ok, as long as you have enough stages. If FalseAlarmRate is .5, then after two stages the overall false positive rate will be 1/4. After 3 stages it will be 1/8, and so on.
Alright but how do I combine multiple detectors into one if I have split my images and trained them into sub-categories?
You would have to run each detector separately.
Hmmm.. So I cannot combine both set of detector codes into one program to run? I have to run 2 different files separately at each time for the detection?
You would need to train two separate detectors, and get two separate XML files. Then you would need to create two separate vision.CascadeObjectDetector objects, and run each one on your image. You can certainly have two detector objects in the same program (or function).

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!