Spaces:
Sleeping
Sleeping
Fix: Runtime error
Browse files
app.py
CHANGED
|
@@ -58,58 +58,58 @@ def main():
|
|
| 58 |
"""
|
| 59 |
)
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 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__":
|