Spaces:
Runtime error
Runtime error
OmerFarooq
commited on
Commit
•
fe1c53b
1
Parent(s):
080f6e6
Update app.py
Browse files
app.py
CHANGED
@@ -91,9 +91,9 @@ def gen_grad_img_single(weights, img, alpha = 0.4):
|
|
91 |
grad_model = Model(input, [x, output])
|
92 |
heatmaps, y_pred = create_heatmap(grad_model, img)
|
93 |
|
94 |
-
for i in range(len(y_pred)):
|
95 |
-
|
96 |
-
|
97 |
|
98 |
img = superimpose_single(heatmaps, img[0])
|
99 |
return np.array(img).astype('uint8'), y_pred
|
@@ -104,14 +104,19 @@ weights = "weights.h5"
|
|
104 |
|
105 |
def get_grad(img):
|
106 |
img = img_pros(img)
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
demo = gr.Interface(
|
111 |
fn = get_grad,
|
112 |
inputs = gr.Image(type = "pil", shape = (224,224)),
|
113 |
# outputs = [gr.outputs.Label(num_top_classes = 2, label = 'Classifiaction'), gr.Textbox('infer_time', label = 'Inference Time(ms)')]
|
114 |
-
outputs = [gr.Image(type = "numpy"), gr.Textbox(
|
115 |
)
|
116 |
demo.launch()
|
117 |
|
|
|
91 |
grad_model = Model(input, [x, output])
|
92 |
heatmaps, y_pred = create_heatmap(grad_model, img)
|
93 |
|
94 |
+
# for i in range(len(y_pred)):
|
95 |
+
# if y_pred[i] > 0.5: y_pred[i] = 1
|
96 |
+
# else: y_pred[i] = 0
|
97 |
|
98 |
img = superimpose_single(heatmaps, img[0])
|
99 |
return np.array(img).astype('uint8'), y_pred
|
|
|
104 |
|
105 |
def get_grad(img):
|
106 |
img = img_pros(img)
|
107 |
+
grad_img, y_pred = gen_grad_img_single(weights, img)
|
108 |
+
|
109 |
+
if y_pred[0] > 0.5: y_pred[0] = "cat"
|
110 |
+
else: y_pred[0] = "dog"
|
111 |
+
|
112 |
+
text = "Raw Score: " + str(y_pred) + "\nClassification: " + y_pred[0]
|
113 |
+
return grad_img, text
|
114 |
|
115 |
demo = gr.Interface(
|
116 |
fn = get_grad,
|
117 |
inputs = gr.Image(type = "pil", shape = (224,224)),
|
118 |
# outputs = [gr.outputs.Label(num_top_classes = 2, label = 'Classifiaction'), gr.Textbox('infer_time', label = 'Inference Time(ms)')]
|
119 |
+
outputs = [gr.Image(type = "numpy"), gr.Textbox(label = 'Prediction (threshold: 0.5)')]
|
120 |
)
|
121 |
demo.launch()
|
122 |
|