| |
| """Example: discover and load a primitive assembly from the release manifest. |
| |
| Run from the dataset repository root:: |
| |
| python examples/load_artifact.py |
| python examples/load_artifact.py --source toys4k --method superfrustum --object-id airplane_002 |
| python examples/load_artifact.py --artifact eval |
| |
| Manifest discovery requires only the Python standard library plus |
| ``load_release.py`` at the repo root. Actually unpickling primitive assemblies |
| may require SuperFit, PyTorch, NumPy, and related runtime dependencies. See: |
| |
| https://github.com/BardOfCodes/superfit |
| """ |
|
|
| from __future__ import annotations |
|
|
| import argparse |
| import sys |
| from pathlib import Path |
|
|
| |
| _REPO_ROOT = Path(__file__).resolve().parent.parent |
| if str(_REPO_ROOT) not in sys.path: |
| sys.path.insert(0, str(_REPO_ROOT)) |
|
|
| from load_release import ReleaseIndex, load_metadata |
|
|
|
|
| def main() -> None: |
| parser = argparse.ArgumentParser(description=__doc__) |
| parser.add_argument("--root", type=Path, default=_REPO_ROOT, help="Dataset repo root.") |
| parser.add_argument("--source", default="toys4k", choices=["toys4k", "partobjaverse"]) |
| parser.add_argument("--method", default="superfrustum") |
| parser.add_argument("--object-id", default=None, help="Instance id; default: first match.") |
| parser.add_argument( |
| "--artifact", |
| default="primitive_assembly", |
| choices=[ |
| "primitive_assembly", |
| "primitive_assembly_eval", |
| "primitive_assembly_error", |
| "primitive_assembly_textured", |
| ], |
| ) |
| args = parser.parse_args() |
|
|
| meta = load_metadata(args.root) |
| print(f"Release: {meta.get('release_root_name', args.root.name)}") |
| print(f"Total instances in manifest: {meta.get('total_instances', '?')}") |
|
|
| index = ReleaseIndex(args.root) |
| if args.object_id: |
| row = index.get(args.source, args.method, args.object_id) |
| else: |
| rows = index.filter(source_dataset=args.source, method=args.method) |
| if not rows: |
| raise SystemExit(f"No rows for {args.source}/{args.method}") |
| row = rows[0] |
| print(f"(using first of {len(rows)} matches)") |
|
|
| print(f"Instance: {row['instance_dir']}") |
| path = index.artifact_path(row, args.artifact) |
| print(f"Loading: {path} ({path.stat().st_size} bytes)") |
|
|
| obj = index.load(row, args.artifact) |
| print(f"Loaded type: {type(obj).__name__}") |
| if isinstance(obj, dict): |
| print(f"Top-level keys ({len(obj)}): {list(obj.keys())[:20]}") |
| if len(obj) > 20: |
| print(" ...") |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|