Spaces:
Runtime error
Runtime error
vahidrezanezhad
commited on
Commit
•
34e73c4
1
Parent(s):
a0c54ca
adding visualizer
Browse files
app.py
CHANGED
@@ -7,6 +7,36 @@ from huggingface_hub import from_pretrained_keras
|
|
7 |
def resize_image(img_in,input_height,input_width):
|
8 |
return cv2.resize( img_in, ( input_width,input_height) ,interpolation=cv2.INTER_NEAREST)
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
def do_prediction(model_name, img):
|
11 |
model = from_pretrained_keras(model_name)
|
12 |
|
@@ -136,7 +166,7 @@ def do_prediction(model_name, img):
|
|
136 |
'''
|
137 |
#prediction_true = prediction_true * -1
|
138 |
#prediction_true = prediction_true + 1
|
139 |
-
return "No numerical output", prediction_true
|
140 |
|
141 |
# catch-all (we should not reach this)
|
142 |
case _:
|
|
|
7 |
def resize_image(img_in,input_height,input_width):
|
8 |
return cv2.resize( img_in, ( input_width,input_height) ,interpolation=cv2.INTER_NEAREST)
|
9 |
|
10 |
+
def visualize_model_output(prediction):
|
11 |
+
unique_classes = np.unique(prediction[:,:,0])
|
12 |
+
rgb_colors = {'0':[0, 0, 0],
|
13 |
+
'1', [255, 0, 0],
|
14 |
+
'2', [255, 125, 0],
|
15 |
+
'3', [255, 0, 125],
|
16 |
+
'4', [125, 125, 125],
|
17 |
+
'5', [125, 125, 0],
|
18 |
+
'6', [0, 125, 255],
|
19 |
+
'7', [0, 125, 0],
|
20 |
+
'8', [125, 125, 125],
|
21 |
+
'9', [0, 125, 255],
|
22 |
+
'10', [125, 0, 125],
|
23 |
+
'11', [0, 255, 0],
|
24 |
+
'12', [0, 0, 255],
|
25 |
+
'13', [0, 255, 255],
|
26 |
+
'14', [255, 125, 125],
|
27 |
+
'15', [255, 0, 255]}
|
28 |
+
|
29 |
+
output = np.zeros(prediction.shape)
|
30 |
+
|
31 |
+
for unq_class in unique_classes:
|
32 |
+
rgb_class_unique = rgb_colors[str(unq_class)]
|
33 |
+
output[:,:,0] = rgb_class_unique[0]
|
34 |
+
output[:,:,1] = rgb_class_unique[1]
|
35 |
+
output[:,:,2] = rgb_class_unique[2]
|
36 |
+
|
37 |
+
return output
|
38 |
+
|
39 |
+
|
40 |
def do_prediction(model_name, img):
|
41 |
model = from_pretrained_keras(model_name)
|
42 |
|
|
|
166 |
'''
|
167 |
#prediction_true = prediction_true * -1
|
168 |
#prediction_true = prediction_true + 1
|
169 |
+
return "No numerical output", visualize_model_output(prediction_true)
|
170 |
|
171 |
# catch-all (we should not reach this)
|
172 |
case _:
|