Files
hand-motion-pipeline/scripts/verify_foundationpose_setup.py
liyang ae28d55f81 Update to 2026-09-17 pipeline snapshot; add weights, L20 assets and recording via Git LFS
Source: RGB-D -> Dyn-HaMR -> L20 retargeting -> FoundationPose -> reference repair -> SPIDER,
documented in docs/PIPELINE_LATEST.md and docs/SETUP_AND_WEIGHTS.md. Adds FoundationPose and
nvdiffrast upstream snapshots, requirements/pipeline_venv.txt and the FoundationPose weight
manifest/downloader.

Assets (Git LFS): weights/ (WiLoR detector, HandFlow denoiser, UniDepth-L), FoundationPose
checkpoints, HaMeR checkpoint, Dyn-HaMR HMP model and BMC constraints, L20 URDF/meshes, the
20260915_171525 D405 recording and the two box CADs. MANO models are not redistributed
(third_party/hamer/_DATA/data/mano/README.txt). Environments, caches and run outputs excluded.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-17 11:43:37 +08:00

33 lines
2.1 KiB
Python

"""Exercise compiled extensions, GPU rendering, official weights and red-box initialization."""
import sys,json
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
sys.path.insert(0,str(ROOT/'third_party/FoundationPose'))
import numpy as np
import torch,trimesh
import nvdiffrast.torch as dr
from estimater import FoundationPose,ScorePredictor,PoseRefinePredictor
import Utils
assert torch.cuda.is_available()
assert Utils.mycpp is not None and hasattr(Utils.mycpp,'cluster_poses')
ctx=dr.RasterizeCudaContext()
pos=torch.tensor([[[-.5,-.5,0,1],[.5,-.5,0,1],[0,.5,0,1]]],dtype=torch.float32,device='cuda')
tri=torch.tensor([[0,1,2]],dtype=torch.int32,device='cuda')
rast,_=dr.rasterize(ctx,pos,tri,resolution=[64,64])
assert torch.isfinite(rast).all() and (rast[...,3]>0).sum()>0
score=ScorePredictor();refine=PoseRefinePredictor()
outputs={}
with torch.inference_mode():
for name,predictor in [('score',score),('refine',refine)]:
h,w=predictor.cfg.input_resize
a=torch.zeros((1,predictor.cfg.c_in,h,w),device='cuda')
out=predictor.model(a,a,L=1) if name=='score' else predictor.model(a,a)
assert all(torch.isfinite(v).all() for v in out.values())
outputs[name]={k:list(v.shape) for k,v in out.items()}
mesh=trimesh.load(ROOT/'docs/上半.stl')
est=FoundationPose(model_pts=mesh.vertices,model_normals=mesh.vertex_normals,mesh=mesh,scorer=score,refiner=refine,glctx=ctx,debug=0,debug_dir=str(ROOT/'output/foundationpose_setup/smoke_debug'))
torch.cuda.synchronize()
report={'status':'passed','gpu':torch.cuda.get_device_name(),'torch':torch.__version__,'cuda':torch.version.cuda,'mycpp':Utils.mycpp.__file__,'rasterized_pixels':int((rast[...,3]>0).sum()),'network_outputs':outputs,'red_box_rotation_hypotheses':list(est.rot_grid.shape),'scope':'GPU rendering, network forward passes and STL estimator initialization; no recorded-video pose accuracy validation','optional_bundlesdf_mycuda':'not built; not required for model-based FoundationPose'}
(ROOT/'output/foundationpose_setup/runtime_verification.json').write_text(json.dumps(report,indent=2))
print(json.dumps(report,indent=2))