dlib icon indicating copy to clipboard operation
dlib copied to clipboard

fHOG SVM object detector not really scale invariant

Open guenterneust opened this issue 8 years ago • 6 comments

Hi I am trying to detect some simple objects (GPIO header on Raspberry Pi) using the train_object_detector example, pulled and compiled today from the dlib GitHub repository. I prepared a tiny dataset of 4 images downloaded from the internet, expecting the trained detector to be able to detect the objects it was trained on at different scales. But, using the default parameters, if I upsample the trainig set and test the same dataset without upsampling, only two of the four GPIO headers are detected. The other way around, all headers get detected as expected. Is this normal?

guenter@Aspire:~/source/testfhog$ ../dlib/examples/build/train_object_detector -t hdr.xml --flip -u1
Loading image dataset from metadata file hdr.xml
Number of images loaded: 4
Saving trained detector to object_detector.svm
Testing detector on training data...
Test detector (precision,recall,AP): 1 1 1

Parameters used:
threads: 4
C: 1
eps: 0.01
target-size: 6400
detection window width: 203
detection window height: 32
upsample this many times : 1
trained using left/right flips.

guenter@Aspire:~/source/testfhog$ ../dlib/examples/build/train_object_detector --test hdr.xml Loading image dataset from metadata file hdr.xml
Number of images loaded: 4
Testing detector on data...
Results (precision,recall,AP): 1 0.5 0.5

guenter@Aspire:~/source/testfhog$ ../dlib/examples/build/train_object_detector -t hdr.xml --flip Loading image dataset from metadata file hdr.xml
Number of images loaded: 4
Saving trained detector to object_detector.svm
Testing detector on training data... Test detector (precision,recall,AP): 1 1 1

Parameters used: threads: 4 C: 1 eps: 0.01 target-size: 6400 detection window width: 202 detection window height: 32 upsample this many times : 0 trained using left/right flips.

guenter@Aspire:~/source/testfhog$ ../dlib/examples/build/train_object_detector --test hdr.xml -u1 Loading image dataset from metadata file hdr.xml Number of images loaded: 4 Testing detector on data... Results (precision,recall,AP): 1 1 1

testfhog.tar.gz

guenterneust avatar Jan 21 '18 13:01 guenterneust

That's how it works. It's scanning an image pyramid. https://en.wikipedia.org/wiki/Pyramid_(image_processing)

Think about it. It's scanning a fixed sized HOG detector over the pyramid. So if you have objects in your images that are smaller than the HOG detector then it will never find them, unless you upsample the image so that the pyramid will include them at a scale >= the HOG detector size.

davisking avatar Jan 21 '18 14:01 davisking

Of course that objects smaller than the detector size will not be recognized. But this is not the case here - if it would be true, these objects would be rejected as unobtainable when trained without upsampling.

guenterneust avatar Jan 21 '18 15:01 guenterneust

That's true. In that case, you probably just need a little bit more training data.

davisking avatar Jan 21 '18 15:01 davisking

Thank you. I willl probably try to shrink the images in the dataset before training to see if this helps, in order to not have object rectangles which are more than two times bigger than the detector size, because it looks to me like the detector has difficulties to detect objects which are smaller than the rectangles it was trained on. More training data will for sure be provided, but I also want to get the most out of the data available. Anyway, thank you for this great library, it's the best I could find.

guenterneust avatar Jan 21 '18 19:01 guenterneust

It doesn't matter that they are smaller than they were trained on. What's going to happen if you train on big objects is that the detector will find an appropriately sized version of the object in the image pyramid and train on that. What is "appropriate" depends on the size of the detection window you configured. With a very small dataset you might just get unlucky and the best pyramid layer corresponds to the objects being slightly larger (since there isn't an infinite gradation of sizes in the pyramid).

In any case, more training data is the solution.

And thanks, glad you like dlib :)

davisking avatar Jan 21 '18 22:01 davisking

You are probably right, but I'll try anyway. Even if it's not helping detection performance, I think it will make training faster, as training time gets longer when the dataset is upsampled. My suspicion came from the fact that I tried 4 different scales when the image was shrunken compared to the training dataset, but still larger than the detector size, and 2 different detector sizes, and encountered unreliable recognition with these images (using a program derived from the example, with finer scale control), before I went back to the original dlib example and encountered the same behaviour. Of course, 4 images, even mirrored horizontally and vertically, are a very limited dataset.

guenterneust avatar Jan 21 '18 22:01 guenterneust