karolmajek commited on
Commit
cd29d0c
1 Parent(s): 6cf385d
Files changed (2) hide show
  1. app.py +66 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import paddlehub as hub
2
+ import gradio as gr
3
+ import requests
4
+ import numpy as np
5
+ import matplotlib.pyplot as plt
6
+
7
+ model = hub.Module(name='deeplabv3p_resnet50_cityscapes')
8
+
9
+ url1 = 'https://cdn.pixabay.com/photo/2014/09/07/21/52/city-438393_1280.jpg'
10
+ r = requests.get(url1, allow_redirects=True)
11
+ open("city1.jpg", 'wb').write(r.content)
12
+ url2 = 'https://cdn.pixabay.com/photo/2016/02/19/11/36/canal-1209808_1280.jpg'
13
+ r = requests.get(url2, allow_redirects=True)
14
+ open("city2.jpg", 'wb').write(r.content)
15
+
16
+
17
+ colormap = np.zeros((256, 3), dtype=np.uint8)
18
+ colormap[0] = [128, 64, 128]
19
+ colormap[1] = [244, 35, 232]
20
+ colormap[2] = [70, 70, 70]
21
+ colormap[3] = [102, 102, 156]
22
+ colormap[4] = [190, 153, 153]
23
+ colormap[5] = [153, 153, 153]
24
+ colormap[6] = [250, 170, 30]
25
+ colormap[7] = [220, 220, 0]
26
+ colormap[8] = [107, 142, 35]
27
+ colormap[9] = [152, 251, 152]
28
+ colormap[10] = [70, 130, 180]
29
+ colormap[11] = [220, 20, 60]
30
+ colormap[12] = [255, 0, 0]
31
+ colormap[13] = [0, 0, 142]
32
+ colormap[14] = [0, 0, 70]
33
+ colormap[15] = [0, 60, 100]
34
+ colormap[16] = [0, 80, 100]
35
+ colormap[17] = [0, 0, 230]
36
+ colormap[18] = [119, 11, 32]
37
+
38
+ def applyColormap(img,colormap):
39
+ ret = np.zeros((img.shape[0],img.shape[1],3), dtype=np.uint8)
40
+ for y in range(img.shape[0]):
41
+ for x in range(img.shape[1]):
42
+ ret[y,x] = colormap[int(img[y,x])]
43
+ return ret.astype(np.uint8)
44
+
45
+
46
+ def inference(image):
47
+ img = np.array(image)[:,:,::-1]
48
+ result = model.predict(images=[img], visualization=True)[0]
49
+ result_color = applyColormap(result,colormap)
50
+ return result_color
51
+
52
+ title = "PaddleHub: DeepLabv3p R50 Cityscapes"
53
+ description = "demo for PaddleHub. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below.\nModel: deeplabv3p_resnet50_cityscapes"
54
+ article = "<p style='text-align: center'><a href='https://www.paddlepaddle.org.cn/hubdetail?name=deeplabv3p_resnet50_cityscapes&en_category=ImageSegmentation'>PaddleHub page</a></p>"
55
+
56
+ gr.Interface(
57
+ inference,
58
+ [gr.inputs.Image(type="pil", label="Input")],
59
+ gr.outputs.Image(type="numpy", label="Output"),
60
+ title=title,
61
+ description=description,
62
+ article=article,
63
+ examples=[
64
+ ["city1.jpg"],
65
+ ["city2.jpg"]
66
+ ]).launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ paddlehub
2
+