Update
Browse files- .pre-commit-config.yaml +35 -0
- .style.yapf +5 -0
- README.md +1 -1
- app.py +26 -57
.pre-commit-config.yaml
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
repos:
|
2 |
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
3 |
+
rev: v4.2.0
|
4 |
+
hooks:
|
5 |
+
- id: check-executables-have-shebangs
|
6 |
+
- id: check-json
|
7 |
+
- id: check-merge-conflict
|
8 |
+
- id: check-shebang-scripts-are-executable
|
9 |
+
- id: check-toml
|
10 |
+
- id: check-yaml
|
11 |
+
- id: double-quote-string-fixer
|
12 |
+
- id: end-of-file-fixer
|
13 |
+
- id: mixed-line-ending
|
14 |
+
args: ['--fix=lf']
|
15 |
+
- id: requirements-txt-fixer
|
16 |
+
- id: trailing-whitespace
|
17 |
+
- repo: https://github.com/myint/docformatter
|
18 |
+
rev: v1.4
|
19 |
+
hooks:
|
20 |
+
- id: docformatter
|
21 |
+
args: ['--in-place']
|
22 |
+
- repo: https://github.com/pycqa/isort
|
23 |
+
rev: 5.12.0
|
24 |
+
hooks:
|
25 |
+
- id: isort
|
26 |
+
- repo: https://github.com/pre-commit/mirrors-mypy
|
27 |
+
rev: v0.991
|
28 |
+
hooks:
|
29 |
+
- id: mypy
|
30 |
+
args: ['--ignore-missing-imports']
|
31 |
+
- repo: https://github.com/google/yapf
|
32 |
+
rev: v0.32.0
|
33 |
+
hooks:
|
34 |
+
- id: yapf
|
35 |
+
args: ['--parallel', '--in-place']
|
.style.yapf
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[style]
|
2 |
+
based_on_style = pep8
|
3 |
+
blank_line_before_nested_class_or_def = false
|
4 |
+
spaces_before_comment = 2
|
5 |
+
split_before_logical_operator = true
|
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: 🏢
|
|
4 |
colorFrom: gray
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
4 |
colorFrom: gray
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.19.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
app.py
CHANGED
@@ -2,7 +2,6 @@
|
|
2 |
|
3 |
from __future__ import annotations
|
4 |
|
5 |
-
import argparse
|
6 |
import functools
|
7 |
import os
|
8 |
import pathlib
|
@@ -16,22 +15,8 @@ import onnxruntime as ort
|
|
16 |
|
17 |
TITLE = 'atksh/onnx-facial-lmk-detector'
|
18 |
DESCRIPTION = 'This is an unofficial demo for https://github.com/atksh/onnx-facial-lmk-detector.'
|
19 |
-
ARTICLE = '<center><img src="https://visitor-badge.glitch.me/badge?page_id=hysts.atksh-onnx-facial-lmk-detector" alt="visitor badge"/></center>'
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
def parse_args() -> argparse.Namespace:
|
25 |
-
parser = argparse.ArgumentParser()
|
26 |
-
parser.add_argument('--theme', type=str)
|
27 |
-
parser.add_argument('--live', action='store_true')
|
28 |
-
parser.add_argument('--share', action='store_true')
|
29 |
-
parser.add_argument('--port', type=int)
|
30 |
-
parser.add_argument('--disable-queue',
|
31 |
-
dest='enable_queue',
|
32 |
-
action='store_false')
|
33 |
-
parser.add_argument('--allow-flagging', type=str, default='never')
|
34 |
-
return parser.parse_args()
|
35 |
|
36 |
|
37 |
def load_sample_images() -> list[pathlib.Path]:
|
@@ -44,7 +29,7 @@ def load_sample_images() -> list[pathlib.Path]:
|
|
44 |
path = huggingface_hub.hf_hub_download(dataset_repo,
|
45 |
name,
|
46 |
repo_type='dataset',
|
47 |
-
use_auth_token=
|
48 |
with tarfile.open(path) as f:
|
49 |
f.extractall(image_dir.as_posix())
|
50 |
return sorted(image_dir.rglob('*.jpg'))
|
@@ -66,43 +51,27 @@ def run(image: np.ndarray, sess: ort.InferenceSession) -> np.ndarray:
|
|
66 |
return res[:, :, ::-1], [face[:, :, ::-1] for face in aligned_images]
|
67 |
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
examples=examples,
|
94 |
-
title=TITLE,
|
95 |
-
description=DESCRIPTION,
|
96 |
-
article=ARTICLE,
|
97 |
-
theme=args.theme,
|
98 |
-
allow_flagging=args.allow_flagging,
|
99 |
-
live=args.live,
|
100 |
-
).launch(
|
101 |
-
enable_queue=args.enable_queue,
|
102 |
-
server_port=args.port,
|
103 |
-
share=args.share,
|
104 |
-
)
|
105 |
-
|
106 |
-
|
107 |
-
if __name__ == '__main__':
|
108 |
-
main()
|
2 |
|
3 |
from __future__ import annotations
|
4 |
|
|
|
5 |
import functools
|
6 |
import os
|
7 |
import pathlib
|
15 |
|
16 |
TITLE = 'atksh/onnx-facial-lmk-detector'
|
17 |
DESCRIPTION = 'This is an unofficial demo for https://github.com/atksh/onnx-facial-lmk-detector.'
|
|
|
18 |
|
19 |
+
HF_TOKEN = os.getenv('HF_TOKEN')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
|
22 |
def load_sample_images() -> list[pathlib.Path]:
|
29 |
path = huggingface_hub.hf_hub_download(dataset_repo,
|
30 |
name,
|
31 |
repo_type='dataset',
|
32 |
+
use_auth_token=HF_TOKEN)
|
33 |
with tarfile.open(path) as f:
|
34 |
f.extractall(image_dir.as_posix())
|
35 |
return sorted(image_dir.rglob('*.jpg'))
|
51 |
return res[:, :, ::-1], [face[:, :, ::-1] for face in aligned_images]
|
52 |
|
53 |
|
54 |
+
options = ort.SessionOptions()
|
55 |
+
options.intra_op_num_threads = 8
|
56 |
+
options.inter_op_num_threads = 8
|
57 |
+
sess = ort.InferenceSession('onnx-facial-lmk-detector/model.onnx',
|
58 |
+
sess_options=options,
|
59 |
+
providers=['CPUExecutionProvider'])
|
60 |
+
|
61 |
+
func = functools.partial(run, sess=sess)
|
62 |
+
|
63 |
+
image_paths = load_sample_images()
|
64 |
+
examples = [['onnx-facial-lmk-detector/input.jpg']] + [[path.as_posix()]
|
65 |
+
for path in image_paths]
|
66 |
+
|
67 |
+
gr.Interface(
|
68 |
+
fn=func,
|
69 |
+
inputs=gr.Image(label='Input', type='numpy'),
|
70 |
+
outputs=[
|
71 |
+
gr.Image(label='Output', type='numpy'),
|
72 |
+
gr.Gallery(label='Aligned Faces', type='numpy'),
|
73 |
+
],
|
74 |
+
examples=examples,
|
75 |
+
title=TITLE,
|
76 |
+
description=DESCRIPTION,
|
77 |
+
).queue().launch(show_api=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|