Skip to content

Commit 4f38b87

Browse files
authored
Gradio Hub Web Demo (#2)
* gradio demo * fix * imports * model path * article * update readme
1 parent ba1e35c commit 4f38b87

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ The notebook supports interactive UI with [Gradio](https://gradio.app/) as below
6060

6161
<img src=".github/gradio_example.png" height="350">
6262

63+
### Gradio Hub Web Demo
64+
[Gradio Web Demo](https://gradio.app/g/AK391/mlsd)
65+
6366
## Citation
6467
If you find *M-LSD* useful in your project, please consider to cite the following paper.
6568

linedemo.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from PIL import Image
2+
import cv2
3+
import numpy as np
4+
import tensorflow as tf
5+
from utils import pred_lines, pred_squares
6+
import gradio as gr
7+
from urllib.request import urlretrieve
8+
9+
10+
# Load MLSD 512 Large FP32 tflite
11+
model_name = 'tflite_models/M-LSD_512_large_fp32.tflite'
12+
interpreter = tf.lite.Interpreter(model_path=model_name)
13+
14+
interpreter.allocate_tensors()
15+
input_details = interpreter.get_input_details()
16+
output_details = interpreter.get_output_details()
17+
18+
def gradio_wrapper_for_LSD(img_input, score_thr, dist_thr):
19+
lines = pred_lines(img_input, interpreter, input_details, output_details, input_shape=[512, 512], score_thr=score_thr, dist_thr=dist_thr)
20+
img_output = img_input.copy()
21+
22+
# draw lines
23+
for line in lines:
24+
x_start, y_start, x_end, y_end = [int(val) for val in line]
25+
cv2.line(img_output, (x_start, y_start), (x_end, y_end), [0,255,255], 2)
26+
27+
return img_output
28+
29+
urlretrieve("https://www.digsdigs.com/photos/2015/05/a-bold-minimalist-living-room-with-dark-stained-wood-geometric-touches-a-sectional-sofa-and-built-in-lights-for-a-futuristic-feel.jpg","example1.jpg")
30+
urlretrieve("https://specials-images.forbesimg.com/imageserve/5dfe2e6925ab5d0007cefda5/960x0.jpg","example2.jpg")
31+
urlretrieve("https://images.livspace-cdn.com/w:768/h:651/plain/https://jumanji.livspace-cdn.com/magazine/wp-content/uploads/2015/11/27170345/atr-1-a-e1577187047515.jpeg","example3.jpg")
32+
sample_images = [["example1.jpg", 0.2, 10.0], ["example2.jpg", 0.2, 10.0], ["example3.jpg", 0.2, 10.0]]
33+
34+
35+
36+
iface = gr.Interface(gradio_wrapper_for_LSD,
37+
["image",
38+
gr.inputs.Number(default=0.2, label='score_thr (0.0 ~ 1.0)'),
39+
gr.inputs.Number(default=10.0, label='dist_thr (0.0 ~ 20.0)')
40+
],
41+
"image",
42+
title="Line segment detection with Mobile LSD (M-LSD)",
43+
description="M-LSD is a light-weight and real-time deep line segment detector, which can run on GPU, CPU, and even on Mobile devices. Try it by uploading an image or clicking on an example. Read more at the links below",
44+
article="<p style='text-align: center'><a href='https://arxiv.org/abs/2106.00186'>Towards Real-time and Light-weight Line Segment Detection</a> | <a href='https://github.com/navervision/mlsd'>Github Repo</a></p>",
45+
examples=sample_images,
46+
allow_screenshot=True)
47+
48+
iface.launch()

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ opencv-python
33
pillow
44
tensorflow-gpu
55
Flask
6+
gradio

0 commit comments

Comments
 (0)