Commit 7bc980ed authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #10983 from dkurt:dnn_face_detection_uint8

parents 8c1d8ecc 8d8f3bca
...@@ -17,7 +17,6 @@ parser = argparse.ArgumentParser( ...@@ -17,7 +17,6 @@ parser = argparse.ArgumentParser(
'using COCO evaluation tool, http://cocodataset.org/#detections-eval') 'using COCO evaluation tool, http://cocodataset.org/#detections-eval')
parser.add_argument('--proto', help='Path to .prototxt of Caffe model or .pbtxt of TensorFlow graph') parser.add_argument('--proto', help='Path to .prototxt of Caffe model or .pbtxt of TensorFlow graph')
parser.add_argument('--model', help='Path to .caffemodel trained in Caffe or .pb from TensorFlow') parser.add_argument('--model', help='Path to .caffemodel trained in Caffe or .pb from TensorFlow')
parser.add_argument('--caffe', help='Indicate that tested model is from Caffe. Otherwise model from TensorFlow is expected.', action='store_true')
parser.add_argument('--cascade', help='Optional path to trained Haar cascade as ' parser.add_argument('--cascade', help='Optional path to trained Haar cascade as '
'an additional model for evaluation') 'an additional model for evaluation')
parser.add_argument('--ann', help='Path to text file with ground truth annotations') parser.add_argument('--ann', help='Path to text file with ground truth annotations')
...@@ -141,10 +140,7 @@ with open('annotations.json', 'wt') as f: ...@@ -141,10 +140,7 @@ with open('annotations.json', 'wt') as f:
### Obtain detections ########################################################## ### Obtain detections ##########################################################
detections = [] detections = []
if args.proto and args.model: if args.proto and args.model:
if args.caffe: net = cv.dnn.readNet(args.proto, args.model)
net = cv.dnn.readNetFromCaffe(args.proto, args.model)
else:
net = cv.dnn.readNetFromTensorflow(args.model, args.proto)
def detect(img, imageId): def detect(img, imageId):
imgWidth = img.shape[1] imgWidth = img.shape[1]
......
...@@ -13,23 +13,32 @@ if(NOT BUILD_EXAMPLES OR NOT OCV_DEPENDENCIES_FOUND) ...@@ -13,23 +13,32 @@ if(NOT BUILD_EXAMPLES OR NOT OCV_DEPENDENCIES_FOUND)
return() return()
endif() endif()
# Model branch name: dnn_samples_face_detector_20170830 function(download_net name commit hash)
set(DNN_FACE_DETECTOR_MODEL_COMMIT "b2bfc75f6aea5b1f834ff0f0b865a7c18ff1459f") set(DNN_FACE_DETECTOR_MODEL_DOWNLOAD_DIR "${CMAKE_CURRENT_LIST_DIR}/face_detector")
set(DNN_FACE_DETECTOR_MODEL_HASH "afbb6037fd180e8d2acb3b58ca737b9e") if(COMMAND ocv_download)
set(DNN_FACE_DETECTOR_MODEL_NAME "res10_300x300_ssd_iter_140000.caffemodel") ocv_download(FILENAME ${name}
set(DNN_FACE_DETECTOR_MODEL_DOWNLOAD_DIR "${CMAKE_CURRENT_LIST_DIR}/face_detector") HASH ${hash}
if(COMMAND ocv_download) URL
ocv_download(FILENAME ${DNN_FACE_DETECTOR_MODEL_NAME} "$ENV{OPENCV_DNN_MODELS_URL}"
HASH ${DNN_FACE_DETECTOR_MODEL_HASH} "${OPENCV_DNN_MODELS_URL}"
URL "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${commit}/"
"$ENV{OPENCV_DNN_MODELS_URL}" DESTINATION_DIR ${DNN_FACE_DETECTOR_MODEL_DOWNLOAD_DIR}
"${OPENCV_DNN_MODELS_URL}" ID DNN_FACE_DETECTOR
"https://raw.githubusercontent.com/opencv/opencv_3rdparty/${DNN_FACE_DETECTOR_MODEL_COMMIT}/" RELATIVE_URL
DESTINATION_DIR ${DNN_FACE_DETECTOR_MODEL_DOWNLOAD_DIR} STATUS res)
ID DNN_FACE_DETECTOR endif()
RELATIVE_URL endfunction()
STATUS res)
endif() # Model branch name: dnn_samples_face_detector_20180205_fp16
download_net("res10_300x300_ssd_iter_140000_fp16.caffemodel"
"19512576c112aa2c7b6328cb0e8d589a4a90a26d"
"f737f886e33835410c69e3ccfe0720a1")
# Model branch name: dnn_samples_face_detector_20180220_uint8
download_net("opencv_face_detector_uint8.pb"
"7b425df276ba2161b8edaab0f0756f4a735d61b9"
"56acf81f55d9b9e96c3347bc65409b9e")
project(dnn_samples) project(dnn_samples)
ocv_include_modules_recurse(${OPENCV_DNN_SAMPLES_REQUIRED_DEPS}) ocv_include_modules_recurse(${OPENCV_DNN_SAMPLES_REQUIRED_DEPS})
file(GLOB_RECURSE dnn_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) file(GLOB_RECURSE dnn_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
......
...@@ -14,6 +14,34 @@ ...@@ -14,6 +14,34 @@
| [Faster-RCNN](https://github.com/rbgirshick/py-faster-rcnn) | `1.0` | `800x600` | `102.9801, 115.9465, 122.7717` | BGR | | [Faster-RCNN](https://github.com/rbgirshick/py-faster-rcnn) | `1.0` | `800x600` | `102.9801, 115.9465, 122.7717` | BGR |
| [R-FCN](https://github.com/YuwenXiong/py-R-FCN) | `1.0` | `800x600` | `102.9801 115.9465 122.7717` | BGR | | [R-FCN](https://github.com/YuwenXiong/py-R-FCN) | `1.0` | `800x600` | `102.9801 115.9465 122.7717` | BGR |
#### Face detection
[An origin model](https://github.com/opencv/opencv/tree/master/samples/dnn/face_detector)
with single precision floating point weights has been quantized using [TensorFlow framework](https://www.tensorflow.org/).
To achieve the best accuracy run the model on BGR images resized to `300x300` applying mean subtraction
of values `(104, 177, 123)` for each blue, green and red channels correspondingly.
The following are accuracy metrics obtained using [COCO object detection evaluation
tool](http://cocodataset.org/#detections-eval) on [FDDB dataset](http://vis-www.cs.umass.edu/fddb/)
(see [script](https://github.com/opencv/opencv/blob/master/modules/dnn/misc/face_detector_accuracy.py))
applying resize to `300x300` and keeping an origin images' sizes.
```
AP - Average Precision | FP32/FP16 | UINT8 | FP32/FP16 | UINT8 |
AR - Average Recall | 300x300 | 300x300 | any size | any size |
--------------------------------------------------|-----------|----------------|-----------|----------------|
AP @[ IoU=0.50:0.95 | area= all | maxDets=100 ] | 0.408 | 0.408 | 0.378 | 0.328 (-0.050) |
AP @[ IoU=0.50 | area= all | maxDets=100 ] | 0.849 | 0.849 | 0.797 | 0.790 (-0.007) |
AP @[ IoU=0.75 | area= all | maxDets=100 ] | 0.251 | 0.251 | 0.208 | 0.140 (-0.068) |
AP @[ IoU=0.50:0.95 | area= small | maxDets=100 ] | 0.050 | 0.051 (+0.001) | 0.107 | 0.070 (-0.037) |
AP @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] | 0.381 | 0.379 (-0.002) | 0.380 | 0.368 (-0.012) |
AP @[ IoU=0.50:0.95 | area= large | maxDets=100 ] | 0.455 | 0.455 | 0.412 | 0.337 (-0.075) |
AR @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] | 0.299 | 0.299 | 0.279 | 0.246 (-0.033) |
AR @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] | 0.482 | 0.482 | 0.476 | 0.436 (-0.040) |
AR @[ IoU=0.50:0.95 | area= all | maxDets=100 ] | 0.496 | 0.496 | 0.491 | 0.451 (-0.040) |
AR @[ IoU=0.50:0.95 | area= small | maxDets=100 ] | 0.189 | 0.193 (+0.004) | 0.284 | 0.232 (-0.052) |
AR @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] | 0.481 | 0.480 (-0.001) | 0.470 | 0.458 (-0.012) |
AR @[ IoU=0.50:0.95 | area= large | maxDets=100 ] | 0.528 | 0.528 | 0.520 | 0.462 (-0.058) |
```
### Classification ### Classification
| Model | Scale | Size WxH| Mean subtraction | Channels order | | Model | Scale | Size WxH| Mean subtraction | Channels order |
|---------------|-------|-----------|--------------------|-------| |---------------|-------|-----------|--------------------|-------|
......
This diff is collapsed.
...@@ -70,7 +70,7 @@ function recognize(face) { ...@@ -70,7 +70,7 @@ function recognize(face) {
function loadModels(callback) { function loadModels(callback) {
var utils = new Utils(''); var utils = new Utils('');
var proto = 'https://raw.githubusercontent.com/opencv/opencv/master/samples/dnn/face_detector/deploy.prototxt'; var proto = 'https://raw.githubusercontent.com/opencv/opencv/master/samples/dnn/face_detector/deploy.prototxt';
var weights = 'https://github.com/opencv/opencv_3rdparty/raw/19512576c112aa2c7b6328cb0e8d589a4a90a26d/res10_300x300_ssd_iter_140000_fp16.caffemodel'; var weights = 'https://raw.githubusercontent.com/opencv/opencv_3rdparty/dnn_samples_face_detector_20180205_fp16/res10_300x300_ssd_iter_140000_fp16.caffemodel';
var recognModel = 'https://raw.githubusercontent.com/pyannote/pyannote-data/master/openface.nn4.small2.v1.t7'; var recognModel = 'https://raw.githubusercontent.com/pyannote/pyannote-data/master/openface.nn4.small2.v1.t7';
utils.createFileFromUrl('face_detector.prototxt', proto, () => { utils.createFileFromUrl('face_detector.prototxt', proto, () => {
document.getElementById('status').innerHTML = 'Downloading face_detector.caffemodel'; document.getElementById('status').innerHTML = 'Downloading face_detector.caffemodel';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment