Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import threading
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
from tools import mtpnet_demo, yolop_demo, yolopv2_demo
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def Hex_to_RGB(hex_string):
|
| 9 |
+
# your code here
|
| 10 |
+
r = int(hex_string[1:3], 16)
|
| 11 |
+
g = int(hex_string[3:5], 16)
|
| 12 |
+
b = int(hex_string[5:7], 16)
|
| 13 |
+
return [r, g, b]
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class TaskThread(threading.Thread):
|
| 17 |
+
def __init__(self, func, args=()):
|
| 18 |
+
super(TaskThread, self).__init__()
|
| 19 |
+
self.func = func
|
| 20 |
+
self.args = args
|
| 21 |
+
|
| 22 |
+
def run(self):
|
| 23 |
+
self.result = self.func(*self.args)
|
| 24 |
+
|
| 25 |
+
def getResult(self):
|
| 26 |
+
try:
|
| 27 |
+
return self.result
|
| 28 |
+
except Exception:
|
| 29 |
+
return None
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def detect(path, model, task, thickness, alpha_da, alpha_ll, color1, color2, color3):
|
| 33 |
+
global mtpnet, yolop
|
| 34 |
+
color = [Hex_to_RGB(color1), Hex_to_RGB(color2), Hex_to_RGB(color3)]
|
| 35 |
+
alpha = [alpha_da, alpha_ll]
|
| 36 |
+
result, result2, result3 = None, None, None
|
| 37 |
+
if 'mtpnet' in model:
|
| 38 |
+
mtpnet = TaskThread(mtpnet_demo.detect, args=(path, task, thickness, color, alpha))
|
| 39 |
+
mtpnet.start()
|
| 40 |
+
|
| 41 |
+
if 'yolop' in model:
|
| 42 |
+
yolop = TaskThread(yolop_demo.detect, args=(path, task, thickness, color, alpha))
|
| 43 |
+
yolop.start()
|
| 44 |
+
|
| 45 |
+
if 'mtpnet' in model:
|
| 46 |
+
mtpnet.join()
|
| 47 |
+
result = mtpnet.getResult()
|
| 48 |
+
|
| 49 |
+
if 'yolop' in model:
|
| 50 |
+
yolop.join()
|
| 51 |
+
result2 = yolop.getResult()
|
| 52 |
+
|
| 53 |
+
# if 'yolopv2' in model:
|
| 54 |
+
# yolopv2 = TaskThread(yolopv2_demo.detect, args=(path, task, thickness, color, alpha))
|
| 55 |
+
# yolopv2.start()
|
| 56 |
+
# yolopv2.join()
|
| 57 |
+
# result3 = yolopv2.getResult()
|
| 58 |
+
|
| 59 |
+
return result, result2
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
gr.Interface(
|
| 63 |
+
fn=detect,
|
| 64 |
+
inputs=
|
| 65 |
+
[
|
| 66 |
+
gr.Image(type='filepath', label="Input Image"),
|
| 67 |
+
gr.CheckboxGroup(["mtpnet", "yolop"], value=["mtpnet", "yolop"], label="Select model"),
|
| 68 |
+
gr.CheckboxGroup(["Vehicle detection", "Driving area segmentation", "Lane detection"],
|
| 69 |
+
value=["Vehicle detection", "Driving area segmentation", "Lane detection"],
|
| 70 |
+
label="Select task"),
|
| 71 |
+
gr.Slider(1, 5, value=2, label="Detection box line thickness", step=1),
|
| 72 |
+
gr.Slider(0.1, 1, value=0.5, label="Driving area transparency", step=0.1),
|
| 73 |
+
gr.Slider(0.1, 1, value=1, label="Lane Line area transparency", step=0.1),
|
| 74 |
+
gr.ColorPicker(label="Detection Box Color", value='#FFFF00'),
|
| 75 |
+
gr.ColorPicker(label="Driving Area Segmentation Color", value='#00FF00'),
|
| 76 |
+
gr.ColorPicker(label="Lane Line Color", value='#FF0000')
|
| 77 |
+
],
|
| 78 |
+
outputs=[
|
| 79 |
+
gr.Image(label="Output image by mtpnet"),
|
| 80 |
+
# gr.Image(label="Output Image by yolopv2"),
|
| 81 |
+
gr.Image(label="Output image by yolop")
|
| 82 |
+
],
|
| 83 |
+
title="MtpNet 💪",
|
| 84 |
+
examples=
|
| 85 |
+
[
|
| 86 |
+
["img/1.jpg", ["mtpnet", "yolop"], ["Vehicle detection", "Driving area segmentation", "Lane detection"], 2, 0.5, 1, '#FFFF00', '#00FF00', '#FF0000'],
|
| 87 |
+
["img/12.png", ["mtpnet", "yolop"], ["Vehicle detection", "Driving area segmentation", "Lane detection"], 2, 0.5, 1, '#FFFF00', '#00FF00', '#FF0000'],
|
| 88 |
+
["img/2.jpg", ["mtpnet", "yolop"], ["Vehicle detection", "Driving area segmentation", "Lane detection"], 2, 0.5, 1, '#FFFF00', '#00FF00', '#FF0000'],
|
| 89 |
+
["img/3.jpg", ["mtpnet", "yolop"], ["Vehicle detection", "Driving area segmentation", "Lane detection"], 2, 0.5, 1, '#FFFF00', '#00FF00', '#FF0000'],
|
| 90 |
+
["img/4.jpg", ["mtpnet", "yolop"], ["Vehicle detection", "Driving area segmentation", "Lane detection"], 2, 0.5, 1, '#FFFF00', '#00FF00', '#FF0000'],
|
| 91 |
+
["img/5.jpg", ["mtpnet", "yolop"], ["Vehicle detection", "Driving area segmentation", "Lane detection"], 2, 0.5, 1, '#FFFF00', '#00FF00', '#FF0000'],
|
| 92 |
+
["img/7.jpg", ["mtpnet", "yolop"], ["Vehicle detection", "Driving area segmentation", "Lane detection"], 2, 0.5, 1, '#FFFF00', '#00FF00', '#FF0000'],
|
| 93 |
+
["img/8.jpg", ["mtpnet", "yolop"], ["Vehicle detection", "Driving area segmentation", "Lane detection"], 2, 0.5, 1, '#FFFF00', '#00FF00', '#FF0000'],
|
| 94 |
+
["img/10.jpg", ["mtpnet", "yolop"], ["Vehicle detection", "Driving area segmentation", "Lane detection"], 2, 0.5, 1, '#FFFF00', '#00FF00', '#FF0000'],
|
| 95 |
+
["img/11.png", ["mtpnet", "yolop"], ["Vehicle detection", "Driving area segmentation", "Lane detection"], 2, 0.5, 1, '#FFFF00', '#00FF00', '#FF0000'],
|
| 96 |
+
|
| 97 |
+
],
|
| 98 |
+
theme='default',
|
| 99 |
+
description="MtpNet 💪: demo for multi-task panoptic driving 🚗 perception network").launch(share=False)
|