Spaces:
Sleeping
Sleeping
Show layer progression as activation maps
Browse files
app.py
CHANGED
|
@@ -293,21 +293,19 @@ def strongest_channels(activation, count):
|
|
| 293 |
return [(channel, fmap[channel].numpy()) for channel in channel_ids]
|
| 294 |
|
| 295 |
|
| 296 |
-
def layer_overview_gallery(
|
| 297 |
-
preview = fit_image(image)
|
| 298 |
choices = layer_choices()
|
| 299 |
outputs = []
|
| 300 |
|
| 301 |
for index, activation in enumerate(activations):
|
| 302 |
_, channels, height, width = activation.shape
|
| 303 |
energy = activation_energy(activation)
|
| 304 |
-
|
| 305 |
caption = (
|
| 306 |
-
f"Layer {index}
|
| 307 |
-
f"{choices[index].split(': ', 1)[1]} | {channels}
|
| 308 |
-
"Heat shows where the layer has the most total response."
|
| 309 |
)
|
| 310 |
-
outputs.append((
|
| 311 |
|
| 312 |
return outputs
|
| 313 |
|
|
@@ -347,7 +345,7 @@ def analyze_image(image, layer_label=DEFAULT_LAYER, channels=DEFAULT_CHANNELS):
|
|
| 347 |
|
| 348 |
return (
|
| 349 |
image,
|
| 350 |
-
layer_overview_gallery(
|
| 351 |
feature_map_gallery(selected, channels),
|
| 352 |
overlay_heatmap(fit_image(image), activation_energy(selected), alpha=0.48, cmap_name="magma"),
|
| 353 |
layer_summary(layer_index, selected, channels),
|
|
@@ -477,7 +475,7 @@ def build_app():
|
|
| 477 |
with gr.Tab("Layer activations"):
|
| 478 |
with gr.Row(equal_height=False):
|
| 479 |
selected_image = gr.Image(label="Selected image", type="pil", interactive=False)
|
| 480 |
-
selected_overlay = gr.Image(label="
|
| 481 |
layer_summary_md = gr.Markdown()
|
| 482 |
channel_explanations = gr.Gallery(
|
| 483 |
label="Selected layer feature maps",
|
|
@@ -487,7 +485,7 @@ def build_app():
|
|
| 487 |
elem_classes=["activation-gallery"],
|
| 488 |
)
|
| 489 |
layer_progression = gr.Gallery(
|
| 490 |
-
label="
|
| 491 |
columns=3,
|
| 492 |
height=760,
|
| 493 |
object_fit="contain",
|
|
|
|
| 293 |
return [(channel, fmap[channel].numpy()) for channel in channel_ids]
|
| 294 |
|
| 295 |
|
| 296 |
+
def layer_overview_gallery(activations):
|
|
|
|
| 297 |
choices = layer_choices()
|
| 298 |
outputs = []
|
| 299 |
|
| 300 |
for index, activation in enumerate(activations):
|
| 301 |
_, channels, height, width = activation.shape
|
| 302 |
energy = activation_energy(activation)
|
| 303 |
+
activation_map = colorize(energy, "magma").resize((TILE_SIZE, TILE_SIZE), Image.Resampling.BILINEAR)
|
| 304 |
caption = (
|
| 305 |
+
f"Layer {index}\n"
|
| 306 |
+
f"{choices[index].split(': ', 1)[1]} | {channels} maps | {height}x{width}"
|
|
|
|
| 307 |
)
|
| 308 |
+
outputs.append((activation_map, caption))
|
| 309 |
|
| 310 |
return outputs
|
| 311 |
|
|
|
|
| 345 |
|
| 346 |
return (
|
| 347 |
image,
|
| 348 |
+
layer_overview_gallery(activations),
|
| 349 |
feature_map_gallery(selected, channels),
|
| 350 |
overlay_heatmap(fit_image(image), activation_energy(selected), alpha=0.48, cmap_name="magma"),
|
| 351 |
layer_summary(layer_index, selected, channels),
|
|
|
|
| 475 |
with gr.Tab("Layer activations"):
|
| 476 |
with gr.Row(equal_height=False):
|
| 477 |
selected_image = gr.Image(label="Selected image", type="pil", interactive=False)
|
| 478 |
+
selected_overlay = gr.Image(label="Single selected-layer overlay", type="pil", interactive=False)
|
| 479 |
layer_summary_md = gr.Markdown()
|
| 480 |
channel_explanations = gr.Gallery(
|
| 481 |
label="Selected layer feature maps",
|
|
|
|
| 485 |
elem_classes=["activation-gallery"],
|
| 486 |
)
|
| 487 |
layer_progression = gr.Gallery(
|
| 488 |
+
label="Activation maps as the image moves through the model",
|
| 489 |
columns=3,
|
| 490 |
height=760,
|
| 491 |
object_fit="contain",
|