Spaces:
Running
Running
Marlin Lee commited on
Commit Β·
34a1691
1
Parent(s): f5a4258
Remove cross-dataset comparison panel
Browse files- scripts/explorer_app.py +2 -73
scripts/explorer_app.py
CHANGED
|
@@ -211,7 +211,7 @@ def _apply_dataset_globals(idx):
|
|
| 211 |
global live_mask, live_indices, dict_live_mask, dict_live_indices
|
| 212 |
global umap_backup
|
| 213 |
global _clip_scores, _clip_vocab, _clip_embeds, _clip_scores_f32, HAS_CLIP
|
| 214 |
-
global _compare_datasets
|
| 215 |
global feature_names, _names_file
|
| 216 |
|
| 217 |
ds = _all_datasets[idx]
|
|
@@ -240,7 +240,6 @@ def _apply_dataset_globals(idx):
|
|
| 240 |
_clip_scores_f32 = ds['clip_scores_f32']
|
| 241 |
HAS_CLIP = _clip_scores is not None and _clip_vocab is not None
|
| 242 |
_compare_datasets = [d for i, d in enumerate(_all_datasets) if i != idx]
|
| 243 |
-
HAS_COMPARE = len(_compare_datasets) > 0
|
| 244 |
feature_names = ds['feature_names']
|
| 245 |
_names_file = ds['names_file']
|
| 246 |
|
|
@@ -577,7 +576,7 @@ def _on_dataset_switch(attr, old, new):
|
|
| 577 |
status_div.text = _status_html('idle', 'Model switched β select a feature to explore.')
|
| 578 |
for div in [top_heatmap_div, top_zoom_div,
|
| 579 |
mean_heatmap_div, mean_zoom_div,
|
| 580 |
-
p75_heatmap_div, p75_zoom_div
|
| 581 |
div.text = ""
|
| 582 |
|
| 583 |
|
|
@@ -596,7 +595,6 @@ mean_heatmap_div = Div(text="", width=900)
|
|
| 596 |
mean_zoom_div = Div(text="", width=900)
|
| 597 |
p75_heatmap_div = Div(text="", width=900)
|
| 598 |
p75_zoom_div = Div(text="", width=900)
|
| 599 |
-
cross_dataset_div = Div(text="", width=900) # cross-dataset comparison rows
|
| 600 |
|
| 601 |
# Name editing widget (defined here so update_feature_display can reference it)
|
| 602 |
name_input = TextInput(
|
|
@@ -754,74 +752,6 @@ def update_feature_display(feature_idx):
|
|
| 754 |
p75_zoom_div.text = make_image_grid_html(
|
| 755 |
p75_zm_infos, f"75th Percentile β Zoomed to peak patch (feature {feat})")
|
| 756 |
|
| 757 |
-
# --- Cross-dataset comparison ---
|
| 758 |
-
if HAS_COMPARE:
|
| 759 |
-
COMP_THUMB = min(THUMB, 160)
|
| 760 |
-
N_COMP = 4
|
| 761 |
-
primary_label = _all_datasets[_active[0]]['label']
|
| 762 |
-
|
| 763 |
-
def _row_html(label, imgs_info, token_type='spatial'):
|
| 764 |
-
tag = (" <span style='font-size:10px;color:#888'>(CLS β no heatmap)</span>"
|
| 765 |
-
if token_type == 'cls' else "")
|
| 766 |
-
html = (f'<div style="margin-bottom:6px">'
|
| 767 |
-
f'<b style="font-size:12px">{label}{tag}</b>'
|
| 768 |
-
f'<div style="display:flex;gap:4px;margin-top:3px">')
|
| 769 |
-
for img, cap in imgs_info:
|
| 770 |
-
url = pil_to_data_url(img)
|
| 771 |
-
html += (f'<div style="text-align:center">'
|
| 772 |
-
f'<img src="{url}" width="{COMP_THUMB}" height="{COMP_THUMB}"'
|
| 773 |
-
f' style="border:1px solid #ccc;border-radius:3px"/>'
|
| 774 |
-
f'<div style="font-size:9px;color:#666">{cap}</div></div>')
|
| 775 |
-
html += '</div></div>'
|
| 776 |
-
return html
|
| 777 |
-
|
| 778 |
-
# Primary dataset row
|
| 779 |
-
primary_infos = []
|
| 780 |
-
for j in range(min(N_COMP, top_img_idx.shape[1])):
|
| 781 |
-
img_i = top_img_idx[feat, j].item()
|
| 782 |
-
if img_i < 0:
|
| 783 |
-
break
|
| 784 |
-
try:
|
| 785 |
-
pil = load_image(img_i).resize((COMP_THUMB, COMP_THUMB), Image.BILINEAR)
|
| 786 |
-
act = top_img_act[feat, j].item()
|
| 787 |
-
primary_infos.append((pil, f"{act:.3f}"))
|
| 788 |
-
except Exception:
|
| 789 |
-
primary_infos.append((Image.new("RGB", (COMP_THUMB, COMP_THUMB), (180,180,180)), "err"))
|
| 790 |
-
|
| 791 |
-
html = ('<div style="border-top:2px solid #e0e0e0;padding-top:8px;margin-top:6px">'
|
| 792 |
-
'<h3 style="margin:0 0 8px 0;color:#333">Cross-dataset comparison'
|
| 793 |
-
' β top images by max activation</h3>')
|
| 794 |
-
html += _row_html(primary_label, primary_infos, 'spatial')
|
| 795 |
-
|
| 796 |
-
# Comparison dataset rows
|
| 797 |
-
for cd in _compare_datasets:
|
| 798 |
-
if cd.get('_lazy', False):
|
| 799 |
-
html += (f'<div style="margin-bottom:6px">'
|
| 800 |
-
f'<b style="font-size:12px">{cd["label"]}</b>'
|
| 801 |
-
f' <span style="font-size:10px;color:#888">'
|
| 802 |
-
f'(not yet loaded β select this model to load it)</span></div>')
|
| 803 |
-
continue
|
| 804 |
-
cd_infos = []
|
| 805 |
-
if feat < cd['d_model']:
|
| 806 |
-
for j in range(min(N_COMP, cd['top_img_idx'].shape[1])):
|
| 807 |
-
img_i = cd['top_img_idx'][feat, j].item()
|
| 808 |
-
if img_i < 0:
|
| 809 |
-
break
|
| 810 |
-
try:
|
| 811 |
-
path = cd['image_paths'][img_i]
|
| 812 |
-
pil = load_compare_image(path, COMP_THUMB)
|
| 813 |
-
act = cd['top_img_act'][feat, j].item()
|
| 814 |
-
cd_infos.append((pil, f"{act:.3f}"))
|
| 815 |
-
except Exception:
|
| 816 |
-
cd_infos.append((Image.new("RGB", (COMP_THUMB, COMP_THUMB), (180,180,180)), "err"))
|
| 817 |
-
else:
|
| 818 |
-
cd_infos = [(Image.new("RGB", (COMP_THUMB, COMP_THUMB), (220,220,220)),
|
| 819 |
-
"feat idx\nout of range")]
|
| 820 |
-
html += _row_html(cd['label'], cd_infos, cd['token_type'])
|
| 821 |
-
|
| 822 |
-
html += '</div>'
|
| 823 |
-
cross_dataset_div.text = html
|
| 824 |
-
|
| 825 |
status_div.text = _status_html('ok', f'✓ Feature {feat} ready.')
|
| 826 |
_update_view_visibility()
|
| 827 |
|
|
@@ -1520,7 +1450,6 @@ right_panel = column(
|
|
| 1520 |
top_heatmap_div, top_zoom_div,
|
| 1521 |
mean_heatmap_div, mean_zoom_div,
|
| 1522 |
p75_heatmap_div, p75_zoom_div,
|
| 1523 |
-
cross_dataset_div,
|
| 1524 |
)
|
| 1525 |
|
| 1526 |
layout = row(left_panel, middle_panel, right_panel)
|
|
|
|
| 211 |
global live_mask, live_indices, dict_live_mask, dict_live_indices
|
| 212 |
global umap_backup
|
| 213 |
global _clip_scores, _clip_vocab, _clip_embeds, _clip_scores_f32, HAS_CLIP
|
| 214 |
+
global _compare_datasets
|
| 215 |
global feature_names, _names_file
|
| 216 |
|
| 217 |
ds = _all_datasets[idx]
|
|
|
|
| 240 |
_clip_scores_f32 = ds['clip_scores_f32']
|
| 241 |
HAS_CLIP = _clip_scores is not None and _clip_vocab is not None
|
| 242 |
_compare_datasets = [d for i, d in enumerate(_all_datasets) if i != idx]
|
|
|
|
| 243 |
feature_names = ds['feature_names']
|
| 244 |
_names_file = ds['names_file']
|
| 245 |
|
|
|
|
| 576 |
status_div.text = _status_html('idle', 'Model switched β select a feature to explore.')
|
| 577 |
for div in [top_heatmap_div, top_zoom_div,
|
| 578 |
mean_heatmap_div, mean_zoom_div,
|
| 579 |
+
p75_heatmap_div, p75_zoom_div]:
|
| 580 |
div.text = ""
|
| 581 |
|
| 582 |
|
|
|
|
| 595 |
mean_zoom_div = Div(text="", width=900)
|
| 596 |
p75_heatmap_div = Div(text="", width=900)
|
| 597 |
p75_zoom_div = Div(text="", width=900)
|
|
|
|
| 598 |
|
| 599 |
# Name editing widget (defined here so update_feature_display can reference it)
|
| 600 |
name_input = TextInput(
|
|
|
|
| 752 |
p75_zoom_div.text = make_image_grid_html(
|
| 753 |
p75_zm_infos, f"75th Percentile β Zoomed to peak patch (feature {feat})")
|
| 754 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 755 |
status_div.text = _status_html('ok', f'✓ Feature {feat} ready.')
|
| 756 |
_update_view_visibility()
|
| 757 |
|
|
|
|
| 1450 |
top_heatmap_div, top_zoom_div,
|
| 1451 |
mean_heatmap_div, mean_zoom_div,
|
| 1452 |
p75_heatmap_div, p75_zoom_div,
|
|
|
|
| 1453 |
)
|
| 1454 |
|
| 1455 |
layout = row(left_panel, middle_panel, right_panel)
|