jm12138 commited on
Commit
daa75d5
β€’
1 Parent(s): b352111
Files changed (1) hide show
  1. app.py +19 -13
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
- long_size = max(image.shape[:2])
11
- if long_size > 512:
12
- f = 512 / long_size
13
- image = cv2.resize(image, (0, 0), fx=f, fy=f)
14
- results = module.segment(
15
- image=image[..., ::-1],
16
- labels=[item for item in labels.split('\n') if item != '']
17
- )
18
- return [
19
- results['color'][..., ::-1],
20
- results['mix'][..., ::-1],
21
- *[v[..., ::-1] for v in results['classes'].values()]
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(