Update
Browse files- README.md +1 -1
- app.py +9 -18
- pre-requirements.txt +1 -0
- requirements.txt +3 -5
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: 😻
|
|
4 |
colorFrom: blue
|
5 |
colorTo: yellow
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
|
|
4 |
colorFrom: blue
|
5 |
colorTo: yellow
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.36.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
app.py
CHANGED
@@ -3,13 +3,7 @@
|
|
3 |
from __future__ import annotations
|
4 |
|
5 |
import functools
|
6 |
-
import os
|
7 |
import pathlib
|
8 |
-
import shlex
|
9 |
-
import subprocess
|
10 |
-
|
11 |
-
if os.getenv('SYSTEM') == 'spaces':
|
12 |
-
subprocess.call(shlex.split('pip install insightface==0.6.2'))
|
13 |
|
14 |
import cv2
|
15 |
import gradio as gr
|
@@ -19,15 +13,12 @@ import numpy as np
|
|
19 |
import onnxruntime as ort
|
20 |
|
21 |
TITLE = 'insightface Person Detection'
|
22 |
-
DESCRIPTION = '
|
23 |
-
|
24 |
-
HF_TOKEN = os.getenv('HF_TOKEN')
|
25 |
|
26 |
|
27 |
def load_model():
|
28 |
-
path = huggingface_hub.hf_hub_download('
|
29 |
-
'models/scrfd_person_2.5g.onnx'
|
30 |
-
use_auth_token=HF_TOKEN)
|
31 |
options = ort.SessionOptions()
|
32 |
options.intra_op_num_threads = 8
|
33 |
options.inter_op_num_threads = 8
|
@@ -44,8 +35,8 @@ def detect_person(
|
|
44 |
img: np.ndarray, detector: insightface.model_zoo.retinaface.RetinaFace
|
45 |
) -> tuple[np.ndarray, np.ndarray]:
|
46 |
bboxes, kpss = detector.detect(img)
|
47 |
-
bboxes = np.round(bboxes[:, :4]).astype(
|
48 |
-
kpss = np.round(kpss).astype(
|
49 |
kpss[:, :, 0] = np.clip(kpss[:, :, 0], 0, img.shape[1])
|
50 |
kpss[:, :, 1] = np.clip(kpss[:, :, 1], 0, img.shape[0])
|
51 |
vbboxes = bboxes.copy()
|
@@ -87,17 +78,17 @@ def detect(image: np.ndarray, detector) -> np.ndarray:
|
|
87 |
|
88 |
detector = load_model()
|
89 |
detector.prepare(-1, nms_thresh=0.5, input_size=(640, 640))
|
90 |
-
|
91 |
|
92 |
image_dir = pathlib.Path('images')
|
93 |
examples = [[path.as_posix()] for path in sorted(image_dir.glob('*.jpg'))]
|
94 |
|
95 |
gr.Interface(
|
96 |
-
fn=
|
97 |
inputs=gr.Image(label='Input', type='numpy'),
|
98 |
-
outputs=gr.Image(label='Output',
|
99 |
examples=examples,
|
100 |
examples_per_page=30,
|
101 |
title=TITLE,
|
102 |
description=DESCRIPTION,
|
103 |
-
).launch(
|
|
|
3 |
from __future__ import annotations
|
4 |
|
5 |
import functools
|
|
|
6 |
import pathlib
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
import cv2
|
9 |
import gradio as gr
|
|
|
13 |
import onnxruntime as ort
|
14 |
|
15 |
TITLE = 'insightface Person Detection'
|
16 |
+
DESCRIPTION = 'https://github.com/deepinsight/insightface/tree/master/examples/person_detection'
|
|
|
|
|
17 |
|
18 |
|
19 |
def load_model():
|
20 |
+
path = huggingface_hub.hf_hub_download('public-data/insightface',
|
21 |
+
'models/scrfd_person_2.5g.onnx')
|
|
|
22 |
options = ort.SessionOptions()
|
23 |
options.intra_op_num_threads = 8
|
24 |
options.inter_op_num_threads = 8
|
|
|
35 |
img: np.ndarray, detector: insightface.model_zoo.retinaface.RetinaFace
|
36 |
) -> tuple[np.ndarray, np.ndarray]:
|
37 |
bboxes, kpss = detector.detect(img)
|
38 |
+
bboxes = np.round(bboxes[:, :4]).astype(int)
|
39 |
+
kpss = np.round(kpss).astype(int)
|
40 |
kpss[:, :, 0] = np.clip(kpss[:, :, 0], 0, img.shape[1])
|
41 |
kpss[:, :, 1] = np.clip(kpss[:, :, 1], 0, img.shape[0])
|
42 |
vbboxes = bboxes.copy()
|
|
|
78 |
|
79 |
detector = load_model()
|
80 |
detector.prepare(-1, nms_thresh=0.5, input_size=(640, 640))
|
81 |
+
fn = functools.partial(detect, detector=detector)
|
82 |
|
83 |
image_dir = pathlib.Path('images')
|
84 |
examples = [[path.as_posix()] for path in sorted(image_dir.glob('*.jpg'))]
|
85 |
|
86 |
gr.Interface(
|
87 |
+
fn=fn,
|
88 |
inputs=gr.Image(label='Input', type='numpy'),
|
89 |
+
outputs=gr.Image(label='Output', height=600),
|
90 |
examples=examples,
|
91 |
examples_per_page=30,
|
92 |
title=TITLE,
|
93 |
description=DESCRIPTION,
|
94 |
+
).queue().launch()
|
pre-requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Cython==0.29.36
|
requirements.txt
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
onnxruntime==1.11.0
|
5 |
-
opencv-python-headless==4.5.5.64
|
|
|
1 |
+
insightface==0.7.3
|
2 |
+
onnxruntime==1.15.1
|
3 |
+
opencv-python-headless==4.8.0.74
|
|
|
|