Spaces:
Runtime error
Runtime error
Commit ·
5499ef7
1
Parent(s): d1ff39a
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,7 +44,9 @@ def get_gradcam_image(input_tensor, label, target_layer):
|
|
| 44 |
|
| 45 |
|
| 46 |
def image_classifier(input_image, top_classes=3, show_cam=True, target_layers=[2, 3], transparency=0.5):
|
|
|
|
| 47 |
input_image = transform(input_image)
|
|
|
|
| 48 |
input_image = input_image.unsqueeze(0)
|
| 49 |
output = model(input_image)
|
| 50 |
|
|
@@ -62,7 +64,7 @@ def image_classifier(input_image, top_classes=3, show_cam=True, target_layers=[2
|
|
| 62 |
if show_cam:
|
| 63 |
for layer in target_layers:
|
| 64 |
grayscale_cam = get_gradcam_image(input_image, label, layer)
|
| 65 |
-
output_image = show_cam_on_image(
|
| 66 |
outputs.append((output_image, f"Layer {layer - 4}"))
|
| 67 |
|
| 68 |
return outputs, confidences
|
|
|
|
| 44 |
|
| 45 |
|
| 46 |
def image_classifier(input_image, top_classes=3, show_cam=True, target_layers=[2, 3], transparency=0.5):
|
| 47 |
+
orig_image = input_image
|
| 48 |
input_image = transform(input_image)
|
| 49 |
+
|
| 50 |
input_image = input_image.unsqueeze(0)
|
| 51 |
output = model(input_image)
|
| 52 |
|
|
|
|
| 64 |
if show_cam:
|
| 65 |
for layer in target_layers:
|
| 66 |
grayscale_cam = get_gradcam_image(input_image, label, layer)
|
| 67 |
+
output_image = show_cam_on_image(orig_image / 255, grayscale_cam, use_rgb=True, image_weight=transparency)
|
| 68 |
outputs.append((output_image, f"Layer {layer - 4}"))
|
| 69 |
|
| 70 |
return outputs, confidences
|