Cascade Object Detector: Unable to generate a sufficient number of negative samples
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
1 vote
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
Dima Lisin
on 1 Dec 2015
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
Leonard Yeo
on 2 Dec 2015
Edited: Leonard Yeo
on 2 Dec 2015
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.
Dima Lisin
on 3 Dec 2015
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.
Leonard Yeo
on 10 Dec 2015
Do I include negative image into the Training Image Labeler?
Dima Lisin
on 10 Dec 2015
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');
Dima Lisin
on 10 Dec 2015
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.
Leonard Yeo
on 10 Dec 2015
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?
Dima Lisin
on 10 Dec 2015
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.
Leonard Yeo
on 11 Dec 2015
Alright but how do I combine multiple detectors into one if I have split my images and trained them into sub-categories?
Dima Lisin
on 11 Dec 2015
You would have to run each detector separately.
Leonard Yeo
on 11 Dec 2015
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?
Dima Lisin
on 11 Dec 2015
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).
More Answers (0)
Categories
Find more on Object Detection in Help Center and File Exchange
Products
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)