Spaces:
Runtime error
Runtime error
isLinXu
commited on
Commit
·
f56f5db
1
Parent(s):
dfeb85d
update
Browse files- app.py +67 -0
- requirements.txt +22 -0
app.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import os
|
3 |
+
os.system("pip install mmcv-full==1.7.0")
|
4 |
+
os.system("pip install tensorflow")
|
5 |
+
os.system("pip install modelscope")
|
6 |
+
|
7 |
+
import cv2
|
8 |
+
import gradio as gr
|
9 |
+
import numpy as np
|
10 |
+
import PIL.Image as Image
|
11 |
+
import torch
|
12 |
+
from modelscope.pipelines import pipeline
|
13 |
+
from modelscope.utils.constant import Tasks
|
14 |
+
from modelscope.utils.cv.image_utils import draw_face_detection_result
|
15 |
+
from modelscope.preprocessors.image import LoadImage
|
16 |
+
|
17 |
+
import warnings
|
18 |
+
|
19 |
+
warnings.filterwarnings("ignore")
|
20 |
+
|
21 |
+
|
22 |
+
# 定义推理函数
|
23 |
+
def detect_faces(img_pil, model_name):
|
24 |
+
# 定义模型
|
25 |
+
face_detection = pipeline(task=Tasks.face_detection, model='damo/cv_ddsar_face-detection_iclr23-damofd')
|
26 |
+
img_dir = "input_img.jpg"
|
27 |
+
img_pil.save(img_dir)
|
28 |
+
# 进行人脸检测
|
29 |
+
result = face_detection(img_dir)
|
30 |
+
# 可视化结果
|
31 |
+
img_cv = draw_face_detection_result(img_dir, result)
|
32 |
+
# 将结果转换为 Gradio 的输出格式
|
33 |
+
img_out_pil = Image.fromarray(cv2.cvtColor(img_cv, cv2.COLOR_BGR2RGB))
|
34 |
+
return img_out_pil
|
35 |
+
|
36 |
+
def download_test_image():
|
37 |
+
# Images
|
38 |
+
torch.hub.download_url_to_file(
|
39 |
+
'https://user-images.githubusercontent.com/59380685/269160118-91a4a758-1ee0-47a3-a873-28bfd8c24a7f.jpg',
|
40 |
+
'faces.jpg')
|
41 |
+
torch.hub.download_url_to_file(
|
42 |
+
'https://user-images.githubusercontent.com/59380685/269160674-bbf4af8b-a5f1-4754-a272-fd7d278050a3.jpg',
|
43 |
+
'000000000110.jpg')
|
44 |
+
|
45 |
+
|
46 |
+
easyface_model_list = ['damo/cv_ddsar_face-detection_iclr23-damofd',
|
47 |
+
'damo/cv_resnet101_face-detection_cvpr22papermogface',
|
48 |
+
'damo/cv_resnet50_face-detection_retinaface',
|
49 |
+
'damo/cv_manual_face-detection_mtcnn']
|
50 |
+
|
51 |
+
if __name__ == '__main__':
|
52 |
+
download_test_image()
|
53 |
+
# 定义输入和输出
|
54 |
+
inputs = gr.inputs.Image(type='pil', label="input")
|
55 |
+
model_name = gr.inputs.Dropdown(choices=easyface_model_list, label="model list",
|
56 |
+
default="damo/cv_ddsar_face-detection_iclr23-damofd")
|
57 |
+
example = [["faces.jpg", "damo/cv_ddsar_face-detection_iclr23-damofd"],
|
58 |
+
["000000000110.jpg", "damo/cv_manual_face-detection_mtcnn"]]
|
59 |
+
outputs = gr.outputs.Image(type='pil', label="output")
|
60 |
+
title = "EasyFace Web Demo"
|
61 |
+
description = "EasyFace旨在快速选型/了解/对比/体验人脸相关sota模型,依托于Modelscope开发库和Pytorch框架"
|
62 |
+
# 启动 Gradio 应用
|
63 |
+
gr.Interface(fn=detect_faces,
|
64 |
+
inputs=[inputs, model_name],
|
65 |
+
outputs=outputs, title=title,
|
66 |
+
examples=example,
|
67 |
+
description=description).launch()
|
requirements.txt
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
git+https://github.com/facebookresearch/[email protected]#egg=detectron2
|
2 |
+
ultralytics~=8.0.169
|
3 |
+
wget~=3.2
|
4 |
+
opencv-python~=4.6.0.66
|
5 |
+
torch
|
6 |
+
torchvision
|
7 |
+
tensorflow
|
8 |
+
numpy~=1.23.0
|
9 |
+
pillow~=9.4.0
|
10 |
+
gradio~=3.42.0
|
11 |
+
pyyaml~=6.0
|
12 |
+
wandb~=0.13.11
|
13 |
+
tqdm~=4.65.0
|
14 |
+
matplotlib~=3.7.1
|
15 |
+
pandas~=2.0.0
|
16 |
+
seaborn~=0.12.2
|
17 |
+
requests~=2.31.0
|
18 |
+
psutil~=5.9.4
|
19 |
+
thop~=0.1.1-2209072238
|
20 |
+
timm~=0.9.2
|
21 |
+
super-gradients~=3.2.0
|
22 |
+
openmim
|