Update
Browse files
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: 🏢
|
|
| 4 |
colorFrom: gray
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
|
|
|
| 4 |
colorFrom: gray
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.36.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
app.py
CHANGED
|
@@ -2,9 +2,6 @@
|
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
-
import functools
|
| 6 |
-
import os
|
| 7 |
-
|
| 8 |
import cv2
|
| 9 |
import gradio as gr
|
| 10 |
import numpy as np
|
|
@@ -12,12 +9,19 @@ import onnxruntime as ort
|
|
| 12 |
|
| 13 |
DESCRIPTION = "# [atksh/onnx-facial-lmk-detector](https://github.com/atksh/onnx-facial-lmk-detector)"
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
def run(image: np.ndarray
|
| 17 |
# float32, int, int, uint8, int, float32
|
| 18 |
# (N,), (N, 4), (N, 5, 2), (N, 224, 224, 3), (N, 106, 2), (N, 2, 3)
|
| 19 |
scores, bboxes, keypoints, aligned_images, landmarks, affine_matrices = sess.run(
|
| 20 |
-
None, {"input": image[:, :, ::-1]}
|
| 21 |
)
|
| 22 |
|
| 23 |
res = image[:, :, ::-1].copy()
|
|
@@ -30,16 +34,7 @@ def run(image: np.ndarray, sess: ort.InferenceSession) -> np.ndarray:
|
|
| 30 |
return res[:, :, ::-1], [face[:, :, ::-1] for face in aligned_images]
|
| 31 |
|
| 32 |
|
| 33 |
-
|
| 34 |
-
options.intra_op_num_threads = 8
|
| 35 |
-
options.inter_op_num_threads = 8
|
| 36 |
-
sess = ort.InferenceSession(
|
| 37 |
-
"onnx-facial-lmk-detector/model.onnx", sess_options=options, providers=["CPUExecutionProvider"]
|
| 38 |
-
)
|
| 39 |
-
|
| 40 |
-
fn = functools.partial(run, sess=sess)
|
| 41 |
-
|
| 42 |
-
examples = [["onnx-facial-lmk-detector/input.jpg"], ["images/pexels-ksenia-chernaya-8535230.jpg"]]
|
| 43 |
|
| 44 |
with gr.Blocks(css="style.css") as demo:
|
| 45 |
gr.Markdown(DESCRIPTION)
|
|
@@ -54,8 +49,14 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 54 |
examples=examples,
|
| 55 |
inputs=image,
|
| 56 |
outputs=[result, gallery],
|
| 57 |
-
fn=
|
| 58 |
-
cache_examples=os.getenv("CACHE_EXAMPLES") == "1",
|
| 59 |
)
|
| 60 |
-
run_button.click(
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
import cv2
|
| 6 |
import gradio as gr
|
| 7 |
import numpy as np
|
|
|
|
| 9 |
|
| 10 |
DESCRIPTION = "# [atksh/onnx-facial-lmk-detector](https://github.com/atksh/onnx-facial-lmk-detector)"
|
| 11 |
|
| 12 |
+
options = ort.SessionOptions()
|
| 13 |
+
options.intra_op_num_threads = 8
|
| 14 |
+
options.inter_op_num_threads = 8
|
| 15 |
+
sess = ort.InferenceSession(
|
| 16 |
+
"onnx-facial-lmk-detector/model.onnx", sess_options=options, providers=["CPUExecutionProvider"]
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
|
| 20 |
+
def run(image: np.ndarray) -> np.ndarray:
|
| 21 |
# float32, int, int, uint8, int, float32
|
| 22 |
# (N,), (N, 4), (N, 5, 2), (N, 224, 224, 3), (N, 106, 2), (N, 2, 3)
|
| 23 |
scores, bboxes, keypoints, aligned_images, landmarks, affine_matrices = sess.run(
|
| 24 |
+
None, {"input": image[:, :, ::-1].copy()}
|
| 25 |
)
|
| 26 |
|
| 27 |
res = image[:, :, ::-1].copy()
|
|
|
|
| 34 |
return res[:, :, ::-1], [face[:, :, ::-1] for face in aligned_images]
|
| 35 |
|
| 36 |
|
| 37 |
+
examples = ["onnx-facial-lmk-detector/input.jpg", "images/pexels-ksenia-chernaya-8535230.jpg"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
with gr.Blocks(css="style.css") as demo:
|
| 40 |
gr.Markdown(DESCRIPTION)
|
|
|
|
| 49 |
examples=examples,
|
| 50 |
inputs=image,
|
| 51 |
outputs=[result, gallery],
|
| 52 |
+
fn=run,
|
|
|
|
| 53 |
)
|
| 54 |
+
run_button.click(
|
| 55 |
+
fn=run,
|
| 56 |
+
inputs=image,
|
| 57 |
+
outputs=[result, gallery],
|
| 58 |
+
api_name="run",
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
if __name__ == "__main__":
|
| 62 |
+
demo.queue(max_size=10).launch()
|
requirements.txt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
-
numpy==1.
|
| 2 |
onnxruntime==1.15.0
|
| 3 |
-
opencv-python-headless==4.
|
|
|
|
| 1 |
+
numpy==1.26.4
|
| 2 |
onnxruntime==1.15.0
|
| 3 |
+
opencv-python-headless==4.10.0.82
|
style.css
CHANGED
|
@@ -1,7 +1,11 @@
|
|
| 1 |
h1 {
|
| 2 |
text-align: center;
|
|
|
|
| 3 |
}
|
| 4 |
|
| 5 |
#duplicate-button {
|
| 6 |
margin: auto;
|
|
|
|
|
|
|
|
|
|
| 7 |
}
|
|
|
|
| 1 |
h1 {
|
| 2 |
text-align: center;
|
| 3 |
+
display: block;
|
| 4 |
}
|
| 5 |
|
| 6 |
#duplicate-button {
|
| 7 |
margin: auto;
|
| 8 |
+
color: #fff;
|
| 9 |
+
background: #1565c0;
|
| 10 |
+
border-radius: 100vh;
|
| 11 |
}
|