Spaces:
Sleeping
Sleeping
File size: 2,021 Bytes
1264129 e0b9fee 1264129 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
import gradio as gr
import subprocess
import json
import os
from PIL import Image
darknetpath = os.path.join(os.path.dirname(__file__), "darknet")
darknet_executable = os.path.join(darknetpath, "darknet")
modelpath = os.path.join(os.path.dirname(__file__), "yolo-lightnet")
models = {}
modellist = []
def init():
subprocess.run(
"make",
cwd=darknetpath,
)
# subprocess.run(
# "git lfs install",
# cwd=modelpath,
# )
# subprocess.run(
# "git lfs pull",
# cwd=modelpath,
# )
global models
models = json.load(open(os.path.join(modelpath, "path.json")))
global modellist
modellist = list(models.keys())
def darknet_command(model, img, thresh=0.25):
return [
darknet_executable,
"detector",
"test",
model["data"],
model["cfg"],
model["weights"],
img,
"-thresh",
str(thresh),
]
def predict(model, img):
input_path = os.path.join(modelpath, "input.jpg")
output_path = os.path.join(modelpath, "predictions.jpg")
img.save(input_path)
model = models[model]["640x640"]
command = darknet_command(model, input_path)
subprocess.run(command, cwd=modelpath)
return Image.open(output_path)
if __name__ == "__main__":
init()
iface = gr.Interface(
predict,
inputs=[
gr.Dropdown(modellist, label="Model"),
gr.Image(type="pil", label="Input Image"),
],
outputs=gr.Image(type="pil", label="Output Image"),
title="Yolo-lightnet",
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.",
# examples=[
# [
# "driving",
# "car.jpg",
# ],
# [
# "head_body",
# "human.jpg",
# ],
# ],
)
iface.launch()
|