Saad0KH commited on
Commit
c4af530
·
verified ·
1 Parent(s): 2c61af9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -7
app.py CHANGED
@@ -11,7 +11,6 @@ from PIL import Image
11
  TITLE = "insightface Person Detection"
12
  DESCRIPTION = "https://github.com/deepinsight/insightface/tree/master/examples/person_detection"
13
 
14
-
15
  def load_model():
16
  path = huggingface_hub.hf_hub_download("public-data/insightface", "models/scrfd_person_2.5g.onnx")
17
  options = ort.SessionOptions()
@@ -23,7 +22,6 @@ def load_model():
23
  model = insightface.model_zoo.retinaface.RetinaFace(model_file=path, session=session)
24
  return model
25
 
26
-
27
  def detect_person(
28
  img: np.ndarray, detector: insightface.model_zoo.retinaface.RetinaFace
29
  ) -> tuple[np.ndarray, np.ndarray]:
@@ -39,7 +37,6 @@ def detect_person(
39
  vbboxes[:, 3] = kpss[:, 4, 1]
40
  return bboxes, vbboxes
41
 
42
-
43
  def visualize(image: np.ndarray, bboxes: np.ndarray, vbboxes: np.ndarray) -> np.ndarray:
44
  res = image.copy()
45
  for i in range(bboxes.shape[0]):
@@ -58,7 +55,6 @@ def visualize(image: np.ndarray, bboxes: np.ndarray, vbboxes: np.ndarray) -> np.
58
  cv2.circle(res, (vx2, vy2), 1, color, 2)
59
  return res
60
 
61
-
62
  def extract_persons(image: np.ndarray, bboxes: np.ndarray) -> list[Image.Image]:
63
  person_images = []
64
  for bbox in bboxes:
@@ -68,11 +64,9 @@ def extract_persons(image: np.ndarray, bboxes: np.ndarray) -> list[Image.Image]:
68
  person_images.append(person_pil_image)
69
  return person_images
70
 
71
-
72
  detector = load_model()
73
  detector.prepare(-1, nms_thresh=0.5, input_size=(640, 640))
74
 
75
-
76
  def detect(image: np.ndarray) -> tuple[Image.Image, list[Image.Image]]:
77
  image = image[:, :, ::-1] # RGB -> BGR
78
  bboxes, vbboxes = detect_person(image, detector)
@@ -80,7 +74,6 @@ def detect(image: np.ndarray) -> tuple[Image.Image, list[Image.Image]]:
80
  person_images = extract_persons(res, bboxes)
81
  return Image.fromarray(res[:, :, ::-1], 'RGB'), person_images # BGR -> RGB
82
 
83
-
84
  examples = sorted(pathlib.Path("images").glob("*.jpg"))
85
 
86
  demo = gr.Interface(
 
11
  TITLE = "insightface Person Detection"
12
  DESCRIPTION = "https://github.com/deepinsight/insightface/tree/master/examples/person_detection"
13
 
 
14
  def load_model():
15
  path = huggingface_hub.hf_hub_download("public-data/insightface", "models/scrfd_person_2.5g.onnx")
16
  options = ort.SessionOptions()
 
22
  model = insightface.model_zoo.retinaface.RetinaFace(model_file=path, session=session)
23
  return model
24
 
 
25
  def detect_person(
26
  img: np.ndarray, detector: insightface.model_zoo.retinaface.RetinaFace
27
  ) -> tuple[np.ndarray, np.ndarray]:
 
37
  vbboxes[:, 3] = kpss[:, 4, 1]
38
  return bboxes, vbboxes
39
 
 
40
  def visualize(image: np.ndarray, bboxes: np.ndarray, vbboxes: np.ndarray) -> np.ndarray:
41
  res = image.copy()
42
  for i in range(bboxes.shape[0]):
 
55
  cv2.circle(res, (vx2, vy2), 1, color, 2)
56
  return res
57
 
 
58
  def extract_persons(image: np.ndarray, bboxes: np.ndarray) -> list[Image.Image]:
59
  person_images = []
60
  for bbox in bboxes:
 
64
  person_images.append(person_pil_image)
65
  return person_images
66
 
 
67
  detector = load_model()
68
  detector.prepare(-1, nms_thresh=0.5, input_size=(640, 640))
69
 
 
70
  def detect(image: np.ndarray) -> tuple[Image.Image, list[Image.Image]]:
71
  image = image[:, :, ::-1] # RGB -> BGR
72
  bboxes, vbboxes = detect_person(image, detector)
 
74
  person_images = extract_persons(res, bboxes)
75
  return Image.fromarray(res[:, :, ::-1], 'RGB'), person_images # BGR -> RGB
76
 
 
77
  examples = sorted(pathlib.Path("images").glob("*.jpg"))
78
 
79
  demo = gr.Interface(