Spaces:
Sleeping
Sleeping
yunkai1841
commited on
Commit
·
1264129
1
Parent(s):
82f15f4
deploy app
Browse files- .gitignore +2 -0
- app.py +72 -0
- packages.txt +1 -0
- requirements.txt +0 -0
- yolo-lightnet +1 -1
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
*.jpg
|
2 |
+
.vscode/
|
app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import subprocess
|
3 |
+
import json
|
4 |
+
import os
|
5 |
+
from PIL import Image
|
6 |
+
|
7 |
+
darknetpath = os.path.join(os.path.dirname(__file__), "darknet")
|
8 |
+
darknet_executable = os.path.join(darknetpath, "darknet")
|
9 |
+
|
10 |
+
modelpath = os.path.join(os.path.dirname(__file__), "yolo-lightnet")
|
11 |
+
models = {}
|
12 |
+
modellist = []
|
13 |
+
|
14 |
+
|
15 |
+
def init():
|
16 |
+
subprocess.run(
|
17 |
+
"make",
|
18 |
+
cwd=darknetpath,
|
19 |
+
)
|
20 |
+
global models
|
21 |
+
models = json.load(open(os.path.join(modelpath, "path.json")))
|
22 |
+
global modellist
|
23 |
+
modellist = list(models.keys())
|
24 |
+
|
25 |
+
|
26 |
+
def darknet_command(model, img, thresh=0.25):
|
27 |
+
return [
|
28 |
+
darknet_executable,
|
29 |
+
"detector",
|
30 |
+
"test",
|
31 |
+
model["data"],
|
32 |
+
model["cfg"],
|
33 |
+
model["weights"],
|
34 |
+
img,
|
35 |
+
"-thresh",
|
36 |
+
str(thresh),
|
37 |
+
]
|
38 |
+
|
39 |
+
|
40 |
+
def predict(model, img):
|
41 |
+
input_path = os.path.join(modelpath, "input.jpg")
|
42 |
+
output_path = os.path.join(modelpath, "predictions.jpg")
|
43 |
+
img.save(input_path)
|
44 |
+
model = models[model]["640x640"]
|
45 |
+
command = darknet_command(model, input_path)
|
46 |
+
subprocess.run(command, cwd=modelpath)
|
47 |
+
return Image.open(output_path)
|
48 |
+
|
49 |
+
|
50 |
+
if __name__ == "__main__":
|
51 |
+
init()
|
52 |
+
iface = gr.Interface(
|
53 |
+
predict,
|
54 |
+
inputs=[
|
55 |
+
gr.Dropdown(modellist, label="Model"),
|
56 |
+
gr.Image(type="pil", label="Input Image"),
|
57 |
+
],
|
58 |
+
outputs=gr.Image(type="pil", label="Output Image"),
|
59 |
+
title="Yolo-lightnet",
|
60 |
+
description="Yolo-lightnet is a lightweight version of Yolo. It removes the heavy layers of Yolo and replaces them with lightweight layers. This makes it faster and more efficient.",
|
61 |
+
# examples=[
|
62 |
+
# [
|
63 |
+
# "driving",
|
64 |
+
# "car.jpg",
|
65 |
+
# ],
|
66 |
+
# [
|
67 |
+
# "head_body",
|
68 |
+
# "human.jpg",
|
69 |
+
# ],
|
70 |
+
# ],
|
71 |
+
)
|
72 |
+
iface.launch()
|
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
libopencv-dev
|
requirements.txt
ADDED
File without changes
|
yolo-lightnet
CHANGED
@@ -1 +1 @@
|
|
1 |
-
Subproject commit
|
|
|
1 |
+
Subproject commit 5886db6c8f20940ef9219a105272bc9f1c60c49e
|