chansung commited on
Commit
0c5b5d7
1 Parent(s): 826a627

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -159
app.py CHANGED
@@ -8,166 +8,8 @@ from matplotlib import gridspec
8
  import matplotlib.pyplot as plt
9
  import onnxruntime as ort
10
 
11
- def ade_palette():
12
- """ADE20K palette that maps each class to RGB values."""
13
- return [
14
- [120, 120, 120],
15
- [180, 120, 120],
16
- [6, 230, 230],
17
- [80, 50, 50],
18
- [4, 200, 3],
19
- [120, 120, 80],
20
- [140, 140, 140],
21
- [204, 5, 255],
22
- [230, 230, 230],
23
- [4, 250, 7],
24
- [224, 5, 255],
25
- [235, 255, 7],
26
- [150, 5, 61],
27
- [120, 120, 70],
28
- [8, 255, 51],
29
- [255, 6, 82],
30
- [143, 255, 140],
31
- [204, 255, 4],
32
- [255, 51, 7],
33
- [204, 70, 3],
34
- [0, 102, 200],
35
- [61, 230, 250],
36
- [255, 6, 51],
37
- [11, 102, 255],
38
- [255, 7, 71],
39
- [255, 9, 224],
40
- [9, 7, 230],
41
- [220, 220, 220],
42
- [255, 9, 92],
43
- [112, 9, 255],
44
- [8, 255, 214],
45
- [7, 255, 224],
46
- [255, 184, 6],
47
- [10, 255, 71],
48
- [255, 41, 10],
49
- [7, 255, 255],
50
- [224, 255, 8],
51
- [102, 8, 255],
52
- [255, 61, 6],
53
- [255, 194, 7],
54
- [255, 122, 8],
55
- [0, 255, 20],
56
- [255, 8, 41],
57
- [255, 5, 153],
58
- [6, 51, 255],
59
- [235, 12, 255],
60
- [160, 150, 20],
61
- [0, 163, 255],
62
- [140, 140, 140],
63
- [250, 10, 15],
64
- [20, 255, 0],
65
- [31, 255, 0],
66
- [255, 31, 0],
67
- [255, 224, 0],
68
- [153, 255, 0],
69
- [0, 0, 255],
70
- [255, 71, 0],
71
- [0, 235, 255],
72
- [0, 173, 255],
73
- [31, 0, 255],
74
- [11, 200, 200],
75
- [255, 82, 0],
76
- [0, 255, 245],
77
- [0, 61, 255],
78
- [0, 255, 112],
79
- [0, 255, 133],
80
- [255, 0, 0],
81
- [255, 163, 0],
82
- [255, 102, 0],
83
- [194, 255, 0],
84
- [0, 143, 255],
85
- [51, 255, 0],
86
- [0, 82, 255],
87
- [0, 255, 41],
88
- [0, 255, 173],
89
- [10, 0, 255],
90
- [173, 255, 0],
91
- [0, 255, 153],
92
- [255, 92, 0],
93
- [255, 0, 255],
94
- [255, 0, 245],
95
- [255, 0, 102],
96
- [255, 173, 0],
97
- [255, 0, 20],
98
- [255, 184, 184],
99
- [0, 31, 255],
100
- [0, 255, 61],
101
- [0, 71, 255],
102
- [255, 0, 204],
103
- [0, 255, 194],
104
- [0, 255, 82],
105
- [0, 10, 255],
106
- [0, 112, 255],
107
- [51, 0, 255],
108
- [0, 194, 255],
109
- [0, 122, 255],
110
- [0, 255, 163],
111
- [255, 153, 0],
112
- [0, 255, 10],
113
- [255, 112, 0],
114
- [143, 255, 0],
115
- [82, 0, 255],
116
- [163, 255, 0],
117
- [255, 235, 0],
118
- [8, 184, 170],
119
- [133, 0, 255],
120
- [0, 255, 92],
121
- [184, 0, 255],
122
- [255, 0, 31],
123
- [0, 184, 255],
124
- [0, 214, 255],
125
- [255, 0, 112],
126
- [92, 255, 0],
127
- [0, 224, 255],
128
- [112, 224, 255],
129
- [70, 184, 160],
130
- [163, 0, 255],
131
- [153, 0, 255],
132
- [71, 255, 0],
133
- [255, 0, 163],
134
- [255, 204, 0],
135
- [255, 0, 143],
136
- [0, 255, 235],
137
- [133, 255, 0],
138
- [255, 0, 235],
139
- [245, 0, 255],
140
- [255, 0, 122],
141
- [255, 245, 0],
142
- [10, 190, 212],
143
- [214, 255, 0],
144
- [0, 204, 255],
145
- [20, 0, 255],
146
- [255, 255, 0],
147
- [0, 153, 255],
148
- [0, 41, 255],
149
- [0, 255, 204],
150
- [41, 0, 255],
151
- [41, 255, 0],
152
- [173, 0, 255],
153
- [0, 245, 255],
154
- [71, 0, 255],
155
- [122, 0, 255],
156
- [0, 255, 184],
157
- [0, 92, 255],
158
- [184, 255, 0],
159
- [0, 133, 255],
160
- [255, 214, 0],
161
- [25, 194, 194],
162
- [102, 255, 0],
163
- [92, 0, 255],
164
- ]
165
-
166
  labels_list = []
167
- colormap = np.asarray(ade_palette())
168
-
169
- model_filename = 'segformer-b5-finetuned-ade-640-640.onnx'
170
- sess = ort.InferenceSession(model_filename)
171
 
172
  csv.field_size_limit(sys.maxsize)
173
 
@@ -175,6 +17,17 @@ with open(r'labels.txt', 'r') as fp:
175
  for line in fp:
176
  labels_list.append(line[:-1])
177
 
 
 
 
 
 
 
 
 
 
 
 
178
  def label_to_color_image(label):
179
  if label.ndim != 2:
180
  raise ValueError("Expect 2-D input label")
 
8
  import matplotlib.pyplot as plt
9
  import onnxruntime as ort
10
 
11
+ ade_palette = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  labels_list = []
 
 
 
 
13
 
14
  csv.field_size_limit(sys.maxsize)
15
 
 
17
  for line in fp:
18
  labels_list.append(line[:-1])
19
 
20
+ with open(r'ade_palette.txt', 'r') as fp:
21
+ for line in fp:
22
+ tmp_list = list(map(int, line[:-1].strip('][').split(', ')))
23
+ ade_palette.append(tmp_list)
24
+
25
+ colormap = np.asarray(ade_palette)
26
+
27
+ model_filename = 'segformer-b5-finetuned-ade-640-640.onnx'
28
+ sess = ort.InferenceSession(model_filename)
29
+
30
+
31
  def label_to_color_image(label):
32
  if label.ndim != 2:
33
  raise ValueError("Expect 2-D input label")