Kaz55's picture
ACT encoder representation analysis: 3-cable + 4-size t-SNE, contact-phase PCA, diameter axis
3c41fb5 verified
Raw History Blame Contribute Delete
4.96 kB
#!/usr/bin/env python3
"""Build a PowerPoint deck from the cable-representation figures.
Slides carry the figures only; the wording that would otherwise clutter the plot
goes into the speaker notes, so the images stay usable as-is in a paper too.
"""
import numpy as np
from pptx import Presentation
from pptx.util import Inches, Pt
FIGDIR = "outputs/pca"
OUT = f"{FIGDIR}/cable_representation.pptx"
SLIDES = [
dict(
title="Cable clusters in the learned representation",
image=f"{FIGDIR}/cable_diameter_clusters.png",
notes=(
"Left: unsupervised PCA of the ACT encoder features (512-d), plotted on PC4 vs PC3 "
"-- the two components that carry cable identity. PC1/PC2 are dominated by arm pose "
"and grasp phase, so the default projection hides the cable entirely.\n\n"
"Right: a diameter axis. Ridge regression maps the same encoder features onto physical "
"cable diameter, fitted on training episodes only. 2.6 mm lands between 1.7 and 4.5 mm "
"even though the model was never given the ordering -- it only ever saw three task "
"strings. Held-out R^2 = 0.88.\n\n"
" true 1.7 mm -> predicted 1.81 +- 0.33 mm\n"
" true 2.6 mm -> predicted 2.66 +- 0.39 mm\n"
" true 4.5 mm -> predicted 4.33 +- 0.43 mm\n\n"
"This means thickness is encoded as a quantity, not as three arbitrary labels: a pure "
"3-way classifier would place the clusters anywhere, not in metric order.\n\n"
"Method: 30 episodes per cable, 25 frames per episode (2250 frames). Split is by "
"EPISODE, not by frame -- frames inside one episode are near-duplicates, so a "
"frame-level split leaks the answer. Only held-out episodes (675 frames) are plotted. "
"Model: act-bluev2-cable170-330-270ep-ac60, 300k checkpoint."
),
),
dict(
title="Why PC1/PC2 hides it",
image=f"{FIGDIR}/pca_cable_informative_300k.png",
notes=(
"Same PCA, three views. Left is the default PC1 vs PC2: the three cables are fully "
"mixed (separability 0.13 and 0.00). Middle is PC4 vs PC3 from the identical "
"decomposition -- the clusters are there all along. Right shows separability per "
"component: the cable signal sits almost entirely in PC4 (ratio 1.53).\n\n"
"PC4 accounts for only 5.0% of variance while PC1 accounts for 11.2%. PCA orders axes "
"by variance, not by class separation, so a larger but cable-irrelevant factor "
"outranks it. Labels were used only to choose which existing axis to look along; the "
"axes themselves are unsupervised."
),
),
dict(
title="The information is really there",
image=f"{FIGDIR}/cable_repr_analysis_300k.png",
notes=(
"A linear probe settles it independently of any visualisation. Logistic regression on "
"the encoder features predicts cable identity with 97.9% accuracy on held-out episodes "
"(chance 33.3%). Raw GelSight pixels reach 95.9%.\n\n"
"Left and middle are LDA projections -- supervised, so they are fitted on training "
"episodes and drawn on held-out ones. Fitting and plotting the same data would "
"manufacture clusters that do not generalise.\n\n"
"Caveat: the model sees four cameras (RealSense x2 + GelSight x2), so this number does "
"not attribute the signal to touch. Comparing against act-bluev2-gs0-ac60, trained "
"without GelSight, would separate visual from tactile contribution. Note that across "
"four datasets, removing GelSight left training loss unchanged."
),
),
]
def main():
prs = Presentation()
prs.slide_width, prs.slide_height = Inches(13.333), Inches(7.5)
blank = prs.slide_layouts[6]
for s in SLIDES:
slide = prs.slides.add_slide(blank)
tb = slide.shapes.add_textbox(Inches(0.6), Inches(0.35), Inches(12.1), Inches(0.7))
p = tb.text_frame.paragraphs[0]
p.text = s["title"]
p.font.size, p.font.bold = Pt(26), True
# Fit the image inside the area below the title, preserving aspect ratio.
from PIL import Image
w, h = Image.open(s["image"]).size
avail_w, avail_h = Inches(12.1), Inches(5.9)
scale = min(avail_w / w, avail_h / h)
iw, ih = int(w * scale), int(h * scale)
slide.shapes.add_picture(s["image"],
int((prs.slide_width - iw) / 2), Inches(1.25),
width=iw, height=ih)
slide.notes_slide.notes_text_frame.text = s["notes"]
prs.save(OUT)
print(f"wrote {OUT}")
print(f" {len(SLIDES)} slides, figures only; explanations in the speaker notes")
if __name__ == "__main__":
main()