Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -125,6 +125,57 @@ id2label= {1: '动物皮',
|
|
125 |
65: '纱窗',
|
126 |
0: '背景/未知'}
|
127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
model_save_path ='jinfengxie/BFM_segformer0821'
|
129 |
model = TFSegformerForSemanticSegmentation.from_pretrained(model_save_path)
|
130 |
|
@@ -294,9 +345,9 @@ def process_image(image_path):
|
|
294 |
#image = Image.open(image_path)
|
295 |
one_mask,color_mask, counts_dict = predict_and_visualize(image_path)
|
296 |
colors_per_class=ext_colors(image_path,one_mask,n_clusters=4)
|
297 |
-
colors_per_label = {
|
298 |
# 定义一个列表,包含需要从字典中删除的键
|
299 |
-
labels_to_remove = ['
|
300 |
# 使用字典推导式删除列表中的键
|
301 |
colors_per_label = {key: value for key, value in colors_per_label.items() if key not in labels_to_remove}
|
302 |
palette_image = plot_material_color_palette_grid(colors_per_label)
|
@@ -304,6 +355,7 @@ def process_image(image_path):
|
|
304 |
# 将结果转化为图片展示
|
305 |
plt.figure(figsize=(5, 5))
|
306 |
plt.imshow(color_mask)
|
|
|
307 |
plt.axis('off')
|
308 |
color_mask_img = plt_to_image()
|
309 |
counts_dict2={id2label[key]: value for key, value in counts_dict.items()}
|
|
|
125 |
65: '纱窗',
|
126 |
0: '背景/未知'}
|
127 |
|
128 |
+
id2material={1: 'Animal skin',
|
129 |
+
2: 'Bone/teeth/horn',
|
130 |
+
3: 'Brickwork',
|
131 |
+
4: 'Cardboard/Paper',
|
132 |
+
6: 'Ceiling tile',
|
133 |
+
7: 'Ceramic',
|
134 |
+
8: 'Chalkboard/blackboard',
|
135 |
+
10: 'Concrete',
|
136 |
+
13: 'Fabric/cloth',
|
137 |
+
15: 'Fire',
|
138 |
+
16: 'Foliage',
|
139 |
+
17: 'Food',
|
140 |
+
18: 'Fur',
|
141 |
+
19: 'Gemstone/quartz',
|
142 |
+
20: 'Glass',
|
143 |
+
21: 'Hair',
|
144 |
+
23: 'Ice',
|
145 |
+
24: 'Leather',
|
146 |
+
26: 'Metal',
|
147 |
+
27: 'Mirror',
|
148 |
+
29: 'Paint/plaster',
|
149 |
+
32: 'Photograph/painting',
|
150 |
+
33: 'Plastic, clear',
|
151 |
+
34: 'Plastic, non-clear',
|
152 |
+
35: 'Rubber/latex',
|
153 |
+
36: 'Sand',
|
154 |
+
37: 'Skin/lips',
|
155 |
+
38: 'Sky',
|
156 |
+
39: 'Snow',
|
157 |
+
41: 'Soil/mud',
|
158 |
+
43: 'natural stone',
|
159 |
+
44: 'polished stone & engineered stone',
|
160 |
+
46: 'Tile',
|
161 |
+
47: 'Wallpaper',
|
162 |
+
48: 'Water',
|
163 |
+
49: 'Wax',
|
164 |
+
50: 'Whiteboard',
|
165 |
+
52: 'Wood',
|
166 |
+
53: 'tree',
|
167 |
+
56: 'Asphalt',
|
168 |
+
57: 'enamel',
|
169 |
+
58: 'Rammed earth',
|
170 |
+
59: 'composite decorative board',
|
171 |
+
60: 'Cement',
|
172 |
+
61: 'Pottery',
|
173 |
+
62: 'Roofing waterproof material',
|
174 |
+
63: 'Metal mesh window (perspective)',
|
175 |
+
64: 'carved brick',
|
176 |
+
65: 'window screen',
|
177 |
+
0: 'background'}
|
178 |
+
|
179 |
model_save_path ='jinfengxie/BFM_segformer0821'
|
180 |
model = TFSegformerForSemanticSegmentation.from_pretrained(model_save_path)
|
181 |
|
|
|
345 |
#image = Image.open(image_path)
|
346 |
one_mask,color_mask, counts_dict = predict_and_visualize(image_path)
|
347 |
colors_per_class=ext_colors(image_path,one_mask,n_clusters=4)
|
348 |
+
colors_per_label = {id2material[key]: value for key, value in colors_per_class.items()}
|
349 |
# 定义一个列表,包含需要从字典中删除的键
|
350 |
+
labels_to_remove = ['sky', 'background','Glass','tree','water','Plastic, clear']
|
351 |
# 使用字典推导式删除列表中的键
|
352 |
colors_per_label = {key: value for key, value in colors_per_label.items() if key not in labels_to_remove}
|
353 |
palette_image = plot_material_color_palette_grid(colors_per_label)
|
|
|
355 |
# 将结果转化为图片展示
|
356 |
plt.figure(figsize=(5, 5))
|
357 |
plt.imshow(color_mask)
|
358 |
+
plt.tight_layout()
|
359 |
plt.axis('off')
|
360 |
color_mask_img = plt_to_image()
|
361 |
counts_dict2={id2label[key]: value for key, value in counts_dict.items()}
|