Python
feat: corrected mhr assets link, corrected distillation pipeline
mohamdevf8937faf8323
diff --git a/README.md b/README.mdindex 7716141..4d74280 100644--- a/README.md+++ b/README.md@@ -141,7 +141,7 @@ CPU-only Linux users: see the comment at the top of `requirements-mhr.txt`.### Step 2 β Download the body-model assets```bash-curl -OL https://github.com/facebookresearch/MHR/releases/download/v1.0.0/assets.zip+curl -OL https://github.com/facebookresearch/MHR/releases/download/v1.0.1/assets.zipunzip assets.zip -d models/mhr_assets```diff --git a/instanthmr_distill_train/train_distill_optimized_correctives.py b/instanthmr_distill_train/train_distill_optimized_correctives.pyindex 3217876..d3d1a8f 100644--- a/instanthmr_distill_train/train_distill_optimized_correctives.py+++ b/instanthmr_distill_train/train_distill_optimized_correctives.py@@ -185,9 +185,9 @@ class DistillConfig:# Format: (parent_idx, child_idx) based on JOINT_NAMESmajor_bones = [(5, 7), # Left Shoulder -> Left Elbow- (7, 41), # Left Elbow -> Left Wrist+ (7, 62), # Left Elbow -> Left Wrist (62 = left_wrist, NOT 41 = right_wrist)(6, 8), # Right Shoulder -> Right Elbow- (8, 42), # Right Elbow -> Right Wrist+ (8, 41), # Right Elbow -> Right Wrist (41 = right_wrist, NOT 42 = left_thumb_tip)(9, 11), # Left Hip -> Left Knee(11, 13), # Left Knee -> Left Ankle(10, 12), # Right Hip -> Right Knee@@ -577,10 +577,11 @@ class InstantHMRStudent(nn.Module):pred_cam_trans = global_preds[:, idx_shape :]feat_2d_processed = self.head_2d_feat(feat_2d)- logits_2d = self.head_2d_logits(feat_2d_processed)- logits_2d = logits_2d.unflatten(-1, (2, self.kp2d_bins))- prob_2d = torch.softmax(logits_2d, dim=-1)- pred_joints_2d = (prob_2d * self.kp2d_bin_centers).sum(dim=-1)+ logits_2d = self.head_2d_logits(feat_2d_processed)+ logits_2d = logits_2d.unflatten(-1, (2, self.kp2d_bins))+ # softmax in fp32 (autocast already promotes it; explicit for no-autocast/bf16/export paths)+ prob_2d = torch.softmax(logits_2d.float(), dim=-1)+ pred_joints_2d = (prob_2d * self.kp2d_bin_centers.float()).sum(dim=-1)pred_joints_3d = self.head_3d(feat_3d)@@ -991,8 +992,8 @@ def train_instant_hmr():print(f"\nπ Epoch {epoch+1} Summary | LR: {scheduler.get_last_lr()[0]:.2e}")print(f" [Train] Tot: {avg_train['total']:.4f} | MHR: {avg_train['mhr']:.4f} | 2D: {avg_train['2d']:.4f} "f"| 3D: {avg_train['3d']:.4f} | Bone: {avg_train['bone']:.4f} | simcc: {avg_train['simcc']:.3f}")- print(f" [Val RAW] Tot: {raw_val['total']:.4f} | Mesh PA-MPJPE: {raw_hmr['Mesh_PA_MPJPE']:.1f} | Mesh MPJPE: {raw_hmr['Mesh_MPJPE']:.1f} | Head PA: {raw_hmr['Head_3D_PA_MPJPE']:.1f} mm")- print(f" [Val EMA] Tot: {ema_val['total']:.4f} | Mesh PA-MPJPE: {ema_hmr['Mesh_PA_MPJPE']:.1f} | Mesh MPJPE: {ema_hmr['Mesh_MPJPE']:.1f} | Head PA: {ema_hmr['Head_3D_PA_MPJPE']:.1f} mm")+ print(f" [Val RAW] Tot: {raw_val['total']:.4f} | Mesh PA-MPJPE: {raw_hmr['Mesh_PA_MPJPE']:.1f} | Mesh MPJPE: {raw_hmr['Mesh_MPJPE']:.1f} | Head PA: {raw_hmr['Head_3D_PA_MPJPE']:.1f} | Head MPJPE: {raw_hmr['Head_3D_MPJPE']:.1f} mm")+ print(f" [Val EMA] Tot: {ema_val['total']:.4f} | Mesh PA-MPJPE: {ema_hmr['Mesh_PA_MPJPE']:.1f} | Mesh MPJPE: {ema_hmr['Mesh_MPJPE']:.1f} | Head PA: {ema_hmr['Head_3D_PA_MPJPE']:.1f} | Head MPJPE: {ema_hmr['Head_3D_MPJPE']:.1f} mm")delta = raw_hmr['Mesh_PA_MPJPE'] - ema_hmr['Mesh_PA_MPJPE']print(f" π¬ EMA vs RAW (Mesh PA-MPJPE): {'EMA better' if delta > 0 else 'RAW better'} by {abs(delta):.1f} mm")@@ -1323,9 +1324,10 @@ def run_overfit_test(steps=1000, subset=8, lr=5e-4):+ ls['loss_cam'].item() + ls['loss_pose'].item() + ls.get('loss_bone_length', torch.tensor(0)).item())first_reg = last_reg = last_pa = None+ best_pa = float('inf') # 8-sample overfit is noisy at constant LR; judge the best fit reachedn_skipped = 0model.train()-+for step in range(steps):optimizer.zero_grad(set_to_none=True)with torch.amp.autocast(device_type='cuda', dtype=torch.float16, enabled=cfg.use_amp):@@ -1355,7 +1357,8 @@ def run_overfit_test(steps=1000, subset=8, lr=5e-4):m = evaluate_hmr_batch(p, batch, cfg, mhr_module)model.train()last_pa = m['Head_3D_PA_MPJPE']-+ best_pa = min(best_pa, last_pa)+print(f" step {step:04d} | tot {losses['total_loss'].item():.3f} "f"| 3d {losses['loss_3d_native'].item():.4f} "f"| pose {losses['loss_pose'].item():.4f} "@@ -1364,9 +1367,9 @@ def run_overfit_test(steps=1000, subset=8, lr=5e-4):f"| Head [MPJPE: {m['Head_3D_MPJPE']:.1f} | PA: {m['Head_3D_PA_MPJPE']:.1f}] mm "f"| Mesh [MPJPE: {m['Mesh_MPJPE']:.1f} | PA: {m['Mesh_PA_MPJPE']:.1f}] mm")- ok = (last_reg < first_reg * 0.10) and (last_pa is not None and last_pa < 40.0)+ ok = (last_reg < first_reg * 0.10) and (best_pa < 40.0)print(f"\n{'β SUCCESS' if ok else 'β FAIL'}: regression loss {first_reg:.4f} -> {last_reg:.5f} "- f"| final Head PA-MPJPE {last_pa:.1f} mm | anomalous steps skipped: {n_skipped}")+ f"| best Head PA-MPJPE {best_pa:.1f} mm (final {last_pa:.1f}) | anomalous steps skipped: {n_skipped}")return okdef parse_args():