File size: 4,197 Bytes
e191f8d d5aedfb e191f8d |
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 82 83 84 85 86 87 88 89 90 91 92 93 94 |
import threading
import gradio as gr
import mtpnet_demo, yolop_demo
def Hex_to_RGB(hex_string):
# your code here
r = int(hex_string[1:3], 16)
g = int(hex_string[3:5], 16)
b = int(hex_string[5:7], 16)
return [r, g, b]
class TaskThread(threading.Thread):
def __init__(self, func, args=()):
super(TaskThread, self).__init__()
self.func = func
self.args = args
def run(self):
self.result = self.func(*self.args)
def getResult(self):
try:
return self.result
except Exception:
return None
def detect(path, model, task, thickness, alpha_da, alpha_ll, color1, color2, color3):
global mtpnet, yolop
color = [Hex_to_RGB(color1), Hex_to_RGB(color2), Hex_to_RGB(color3)]
alpha = [alpha_da, alpha_ll]
result, result2, result3 = None, None, None
if 'mtpnet' in model:
mtpnet = TaskThread(mtpnet_demo.detect, args=(path, task, thickness, color, alpha))
mtpnet.start()
if 'yolop' in model:
yolop = TaskThread(yolop_demo.detect, args=(path, task, thickness, color, alpha))
yolop.start()
if 'mtpnet' in model:
mtpnet.join()
result = mtpnet.getResult()
if 'yolop' in model:
yolop.join()
result2 = yolop.getResult()
return result, result2
gr.Interface(
fn=detect,
inputs=
[
gr.Image(type='filepath', label="Input Image"),
gr.CheckboxGroup(["mtpnet", "yolop"], value=["mtpnet", "yolop"], label="Select model"),
gr.CheckboxGroup(["Vehicle detection", "Driving area segmentation", "Lane detection"],
value=["Vehicle detection", "Driving area segmentation", "Lane detection"],
label="Select task"),
gr.Slider(1, 5, value=2, label="Detection box line thickness", step=1),
gr.Slider(0.1, 1, value=0.5, label="Driving area transparency", step=0.1),
gr.Slider(0.1, 1, value=1, label="Lane Line area transparency", step=0.1),
gr.ColorPicker(label="Detection Box Color", value='#FFFF00'),
gr.ColorPicker(label="Driving Area Segmentation Color", value='#00FF00'),
gr.ColorPicker(label="Lane Line Color", value='#FF0000')
],
outputs=[
gr.Image(label="Output image by mtpnet"),
# gr.Image(label="Output Image by yolopv2"),
gr.Image(label="Output image by yolop")
],
title="MtpNet ๐ช",
examples=
[
["img/1.jpg", ["mtpnet", "yolop"], ["Vehicle detection", "Driving area segmentation", "Lane detection"], 2, 0.5, 1, '#FFFF00', '#00FF00', '#FF0000'],
["img/12.png", ["mtpnet", "yolop"], ["Vehicle detection", "Driving area segmentation", "Lane detection"], 2, 0.5, 1, '#FFFF00', '#00FF00', '#FF0000'],
["img/2.jpg", ["mtpnet", "yolop"], ["Vehicle detection", "Driving area segmentation", "Lane detection"], 2, 0.5, 1, '#FFFF00', '#00FF00', '#FF0000'],
["img/3.jpg", ["mtpnet", "yolop"], ["Vehicle detection", "Driving area segmentation", "Lane detection"], 2, 0.5, 1, '#FFFF00', '#00FF00', '#FF0000'],
["img/4.jpg", ["mtpnet", "yolop"], ["Vehicle detection", "Driving area segmentation", "Lane detection"], 2, 0.5, 1, '#FFFF00', '#00FF00', '#FF0000'],
["img/5.jpg", ["mtpnet", "yolop"], ["Vehicle detection", "Driving area segmentation", "Lane detection"], 2, 0.5, 1, '#FFFF00', '#00FF00', '#FF0000'],
["img/7.jpg", ["mtpnet", "yolop"], ["Vehicle detection", "Driving area segmentation", "Lane detection"], 2, 0.5, 1, '#FFFF00', '#00FF00', '#FF0000'],
["img/8.jpg", ["mtpnet", "yolop"], ["Vehicle detection", "Driving area segmentation", "Lane detection"], 2, 0.5, 1, '#FFFF00', '#00FF00', '#FF0000'],
["img/10.jpg", ["mtpnet", "yolop"], ["Vehicle detection", "Driving area segmentation", "Lane detection"], 2, 0.5, 1, '#FFFF00', '#00FF00', '#FF0000'],
["img/11.png", ["mtpnet", "yolop"], ["Vehicle detection", "Driving area segmentation", "Lane detection"], 2, 0.5, 1, '#FFFF00', '#00FF00', '#FF0000'],
],
theme='default',
description="MtpNet ๐ช: demo for multi-task panoptic driving ๐ perception network").launch(share=False)
|