Spaces:
Runtime error
Runtime error
fix a bug
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import cv2
|
|
|
2 |
import paddlehub as hub
|
3 |
import gradio as gr
|
4 |
|
@@ -7,19 +8,24 @@ module = hub.Module(name="lseg")
|
|
7 |
|
8 |
|
9 |
def segment(image, labels):
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
|
25 |
gr.Interface(
|
|
|
1 |
import cv2
|
2 |
+
import paddle
|
3 |
import paddlehub as hub
|
4 |
import gradio as gr
|
5 |
|
|
|
8 |
|
9 |
|
10 |
def segment(image, labels):
|
11 |
+
try:
|
12 |
+
long_size = max(image.shape[:2])
|
13 |
+
if long_size > 512:
|
14 |
+
f = 512 / long_size
|
15 |
+
image = cv2.resize(image, (0, 0), fx=f, fy=f)
|
16 |
+
results = module.segment(
|
17 |
+
image=image[..., ::-1],
|
18 |
+
labels=[item for item in labels.split('\n') if item != '']
|
19 |
+
)
|
20 |
+
|
21 |
+
return [
|
22 |
+
results['color'][..., ::-1],
|
23 |
+
results['mix'][..., ::-1],
|
24 |
+
*[cv2.cvtColor(v, cv2.COLOR_BGRA2RGBA) for v in results['classes'].values()]
|
25 |
+
]
|
26 |
+
except:
|
27 |
+
paddle.disable_static()
|
28 |
+
raise ValueError
|
29 |
|
30 |
|
31 |
gr.Interface(
|