jm12138 commited on
Commit
ef0caf9
β€’
1 Parent(s): f1ce139
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import paddlehub as hub
2
  import gradio as gr
3
 
@@ -6,11 +7,19 @@ module = hub.Module(name="lseg")
6
 
7
 
8
  def segment(image, labels):
 
 
 
 
9
  results = module.segment(
10
  image=image[..., ::-1],
11
- labels=labels.split('\n')
12
  )
13
- return [results['color'][..., ::-1], results['mix'][..., ::-1], *[v[..., ::-1] for v in results['classes'].values()]]
 
 
 
 
14
 
15
 
16
  gr.Interface(
 
1
+ import cv2
2
  import paddlehub as hub
3
  import gradio as gr
4
 
 
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(