ONNX
Satyam Goyal commited on
Commit
c8cb30c
·
1 Parent(s): e91c7ba

Merge pull request #95 from Satgoy152:adding-doc

Browse files

Improved help messages for demo programs (#95)
- Added Demo Documentation
- Updated help messages
- Changed exception link

Files changed (2) hide show
  1. README.md +8 -5
  2. demo.py +8 -8
README.md CHANGED
@@ -3,30 +3,33 @@
3
  SFace: Sigmoid-Constrained Hypersphere Loss for Robust Face Recognition
4
 
5
  Note:
 
6
  - SFace is contributed by [Yaoyao Zhong](https://github.com/zhongyy/SFace).
7
  - [face_recognition_sface_2021sep.onnx](./face_recognition_sface_2021sep.onnx) is converted from the model from https://github.com/zhongyy/SFace thanks to [Chengrui Wang](https://github.com/crywang).
8
  - Support 5-landmark warpping for now (2021sep)
9
 
10
  Results of accuracy evaluation with [tools/eval](../../tools/eval).
11
 
12
- | Models | Accuracy |
13
- |-------------|----------|
14
  | SFace | 0.9940 |
15
  | SFace quant | 0.9932 |
16
 
17
  \*: 'quant' stands for 'quantized'.
18
 
19
-
20
  ## Demo
21
 
22
  ***NOTE***: This demo uses [../face_detection_yunet](../face_detection_yunet) as face detector, which supports 5-landmark detection for now (2021sep).
23
 
24
  Run the following command to try the demo:
 
25
  ```shell
26
  # recognize on images
27
  python demo.py --input1 /path/to/image1 --input2 /path/to/image2
28
- ```
29
 
 
 
 
30
 
31
  ## License
32
 
@@ -35,4 +38,4 @@ All files in this directory are licensed under [Apache 2.0 License](./LICENSE).
35
  ## Reference
36
 
37
  - https://ieeexplore.ieee.org/document/9318547
38
- - https://github.com/zhongyy/SFace
 
3
  SFace: Sigmoid-Constrained Hypersphere Loss for Robust Face Recognition
4
 
5
  Note:
6
+
7
  - SFace is contributed by [Yaoyao Zhong](https://github.com/zhongyy/SFace).
8
  - [face_recognition_sface_2021sep.onnx](./face_recognition_sface_2021sep.onnx) is converted from the model from https://github.com/zhongyy/SFace thanks to [Chengrui Wang](https://github.com/crywang).
9
  - Support 5-landmark warpping for now (2021sep)
10
 
11
  Results of accuracy evaluation with [tools/eval](../../tools/eval).
12
 
13
+ | Models | Accuracy |
14
+ | ----------- | -------- |
15
  | SFace | 0.9940 |
16
  | SFace quant | 0.9932 |
17
 
18
  \*: 'quant' stands for 'quantized'.
19
 
 
20
  ## Demo
21
 
22
  ***NOTE***: This demo uses [../face_detection_yunet](../face_detection_yunet) as face detector, which supports 5-landmark detection for now (2021sep).
23
 
24
  Run the following command to try the demo:
25
+
26
  ```shell
27
  # recognize on images
28
  python demo.py --input1 /path/to/image1 --input2 /path/to/image2
 
29
 
30
+ # get help regarding various parameters
31
+ python demo.py --help
32
+ ```
33
 
34
  ## License
35
 
 
38
  ## Reference
39
 
40
  - https://ieeexplore.ieee.org/document/9318547
41
+ - https://github.com/zhongyy/SFace
demo.py CHANGED
@@ -25,7 +25,7 @@ def str2bool(v):
25
 
26
  backends = [cv.dnn.DNN_BACKEND_OPENCV, cv.dnn.DNN_BACKEND_CUDA]
27
  targets = [cv.dnn.DNN_TARGET_CPU, cv.dnn.DNN_TARGET_CUDA, cv.dnn.DNN_TARGET_CUDA_FP16]
28
- help_msg_backends = "Choose one of the computation backends: {:d}: OpenCV implementation (default); {:d}: CUDA"
29
  help_msg_targets = "Chose one of the target computation devices: {:d}: CPU (default); {:d}: CUDA; {:d}: CUDA fp16"
30
  try:
31
  backends += [cv.dnn.DNN_BACKEND_TIMVX]
@@ -33,18 +33,18 @@ try:
33
  help_msg_backends += "; {:d}: TIMVX"
34
  help_msg_targets += "; {:d}: NPU"
35
  except:
36
- print('This version of OpenCV does not support TIM-VX and NPU. Visit https://gist.github.com/fengyuentau/5a7a5ba36328f2b763aea026c43fa45f for more information.')
37
 
38
  parser = argparse.ArgumentParser(
39
  description="SFace: Sigmoid-Constrained Hypersphere Loss for Robust Face Recognition (https://ieeexplore.ieee.org/document/9318547)")
40
- parser.add_argument('--input1', '-i1', type=str, help='Path to the input image 1.')
41
- parser.add_argument('--input2', '-i2', type=str, help='Path to the input image 2.')
42
- parser.add_argument('--model', '-m', type=str, default='face_recognition_sface_2021dec.onnx', help='Path to the model.')
43
  parser.add_argument('--backend', '-b', type=int, default=backends[0], help=help_msg_backends.format(*backends))
44
  parser.add_argument('--target', '-t', type=int, default=targets[0], help=help_msg_targets.format(*targets))
45
- parser.add_argument('--dis_type', type=int, choices=[0, 1], default=0, help='Distance type. \'0\': cosine, \'1\': norm_l1.')
46
- parser.add_argument('--save', '-s', type=str, default=False, help='Set true to save results. This flag is invalid when using camera.')
47
- parser.add_argument('--vis', '-v', type=str2bool, default=True, help='Set true to open a window for result visualization. This flag is invalid when using camera.')
48
  args = parser.parse_args()
49
 
50
  if __name__ == '__main__':
 
25
 
26
  backends = [cv.dnn.DNN_BACKEND_OPENCV, cv.dnn.DNN_BACKEND_CUDA]
27
  targets = [cv.dnn.DNN_TARGET_CPU, cv.dnn.DNN_TARGET_CUDA, cv.dnn.DNN_TARGET_CUDA_FP16]
28
+ help_msg_backends = "Choose one of the computation backends: {:d}: OpenCV implementation (default); {:d}: CUDA \n Usage: Set backend DNN model, defaults to cv.dnn.DNN_BACKEND_OPENCV (int = 0). Based on your OpenCV version, it may or may not support cv.dnn.DNN_BACKEND_TIMVX. More details: [https://gist.github.com/fengyuentau/5a7a5ba36328f2b763aea026c43fa45f]"
29
  help_msg_targets = "Chose one of the target computation devices: {:d}: CPU (default); {:d}: CUDA; {:d}: CUDA fp16"
30
  try:
31
  backends += [cv.dnn.DNN_BACKEND_TIMVX]
 
33
  help_msg_backends += "; {:d}: TIMVX"
34
  help_msg_targets += "; {:d}: NPU"
35
  except:
36
+ print('This version of OpenCV does not support TIM-VX and NPU. Visit https://github.com/opencv/opencv/wiki/TIM-VX-Backend-For-Running-OpenCV-On-NPU for more information.')
37
 
38
  parser = argparse.ArgumentParser(
39
  description="SFace: Sigmoid-Constrained Hypersphere Loss for Robust Face Recognition (https://ieeexplore.ieee.org/document/9318547)")
40
+ parser.add_argument('--input1', '-i1', type=str, help='Usage: Set path to the input image 1 (original face).')
41
+ parser.add_argument('--input2', '-i2', type=str, help='Usage: Set path to the input image 2 (comparison face).')
42
+ parser.add_argument('--model', '-m', type=str, default='face_recognition_sface_2021dec.onnx', help='Usage: Set model path, defaults to face_recognition_sface_2021dec.onnx.')
43
  parser.add_argument('--backend', '-b', type=int, default=backends[0], help=help_msg_backends.format(*backends))
44
  parser.add_argument('--target', '-t', type=int, default=targets[0], help=help_msg_targets.format(*targets))
45
+ parser.add_argument('--dis_type', type=int, choices=[0, 1], default=0, help='Usage: Distance type. \'0\': cosine, \'1\': norm_l1. Defaults to \'0\'')
46
+ parser.add_argument('--save', '-s', type=str, default=False, help='Usage: Set “True” to save file with results (i.e. bounding box, confidence level). Invalid in case of camera input. Default will be set to “False”.')
47
+ parser.add_argument('--vis', '-v', type=str2bool, default=True, help='Usage: Default will be set to “True” and will open a new window to show results. Set to “False” to stop visualizations from being shown. Invalid in case of camera input.')
48
  args = parser.parse_args()
49
 
50
  if __name__ == '__main__':