Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -40,7 +40,7 @@ def resize_image_pil(image, new_width, new_height):
|
|
40 |
return resized
|
41 |
|
42 |
|
43 |
-
def inference(input_img, transparency=0.5, target_layer_number=-1, grad_cam_option="Yes"):
|
44 |
input_img = resize_image_pil(input_img, 32, 32)
|
45 |
input_img = np.array(input_img)
|
46 |
org_img = input_img
|
@@ -52,6 +52,7 @@ def inference(input_img, transparency=0.5, target_layer_number=-1, grad_cam_opti
|
|
52 |
softmax = torch.nn.Softmax(dim=0)
|
53 |
o = softmax(outputs.flatten())
|
54 |
confidences = {classes[i]: float(o[i]) for i in range(10)}
|
|
|
55 |
_, prediction = torch.max(outputs, 1)
|
56 |
target_layers = [model.layer2[target_layer_number]]
|
57 |
cam = GradCAM(model=model, target_layers=target_layers)
|
@@ -77,12 +78,13 @@ demo = gr.Interface(
|
|
77 |
gr.Image(width=256, height=256, label="Input Image"),
|
78 |
gr.Slider(0, 1, value=0.5, label="Overall Opacity of Image"),
|
79 |
gr.Slider(-2, -1, value=-2, step=1, label="Which Layer?"),
|
80 |
-
gr.Dropdown(["Yes", "No"], label="Want to see Grad Cam Images?")
|
|
|
81 |
],
|
82 |
outputs=[
|
83 |
"text",
|
84 |
gr.Image(width=256, height=256, label="Output"),
|
85 |
-
gr.Label(
|
86 |
],
|
87 |
title=title,
|
88 |
description=description,
|
|
|
40 |
return resized
|
41 |
|
42 |
|
43 |
+
def inference(input_img, transparency=0.5, target_layer_number=-1, grad_cam_option="Yes",top_classes=3):
|
44 |
input_img = resize_image_pil(input_img, 32, 32)
|
45 |
input_img = np.array(input_img)
|
46 |
org_img = input_img
|
|
|
52 |
softmax = torch.nn.Softmax(dim=0)
|
53 |
o = softmax(outputs.flatten())
|
54 |
confidences = {classes[i]: float(o[i]) for i in range(10)}
|
55 |
+
confidences = dict(list(confidences.items())[:top_classes])
|
56 |
_, prediction = torch.max(outputs, 1)
|
57 |
target_layers = [model.layer2[target_layer_number]]
|
58 |
cam = GradCAM(model=model, target_layers=target_layers)
|
|
|
78 |
gr.Image(width=256, height=256, label="Input Image"),
|
79 |
gr.Slider(0, 1, value=0.5, label="Overall Opacity of Image"),
|
80 |
gr.Slider(-2, -1, value=-2, step=1, label="Which Layer?"),
|
81 |
+
gr.Dropdown(["Yes", "No"], label="Want to see Grad Cam Images?"),
|
82 |
+
gr.Number(value=3, minimum=1,maximum=10)
|
83 |
],
|
84 |
outputs=[
|
85 |
"text",
|
86 |
gr.Image(width=256, height=256, label="Output"),
|
87 |
+
gr.Label()
|
88 |
],
|
89 |
title=title,
|
90 |
description=description,
|