|
Download examples/visualizer_code/source/docs/scale4d.md from facebook/SCALE4D: direct link, hf CLI and curl.
- Browser
- Download file 6.91 kB
-
https://huggingface.co/facebook/SCALE4D/resolve/main/examples/visualizer_code/source/docs/scale4d.md
- Command line
-
hf download hf://facebook/SCALE4D/examples/visualizer_code/source/docs/scale4d.md
-
curl -L -o scale4d.md https://huggingface.co/facebook/SCALE4D/resolve/main/examples/visualizer_code/source/docs/scale4d.md
6.91 kB
| # SCALE4D inference | |
| The 140,000-step SCALE4D checkpoint uses the stable UCPE VideoMAE-Giant encoder, | |
| the FP32 D4RT decoder, a 20 m camera-diameter cap, and UCPE extent-scale bias. | |
| The encoder processes 48 frames at 224 × 224 resolution, with one to three views. | |
| The Forge trainer uses the same inference architecture as stable UCPE. | |
| The exact 140k inference config ships in | |
| [`model_config_scale4d_140k.json`](../nets/ucpe_cd50_stable/model_config_scale4d_140k.json), | |
| including `extent_scale_injection: "ucpe_bias"`, `selective_ucpe_rows: true`, and | |
| `ucpe_transition: null`. The effective UCPE transition scale is **1.0**. This | |
| config was checked against the native checkpoint's recorded `run_config`. | |
| The 140k inference weights are hosted at | |
| [facebook/SCALE4D](https://huggingface.co/facebook/SCALE4D). The verified release | |
| revision is `069f22ba021e3c23c7e4831ff4385927978eac63`. | |
| ## Install | |
| Install a CUDA-compatible PyTorch build, then install this checkout: | |
| ```bash | |
| python -m pip install -e . | |
| ``` | |
| ## Run a video | |
| ```bash | |
| infd4rt-infer-scale4d \ | |
| --checkpoint facebook/SCALE4D \ | |
| --video video.mp4 \ | |
| --output tracks.npz | |
| ``` | |
| For a local inference export, pass its directory to `--checkpoint`. A native WDM | |
| `.pt` checkpoint is also supported. Use `--revision <commit>` to pin a Hub release. | |
| Authenticate with `hf auth login` when the Hub repository requires access. | |
| The default Hub download is pinned to the verified 140k release revision above. | |
| Local checkpoint loading needs no Hub access. Native `.pt` files use their | |
| recorded architecture. A standalone `model.safetensors` file, or a PyTorch | |
| state dictionary in `.pt`/`.pth`, uses a neighboring `config.json` when present | |
| and otherwise uses the packaged 140k config: | |
| ```bash | |
| infd4rt-infer-scale4d \ | |
| --checkpoint /path/to/model.safetensors \ | |
| --video video.mp4 --output tracks.npz | |
| ``` | |
| For weights from another architecture, supply `--config /path/to/config.json`. | |
| An explicit config that conflicts with a native checkpoint is rejected. Every | |
| model tensor, including the learned extent projection, must load strictly. | |
| ## Python API | |
| ```python | |
| from evaluation.scale4d import SCALE4D | |
| tracker = SCALE4D("/path/to/checkpoint_iter_000140000.pt", device="cuda:0") | |
| tracks = tracker.predict_video("video.mp4", grid_size=16) | |
| tracks.save("tracks.npz") | |
| ``` | |
| The tracker loads the model once and can predict multiple clips. For a prepared | |
| calibrated NPZ, use `tracker.predict_npz("clip.npz", views=3, camera="on")`. | |
| To supply arrays directly: | |
| ```python | |
| tracks = tracker.predict( | |
| rgbs, # uint8 (V, 48, 3, H, W), RGB | |
| query_uv=query_uv, # float32 (N, 2), source pixels (u, v) | |
| query_times=query_times, # int64 (N,), source frame indices | |
| cameras_to_world=poses, # (V, 48, 4, 4), OpenCV camera-to-world | |
| intrinsics=intrinsics, # (V, 48, 3, 3), original image raster | |
| world_up=world_up, # (3,), up direction in the pose world frame | |
| camera="on", | |
| ) | |
| tracks.save("calibrated_tracks.npz") | |
| ``` | |
| Queries refer to the first supplied view. If queries are omitted, a 16 × 16 grid | |
| is queried in its first frame; `grid_size` changes this. Single-view RGB arrays | |
| may have shape `(48, 3, H, W)`. Camera OFF can omit calibration and world up; | |
| the API then supplies synthetic intrinsics and identity poses. Camera ON | |
| requires poses, intrinsics, and world up. | |
| `tracks.xyz`, `tracks.uv_depth`, `tracks.uv`, `tracks.visibility`, and | |
| `tracks.confidence` are CPU tensors. Saved NPZs also contain the source queries, | |
| camera identities, coordinate frame, frame sampling, and recorded model config. | |
| Saving refuses to overwrite an existing output. | |
| The video path uniformly samples 48 frames across the video and queries a | |
| 16 × 16 pixel grid in the first sampled frame. `--grid-size` changes that grid. | |
| The output records `source_frame_indices`, including repeats for short videos. | |
| This runs a single 48-frame window; it does not stitch long-video trajectories. | |
| Video-only inference uses camera-OFF conditioning and synthetic intrinsics. | |
| Its 3D predictions have no supplied metric calibration. `uv_depth` combines the | |
| predicted pixel coordinates and predicted Z using those synthetic intrinsics; | |
| `xyz` retains the independent 3D head. | |
| ## Run calibrated multi-view input | |
| ```bash | |
| infd4rt-infer-scale4d \ | |
| --checkpoint /path/to/scale4d_export \ | |
| --input-npz clip.npz \ | |
| --views 3 --camera on \ | |
| --output tracks.npz | |
| ``` | |
| The NPZ contains these arrays; it does not require labels: | |
| | Array | Shape / type | | |
| | --- | --- | | |
| | `rgbs` | `(V, 48, 3, H, W)`, uint8 RGB | | |
| | `cameras_to_world` | `(V, 48, 4, 4)`, camera-to-world transforms | | |
| | `intrinsics` | `(V, 48, 3, 3)`, intrinsics in the original image raster | | |
| | `query_uv` | `(N, 2)`, source pixel coordinates `(u, v)` | | |
| | `query_times` | `(N,)`, int64 source-frame indices | | |
| | `query_views` | `(N,)`, int64 zeros; queries refer to the first supplied camera | | |
| | `world_up` | `(3,)`, world-space up vector; required with `--camera on` | | |
| Optional `metadata_json` is a scalar JSON string with `camera_ids` and | |
| `dataset_type`. Existing frozen UCPE benchmark NPZs are accepted. | |
| Predictions are expressed in the first supplied view's camera at each target | |
| frame. Outputs include `xyz`, `uv_depth`, `uv`, and visibility/confidence | |
| probabilities, with shapes `(48, N, 3)`, `(48, N, 3)`, `(48, N, 2)`, and | |
| `(48, N)`. Native 24/25-frame DexYCB benchmark bundles retain their existing | |
| repeat-padding behavior and return predictions on their native timeline. | |
| FlashAttention is optional: the default encoder automatically uses PyTorch SDPA | |
| when it is absent. Keep the same attention option when comparing predictions; | |
| `--no-flash` selects the encoder's explicit math path and can change its output. | |
| `--decoder-chunk` controls decoder memory. | |
| The standalone model and query code are in `nets/ucpe_cd50_stable/` and | |
| `evaluation/ucpe_inference.py`; `nets/scale4d.py` resolves and strictly loads | |
| the native or safetensors checkpoint. | |
| The encoder, camera geometry, UCPE attention, transition, and FP32 decoder are | |
| all included in this package. Running inference requires no fbsource checkout, | |
| Buck build, trainer, or additional VideoMAE initialization checkpoint. | |
| ## Prepare and upload an inference release | |
| ```bash | |
| infd4rt-export-scale4d \ | |
| --checkpoint checkpoint_iter_000140000.pt \ | |
| --output-dir scale4d_export | |
| python -m d4rt_scripts.upload_scale4d --release-dir scale4d_export | |
| ``` | |
| The export contains lossless model tensors in `model.safetensors`, the recorded | |
| inference architecture in `config.json`, and SHA-256 identities in `release.json`. | |
| It omits optimizer, RNG, data-loader, and training-dataset state. | |
| The upload uses the configured Hugging Face credentials, requires write access | |
| and any organization SSO authorization, and verifies the uploaded size and | |
| SHA-256. It writes only those three release files to `facebook/SCALE4D`. | |