"""Download and verify the FoundationPose checkpoints listed in configs/foundationpose_weights_manifest.json. Files go to third_party/FoundationPose/weights//{config.yml, model_best.pth}; resumable (Range requests), SHA-256 checked. The manifest URLs point at a community Hugging Face mirror (official Google Drive quota was exceeded when the snapshot was made); replace `url` entries with the official links if you have them. Usage: .venv/bin/python scripts/download_foundationpose_weights.py """ import hashlib, json, time from pathlib import Path import requests ROOT = Path(__file__).resolve().parents[1] manifest = json.loads((ROOT / 'configs/foundationpose_weights_manifest.json').read_text()) dest = ROOT / 'third_party/FoundationPose/weights' for item in manifest['files']: path = dest / item['path']; path.parent.mkdir(parents=True, exist_ok=True); tmp = path.with_suffix(path.suffix + '.part') if path.exists() and path.stat().st_size == item['size'] and hashlib.sha256(path.read_bytes()).hexdigest() == item['sha256']: print('ok ', item['path']); continue for attempt in range(5): try: offset = tmp.stat().st_size if tmp.exists() else 0 print(f'download {item["path"]} from byte {offset}', flush=True) with requests.get(item['url'], headers={'Range': f'bytes={offset}-{item["size"] - 1}'}, stream=True, timeout=(20, 60)) as r: r.raise_for_status() if offset and r.status_code != 206: offset = 0 with tmp.open('ab' if offset else 'wb') as f: for chunk in r.iter_content(1024 * 1024): f.write(chunk) if tmp.stat().st_size == item['size']: tmp.replace(path); break except requests.RequestException as e: print('retry:', type(e).__name__, flush=True); time.sleep(3) assert path.exists() and path.stat().st_size == item['size'], f'incomplete: {path}' digest = hashlib.sha256(path.read_bytes()).hexdigest(); assert digest == item['sha256'], f'sha256 mismatch: {path}' print('verified', item['path'], flush=True) (dest / 'download_manifest.json').write_text(json.dumps(manifest, indent=2)); print('all FoundationPose weights present in', dest)