Shilpaj commited on
Commit
671ad7d
·
verified ·
1 Parent(s): ebf74f1

Fix: Runtime error

Browse files
Files changed (1) hide show
  1. app.py +52 -52
app.py CHANGED
@@ -58,58 +58,58 @@ def main():
58
  """
59
  )
60
 
61
- # #############################################################################
62
- # ################################ GradCam Tab ################################
63
- # #############################################################################
64
- with gr.Tab("GradCam"):
65
- gr.Markdown(
66
- """
67
- Visualize Class Activations Maps generated by the model's layer for the predicted class.
68
- This is used to see what the model is actually looking at in the image.
69
- """
70
- )
71
- with gr.Row():
72
- # Update the image input dimensions
73
- img_input = [gr.Image(label="Input Image", type="numpy", height=224)] # Changed dimensions
74
- gradcam_outputs = [
75
- gr.Label(label="Predictions"),
76
- gr.Image(label="GradCAM Output", height=224) # Match input image height
77
- ]
78
-
79
- with gr.Row():
80
- gradcam_inputs = [
81
- gr.Slider(0, 1, value=0.5, label="Activation Map Transparency"),
82
- gr.Slider(1, 10, value=3, step=1, label="Number of Top Predictions"),
83
- gr.Slider(1, 6, value=4, step=1, label="Target Layer Number")
84
- ]
85
-
86
- gradcam_button = gr.Button("Generate GradCAM")
87
- # Pass model to inference function using partial
88
- from functools import partial
89
- inference_fn = partial(inference, model=model, classes=classes)
90
- gradcam_button.click(inference_fn, inputs=img_input + gradcam_inputs, outputs=gradcam_outputs)
91
-
92
- gr.Markdown("## Examples")
93
- gr.Examples(
94
- examples=[
95
- ["./assets/examples/dog.jpg", 0.5, 3, 4],
96
- ["./assets/examples/cat.jpg", 0.5, 3, 4],
97
- ["./assets/examples/frog.jpg", 0.5, 3, 4],
98
- ["./assets/examples/bird.jpg", 0.5, 3, 4],
99
- ["./assets/examples/shark-plane.jpg", 0.5, 3, 4],
100
- ["./assets/examples/car.jpg", 0.5, 3, 4],
101
- ["./assets/examples/truck.jpg", 0.5, 3, 4],
102
- ["./assets/examples/horse.jpg", 0.5, 3, 4],
103
- ["./assets/examples/plane.jpg", 0.5, 3, 4],
104
- ["./assets/examples/ship.png", 0.5, 3, 4]
105
- ],
106
- inputs=img_input + gradcam_inputs,
107
- fn=inference_fn,
108
- outputs=gradcam_outputs
109
- )
110
-
111
- gr.close_all()
112
- demo.launch(debug=True)
113
 
114
 
115
  if __name__ == "__main__":
 
58
  """
59
  )
60
 
61
+ # #############################################################################
62
+ # ################################ GradCam Tab ################################
63
+ # #############################################################################
64
+ with gr.Tab("GradCam"):
65
+ gr.Markdown(
66
+ """
67
+ Visualize Class Activations Maps generated by the model's layer for the predicted class.
68
+ This is used to see what the model is actually looking at in the image.
69
+ """
70
+ )
71
+ with gr.Row():
72
+ img_input = [gr.Image(label="Input Image", type="numpy", height=224)]
73
+ gradcam_outputs = [
74
+ gr.Label(label="Predictions"),
75
+ gr.Image(label="GradCAM Output", height=224)
76
+ ]
77
+
78
+ with gr.Row():
79
+ gradcam_inputs = [
80
+ gr.Slider(0, 1, value=0.5, label="Activation Map Transparency"),
81
+ gr.Slider(1, 10, value=3, step=1, label="Number of Top Predictions"),
82
+ gr.Slider(1, 6, value=4, step=1, label="Target Layer Number")
83
+ ]
84
+
85
+ gradcam_button = gr.Button("Generate GradCAM")
86
+
87
+ # Pass model to inference function using partial
88
+ from functools import partial
89
+ inference_fn = partial(inference, model=model, classes=classes)
90
+ gradcam_button.click(inference_fn, inputs=img_input + gradcam_inputs, outputs=gradcam_outputs)
91
+
92
+ gr.Markdown("## Examples")
93
+ gr.Examples(
94
+ examples=[
95
+ ["./assets/examples/dog.jpg", 0.5, 3, 4],
96
+ ["./assets/examples/cat.jpg", 0.5, 3, 4],
97
+ ["./assets/examples/frog.jpg", 0.5, 3, 4],
98
+ ["./assets/examples/bird.jpg", 0.5, 3, 4],
99
+ ["./assets/examples/shark-plane.jpg", 0.5, 3, 4],
100
+ ["./assets/examples/car.jpg", 0.5, 3, 4],
101
+ ["./assets/examples/truck.jpg", 0.5, 3, 4],
102
+ ["./assets/examples/horse.jpg", 0.5, 3, 4],
103
+ ["./assets/examples/plane.jpg", 0.5, 3, 4],
104
+ ["./assets/examples/ship.png", 0.5, 3, 4]
105
+ ],
106
+ inputs=img_input + gradcam_inputs,
107
+ fn=inference_fn,
108
+ outputs=gradcam_outputs
109
+ )
110
+
111
+ # Launch the demo (moved inside the Blocks context)
112
+ demo.launch(debug=True)
113
 
114
 
115
  if __name__ == "__main__":