This commit is contained in:
Pepijn
2025-08-31 21:38:46 +02:00
parent d8c875e069
commit d51bbe9492
+27 -4
View File
@@ -314,13 +314,15 @@ class RLearNPolicy(PreTrainedPolicy):
if flat.max() > 1.0: if flat.max() > 1.0:
flat = flat / 255.0 flat = flat / 255.0
# DINOv3 expects images in [0, 1] range, RGB format # Prepare inputs for processor: feed uint8 to avoid double-rescale; let processor rescale/normalize
# Convert tensor to list of PIL-like arrays for processor flat_clamped = flat.clamp(0.0, 1.0)
flat_numpy = flat.permute(0, 2, 3, 1).cpu().numpy() # (BT, H, W, C) flat_uint8 = (flat_clamped * 255.0).round().to(torch.uint8) # (BT, C, H, W)
flat_numpy = flat_uint8.permute(0, 2, 3, 1).cpu().numpy() # (BT, H, W, C) uint8
images_list = [flat_numpy[i] for i in range(B * T)] images_list = [flat_numpy[i] for i in range(B * T)]
# Process through DINOv3 processor and model # Process through DINOv3 processor and model
inputs = self.vision_processor(images=images_list, return_tensors="pt") # Disable center-crop to preserve motion near borders; allow default rescale/normalize
inputs = self.vision_processor(images=images_list, return_tensors="pt", do_center_crop=False)
inputs = {k: v.to(device) for k, v in inputs.items()} inputs = {k: v.to(device) for k, v in inputs.items()}
# Process in batch through DINOv3 model # Process in batch through DINOv3 model
@@ -412,6 +414,27 @@ class RLearNPolicy(PreTrainedPolicy):
feature_std = vision_features.std().item() feature_std = vision_features.std().item()
print(f"Feature stats: mean={feature_mean:.4f}, std={feature_std:.4f}") print(f"Feature stats: mean={feature_mean:.4f}, std={feature_std:.4f}")
# Extra DIAGNOSTIC: CLS vs patch mean/max deltas for one sample, two far-apart frames
try:
if 'last_hidden_state' in vision_outputs.__dict__ and T >= 2:
# Recover CLS tokens
cls_flat = tokens[:, 0, :] # (BT, D)
cls = rearrange(cls_flat, '(b t) d -> b t d', b=B, t=T)
b0 = 0
f0, f1 = 0, T - 1
# L2 between CLS at two frames
cls_l2 = (cls[b0, f1] - cls[b0, f0]).pow(2).sum().sqrt().item()
# Patch mean L2
pm_f0 = patch_features[b0, f0].mean(dim=0)
pm_f1 = patch_features[b0, f1].mean(dim=0)
pm_l2 = (pm_f1 - pm_f0).pow(2).sum().sqrt().item()
# Max over patches L2
per_patch_l2 = (patch_features[b0, f1] - patch_features[b0, f0]).pow(2).sum(dim=1).sqrt()
max_p_l2 = per_patch_l2.max().item()
print(f"CLS ΔL2: {cls_l2:.6f} | mean(patches) ΔL2: {pm_l2:.6f} | max(patch) ΔL2: {max_p_l2:.6f}")
except Exception as _:
pass
# Check temporal variance for each sample # Check temporal variance for each sample
for b_idx in range(min(B, 2)): # Debug first 2 samples for b_idx in range(min(B, 2)): # Debug first 2 samples
sample_features = vision_features[b_idx] # (T, D) sample_features = vision_features[b_idx] # (T, D)