Spaces:
Runtime error
Runtime error
Commit
·
4501c57
1
Parent(s):
43a409b
Update app.py
Browse files
app.py
CHANGED
@@ -20,6 +20,7 @@ classes = ('plane', 'car', 'bird', 'cat', 'deer',
|
|
20 |
|
21 |
def inference(input_img, transparency = 0.5, target_layer_number = -1):
|
22 |
transform = transforms.ToTensor()
|
|
|
23 |
input_img = transform(input_img)
|
24 |
input_img = input_img
|
25 |
input_img = input_img.unsqueeze(0)
|
@@ -33,12 +34,12 @@ def inference(input_img, transparency = 0.5, target_layer_number = -1):
|
|
33 |
img = inv_normalize(img)
|
34 |
rgb_img = np.transpose(img, (1, 2, 0))
|
35 |
rgb_img = rgb_img.numpy()
|
36 |
-
visualization = show_cam_on_image(
|
37 |
return classes[prediction[0].item()], visualization
|
38 |
|
39 |
title = "CIFAR10 trained on ResNet18 Model with GradCAM"
|
40 |
description = "A simple Gradio interface to infer on ResNet model, and get GradCAM results"
|
41 |
-
examples = [["cat.jpg", "dog.jpg"]]
|
42 |
demo = gr.Interface(
|
43 |
inference,
|
44 |
inputs = [gr.Image(shape=(32, 32), label="Input Image"), gr.Slider(0, 1, value = 0.5, label="Opacity of GradCAM"), gr.Slider(-2, -1, value = -2, step=1, label="Which Layer?")],
|
|
|
20 |
|
21 |
def inference(input_img, transparency = 0.5, target_layer_number = -1):
|
22 |
transform = transforms.ToTensor()
|
23 |
+
org_img = input_img
|
24 |
input_img = transform(input_img)
|
25 |
input_img = input_img
|
26 |
input_img = input_img.unsqueeze(0)
|
|
|
34 |
img = inv_normalize(img)
|
35 |
rgb_img = np.transpose(img, (1, 2, 0))
|
36 |
rgb_img = rgb_img.numpy()
|
37 |
+
visualization = show_cam_on_image(org_img/255, grayscale_cam, use_rgb=True, image_weight=transparency)
|
38 |
return classes[prediction[0].item()], visualization
|
39 |
|
40 |
title = "CIFAR10 trained on ResNet18 Model with GradCAM"
|
41 |
description = "A simple Gradio interface to infer on ResNet model, and get GradCAM results"
|
42 |
+
examples = [["cat.jpg", 0.5, -1], ["dog.jpg", 0.5, -1]]
|
43 |
demo = gr.Interface(
|
44 |
inference,
|
45 |
inputs = [gr.Image(shape=(32, 32), label="Input Image"), gr.Slider(0, 1, value = 0.5, label="Opacity of GradCAM"), gr.Slider(-2, -1, value = -2, step=1, label="Which Layer?")],
|