dusaurabh commited on
Commit
490cf0f
1 Parent(s): 167b47a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -9
app.py CHANGED
@@ -39,10 +39,8 @@ def resize_image_pil(image, new_width, new_height):
39
 
40
  return resized
41
 
42
- def get_num_top_classes(num_classes_input):
43
- return int(num_classes_input)
44
 
45
- def inference(input_img, transparency=0.5, target_layer_number=-1, grad_cam_option="Yes", num_classes_input=3, num_top_classes=3):
46
  input_img = resize_image_pil(input_img, 32, 32)
47
  input_img = np.array(input_img)
48
  org_img = input_img
@@ -61,11 +59,12 @@ def inference(input_img, transparency=0.5, target_layer_number=-1, grad_cam_opti
61
  grayscale_cam = grayscale_cam[0, :]
62
  img = input_img.squeeze(0)
63
  img = inv_normalize(img)
 
64
  if grad_cam_option == "Yes":
65
  visualization = show_cam_on_image(org_img/255, grayscale_cam, use_rgb=True, image_weight=transparency)
66
- return classes[prediction[0].item()], visualization, confidences, num_top_classes
67
  else:
68
- return classes[prediction[0].item()], None, confidences, num_top_classes
69
 
70
  title = "CIFAR10 trained on ResNet18 Model with GradCAM"
71
  description = "A simple Gradio interface to infer on ResNet model, and get GradCAM results"
@@ -78,14 +77,12 @@ demo = gr.Interface(
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(1, 10, label="Number of Classes"),
83
- gr.Number(1, 10, label="Number of Top Classes")
84
  ],
85
  outputs=[
86
  "text",
87
  gr.Image(width=256, height=256, label="Output"),
88
- gr.Label(num_top_classes=get_num_top_classes)
89
  ],
90
  title=title,
91
  description=description,
 
39
 
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
 
59
  grayscale_cam = grayscale_cam[0, :]
60
  img = input_img.squeeze(0)
61
  img = inv_normalize(img)
62
+ print('Confidences ',confidences)
63
  if grad_cam_option == "Yes":
64
  visualization = show_cam_on_image(org_img/255, grayscale_cam, use_rgb=True, image_weight=transparency)
65
+ return classes[prediction[0].item()], visualization, confidences
66
  else:
67
+ return classes[prediction[0].item()], None, confidences
68
 
69
  title = "CIFAR10 trained on ResNet18 Model with GradCAM"
70
  description = "A simple Gradio interface to infer on ResNet model, and get GradCAM results"
 
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(num_top_classes=3)
86
  ],
87
  title=title,
88
  description=description,