Adding support for cnn face detector

CNN face detector (deep learning face detection) is modeled as
PHP class. Currently, it only has constructor (which loads a model)
and detect() method. I tried to make it resamble to Python implementation.
Similar to Python, also added support for upsampling. Returned value
is array with numbers as keys where number of keys is equal to number
of found faced. Each element is associative array that has "top", "left",
"right", "bottom" and "detection_confidence" keys.

All errors are propagated using exceptions.

Added two new error tests. I didn't want to rely on presence of model,
so tests are not having great coverage. If we are OK to download models
in tests, it would allow us to have far better coverage.

What is missing:
* Testing with models (should we test that?)
* detect_mult method (similar to what Python have; however, I consider
  that this should not block pushing this change)
This commit is contained in:
Branko Kokanovic
2018-07-14 00:12:10 +02:00
parent d12d75c69e
commit f8cc0e48d3
7 changed files with 213 additions and 3 deletions

View File

@@ -0,0 +1,15 @@
--TEST--
Testing CnnFaceDetection constructor without arguments
--SKIPIF--
<?php if (!extension_loaded("pdlib")) print "skip"; ?>
--FILE--
<?php
try {
new CnnFaceDetection();
} catch (Exception $e) {
var_dump($e->getMessage());
}
?>
--EXPECT--
Warning: CnnFaceDetection::__construct() expects exactly 1 parameter, 0 given in /home/branko/pdlib/tests/cnn_face_detection_ctor_error.php on line 3
string(41) "Unable to parse face_detection_model_path"

View File

@@ -0,0 +1,14 @@
--TEST--
Testing CnnFaceDetection constructor with model that do not exist
--SKIPIF--
<?php if (!extension_loaded("pdlib")) print "skip"; ?>
--FILE--
<?php
try {
new CnnFaceDetection("foo");
} catch (Exception $e) {
var_dump($e->getMessage());
}
?>
--EXPECT--
string(31) "Unable to open foo for reading."