hysts HF staff commited on
Commit
bfe786b
1 Parent(s): 08ba7c3
Files changed (4) hide show
  1. README.md +1 -1
  2. app.py +9 -18
  3. pre-requirements.txt +1 -0
  4. 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.19.1
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 = 'This is an unofficial demo for https://github.com/deepinsight/insightface/tree/master/examples/person_detection.'
23
-
24
- HF_TOKEN = os.getenv('HF_TOKEN')
25
 
26
 
27
  def load_model():
28
- path = huggingface_hub.hf_hub_download('hysts/insightface',
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(np.int)
48
- kpss = np.round(kpss).astype(np.int)
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
- func = functools.partial(detect, detector=detector)
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=func,
97
  inputs=gr.Image(label='Input', type='numpy'),
98
- outputs=gr.Image(label='Output', type='numpy'),
99
  examples=examples,
100
  examples_per_page=30,
101
  title=TITLE,
102
  description=DESCRIPTION,
103
- ).launch(show_api=False)
 
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
- Cython==0.29.28
2
- #insightface==0.6.2
3
- numpy==1.22.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