Skip to content

Commit 33ef3e6

Browse files
author
Maxim Pashchenkov
authored
G-API: Adding anti spoofing scenario for IFD-GAPI (#2959)
* IFD spoof scenario + fixed README * Removed extra line * Returned comma visualization * Added network to cases.py
1 parent 14224d1 commit 33ef3e6

File tree

10 files changed

+127
-57
lines changed

10 files changed

+127
-57
lines changed

demos/interactive_face_detection_demo/cpp/detectors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ InferenceEngine::CNNNetwork AntispoofingClassifier::read(const InferenceEngine::
339339
// ---------------------------Check outputs ------------------------------------------------------------
340340
InferenceEngine::OutputsDataMap outputInfo(network.getOutputsInfo());
341341
if (outputInfo.size() != 1) {
342-
throw std::logic_error("Antispoofing Classifier network should have one output layers");
342+
throw std::logic_error("Antispoofing Classifier network should have one output layer");
343343
}
344344
auto it = outputInfo.begin();
345345

demos/interactive_face_detection_demo/cpp_gapi/README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
# G-API Interactive Face Detection Demo
22

3+
![example](../interactive_face_detection.gif)
4+
35
This demo showcases Object Detection task applied for face recognition using sequence of neural networks.
46
The pipeline is based on [G-API framework](https://docs.opencv.org/master/d0/d1e/gapi.html). This demo executes six [kernels](https://docs.opencv.org/master/d0/d25/gapi_kernel_api.html), five of them infer networks and another one is a postprocessing kernel.
5-
This demo executes the Face Detection, Age/Gender Recognition, Head Pose Estimation, Emotions Recognition, and Facial Landmarks Detection networks. You can use a set of the following pre-trained models with the demo:
7+
This demo executes the Face Detection, Age/Gender Recognition, Head Pose Estimation, Emotions Recognition, Facial Landmarks Detection and Antispoofing Classifier networks. You can use a set of the following pre-trained models with the demo:
68

79
* `face-detection-adas-0001`, which is a primary detection network for finding faces
810
* `age-gender-recognition-retail-0013`, which is executed on top of the results of the first model and reports estimated age and gender for each detected face
911
* `head-pose-estimation-adas-0001`, which is executed on top of the results of the first model and reports estimated head pose in Tait-Bryan angles
1012
* `emotions-recognition-retail-0003`, which is executed on top of the results of the first model and reports an emotion for each detected face
1113
* `facial-landmarks-35-adas-0002`, which is executed on top of the results of the first model and reports normed coordinates of estimated facial landmarks
14+
* `anti-spoof-mn3`, which is executed on top of the results of the first model and reports estimated probability whether spoof or real face is shown
1215

1316
Other demo objectives are:
1417

18+
* Video as input support via OpenCV\*
1519
* Visualization of the resulting face bounding boxes from Face Detection network
16-
* Visualization of age/gender, head pose, emotion information, and facial landmarks positions for each detected face
20+
* Visualization of age/gender, spoof/real, head pose, emotion information, and facial landmarks positions for each detected face
1721

1822
OpenCV is used to draw resulting bounding boxes, labels, and other information. You can copy and paste this code without pulling Inference Engine demo helpers into your application.
1923

@@ -24,7 +28,7 @@ Engine.
2428
2. G-API pipeline gets a video/image/camera like a source, using the OpenCV VideoCapture.
2529
3. G-API pipeline performs inference on the Face Detection network.
2630
4. G-API pipeline runs post processing kernel.
27-
5. G-API pipeline performs four inferences, using the Age/Gender, Head Pose, Emotions, and Facial Landmarks detection networks if they are specified in the command line.
31+
5. G-API pipeline performs four inferences, using the Age/Gender, Head Pose, Emotions, Facial Landmarks detection and Anti-spoof detection networks if they are specified in the command line.
2832
6. The application displays the results.
2933

3034
> **NOTE**: By default, Open Model Zoo demos expect input with BGR channels order. If you trained your model to work with RGB order, you need to manually rearrange the default channels order in the demo application or reconvert your model using the Model Optimizer tool with the `--reverse_input_channels` argument specified. For more information about the argument, refer to **When to Reverse Input Channels** section of [Converting a Model Using General Conversion Parameters](https://docs.openvino.ai/latest/openvino_docs_MO_DG_prepare_model_convert_model_Converting_Model.html#general-conversion-parameters).
@@ -50,6 +54,7 @@ omz_converter --list models.lst
5054
### Supported Models
5155

5256
* age-gender-recognition-retail-0013
57+
* anti-spoof-mn3
5358
* emotions-recognition-retail-0003
5459
* face-detection-adas-0001
5560
* face-detection-retail-0004
@@ -77,11 +82,13 @@ Options:
7782
-m_hp "<path>" Optional. Path to an .xml file with a trained Head Pose Estimation model.
7883
-m_em "<path>" Optional. Path to an .xml file with a trained Emotions Recognition model.
7984
-m_lm "<path>" Optional. Path to an .xml file with a trained Facial Landmarks Estimation model.
85+
-m_am "<path>" Optional. Path to an .xml file with a trained Antispoofing Classification model.
8086
-d "<device>" Optional. Target device for Face Detection network (the list of available devices is shown below). Default value is CPU. The demo will look for a suitable plugin for a specified device.
8187
-d_ag "<device>" Optional. Target device for Age/Gender Recognition network (the list of available devices is shown below). Default value is CPU. The demo will look for a suitable plugin for a specified device.
8288
-d_hp "<device>" Optional. Target device for Head Pose Estimation network (the list of available devices is shown below). Default value is CPU. The demo will look for a suitable plugin for a specified device.
8389
-d_em "<device>" Optional. Target device for Emotions Recognition network (the list of available devices is shown below). Default value is CPU. The demo will look for a suitable plugin for a specified device.
8490
-d_lm "<device>" Optional. Target device for Facial Landmarks Estimation network (the list of available devices is shown below). Default value is CPU. The demo will look for a suitable plugin for device specified.
91+
-d_am "<device>" Optional. Target device for Antispoofing Classification network (the list of available devices is shown below). Default value is CPU. Use "-d HETERO:<comma-separated_devices_list>" format to specify HETERO plugin. The demo will look for a suitable plugin for a specified device.
8592
-no_show Optional. Don't show output.
8693
-r Optional. Output inference results as raw values
8794
-t Optional. Probability threshold for detections
@@ -106,7 +113,8 @@ For example, to do inference on a GPU with the OpenVINO&trade; toolkit pre-train
106113
-m_ag <path_to_model>/age-gender-recognition-retail-0013.xml \
107114
-m_hp <path_to_model>/head-pose-estimation-adas-0001.xml \
108115
-m_em <path_to_model>/emotions-recognition-retail-0003.xml \
109-
-m_lm <path_to_model>/facial-landmarks-35-adas-0002.xml
116+
-m_lm <path_to_model>/facial-landmarks-35-adas-0002.xml \
117+
-m_am <path_to_model>/anti-spoof-mn3.xml
110118
```
111119

112120
>**NOTE**: If you provide a single image as an input, the demo processes and renders it quickly, then exits. To continuously visualize inference results on the screen, apply the `loop` option, which enforces processing a single image in a loop.

demos/interactive_face_detection_demo/cpp_gapi/face.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ void Face::updateLandmarks(std::vector<float> values) {
4343
_landmarks = std::move(values);
4444
}
4545

46+
void Face::updateRealFaceConfidence(float value) {
47+
_realFaceConfidence = value;
48+
}
49+
4650
int Face::getAge() {
4751
return static_cast<int>(std::floor(_age + 0.5f));
4852
}
@@ -51,6 +55,10 @@ bool Face::isMale() {
5155
return _maleScore > _femaleScore;
5256
}
5357

58+
bool Face::isReal() {
59+
return _realFaceConfidence > 50.f;
60+
}
61+
5462
std::map<std::string, float> Face::getEmotions() {
5563
return _emotions;
5664
}

demos/interactive_face_detection_demo/cpp_gapi/face.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ struct Face {
2222
void updateEmotions(const std::map<std::string, float>& values);
2323
void updateHeadPose(float y, float p, float r);
2424
void updateLandmarks(std::vector<float> values);
25+
void updateRealFaceConfidence(float value);
2526

2627
int getAge();
2728
bool isMale();
29+
bool isReal();
2830
std::map<std::string, float> getEmotions();
2931
std::pair<std::string, float> getMainEmotion();
3032
const std::vector<float>& getLandmarks();
@@ -43,7 +45,8 @@ struct Face {
4345
float _pitch;
4446
float _roll;
4547
std::vector<float> _landmarks;
48+
float _realFaceConfidence;
4649
};
4750

48-
// ----------------------------------- Utils -----------------------------------------------------------------
51+
// ----------------- Utils -----------------
4952
Face::Ptr matchFace(cv::Rect rect, const std::list<Face::Ptr>& faces);

demos/interactive_face_detection_demo/cpp_gapi/interactive_face_detection_gapi.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ static const char age_gender_model_message[] = "Optional. Path to an .xml file w
1616
static const char head_pose_model_message[] = "Optional. Path to an .xml file with a trained Head Pose Estimation model.";
1717
static const char emotions_model_message[] = "Optional. Path to an .xml file with a trained Emotions Recognition model.";
1818
static const char facial_landmarks_model_message[] = "Optional. Path to an .xml file with a trained Facial Landmarks Estimation model.";
19+
static const char antispoofing_model_message[] = "Optional. Path to an .xml file with a trained Antispoofing Classification model.";
1920
static const char target_device_message[] = "Optional. Target device for Face Detection network (the list of available devices is shown below). "
2021
"Default value is CPU. The demo will look for a suitable plugin for a specified device.";
2122
static const char target_device_message_ag[] = "Optional. Target device for Age/Gender Recognition network (the list of available devices is shown below). "
@@ -26,6 +27,9 @@ static const char target_device_message_em[] = "Optional. Target device for Emot
2627
"Default value is CPU. The demo will look for a suitable plugin for a specified device.";
2728
static const char target_device_message_lm[] = "Optional. Target device for Facial Landmarks Estimation network "
2829
"(the list of available devices is shown below). Default value is CPU. The demo will look for a suitable plugin for device specified.";
30+
static const char target_device_message_am[] = "Optional. Target device for Antispoofing Classification network (the list of available devices is shown below). "
31+
"Default value is CPU. Use \"-d HETERO:<comma-separated_devices_list>\" format to specify HETERO plugin. "
32+
"The demo will look for a suitable plugin for a specified device.";
2933
static const char thresh_output_message[] = "Optional. Probability threshold for detections";
3034
static const char bb_enlarge_coef_output_message[] = "Optional. Coefficient to enlarge/reduce the size of the bounding box around the detected face";
3135
static const char raw_output_message[] = "Optional. Output inference results as raw values";
@@ -59,11 +63,13 @@ DEFINE_string(m_ag, "", age_gender_model_message);
5963
DEFINE_string(m_hp, "", head_pose_model_message);
6064
DEFINE_string(m_em, "", emotions_model_message);
6165
DEFINE_string(m_lm, "", facial_landmarks_model_message);
66+
DEFINE_string(m_am, "", antispoofing_model_message);
6267
DEFINE_string(d, "CPU", target_device_message);
6368
DEFINE_string(d_ag, "CPU", target_device_message_ag);
6469
DEFINE_string(d_hp, "CPU", target_device_message_hp);
6570
DEFINE_string(d_em, "CPU", target_device_message_em);
6671
DEFINE_string(d_lm, "CPU", target_device_message_lm);
72+
DEFINE_string(d_am, "CPU", target_device_message_am);
6773
DEFINE_bool(r, false, raw_output_message);
6874
DEFINE_double(t, 0.5, thresh_output_message);
6975
DEFINE_double(bb_enlarge_coef, 1.2, bb_enlarge_coef_output_message);
@@ -93,11 +99,13 @@ static void showUsage() {
9399
std::cout << " -m_hp \"<path>\" " << head_pose_model_message << std::endl;
94100
std::cout << " -m_em \"<path>\" " << emotions_model_message << std::endl;
95101
std::cout << " -m_lm \"<path>\" " << facial_landmarks_model_message << std::endl;
102+
std::cout << " -m_am \"<path>\" " << antispoofing_model_message << std::endl;
96103
std::cout << " -d \"<device>\" " << target_device_message << std::endl;
97104
std::cout << " -d_ag \"<device>\" " << target_device_message_ag << std::endl;
98105
std::cout << " -d_hp \"<device>\" " << target_device_message_hp << std::endl;
99106
std::cout << " -d_em \"<device>\" " << target_device_message_em << std::endl;
100107
std::cout << " -d_lm \"<device>\" " << target_device_message_lm << std::endl;
108+
std::cout << " -d_am \"<device>\" " << target_device_message_am << std::endl;
101109
std::cout << " -no_show " << no_show_message << std::endl;
102110
std::cout << " -r " << raw_output_message << std::endl;
103111
std::cout << " -t " << thresh_output_message << std::endl;

0 commit comments

Comments
 (0)