Datasets:
Download temporal-same-camera-33/bf16_loader.py from HugMinjun/Blender6D-Track4D-v3: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/datasets/HugMinjun/Blender6D-Track4D-v3/resolve/main/temporal-same-camera-33/bf16_loader.py
- Command line
-
hf download hf://datasets/HugMinjun/Blender6D-Track4D-v3/temporal-same-camera-33/bf16_loader.py
-
curl -L -o bf16_loader.py https://huggingface.co/datasets/HugMinjun/Blender6D-Track4D-v3/resolve/main/temporal-same-camera-33/bf16_loader.py
1.1 kB
| """Minimal reader for this dataset's versioned condition archives.""" | |
| import json | |
| from pathlib import Path | |
| import zipfile | |
| import torch | |
| import zstandard as zstd | |
| from safetensors.torch import load | |
| def load_conditions(archive, member): | |
| """Return saved tensors; this does not load RGB or construct external targets.""" | |
| with zipfile.ZipFile(Path(archive)) as z: | |
| raw = zstd.ZstdDecompressor().decompress(z.read(member), max_output_size=1024**3) | |
| header = json.loads(raw[8:8 + int.from_bytes(raw[:8], "little")]) | |
| fmt = header.get("__metadata__", {}).get("format") | |
| if fmt not in {"bf16_dynamic_zstd_v1", "int8_dynamic_zstd_v1", "int8_dynamic_zstd_v2"}: | |
| raise ValueError(f"Unsupported condition format: {fmt}") | |
| tensors = load(raw) | |
| for key in ("memory_latent", "control_latents"): | |
| scale = tensors.pop("_qscale_" + key, None) | |
| if scale is not None: | |
| tensors[key] = (tensors[key].float() * scale).to(torch.bfloat16) | |
| if tensors[key].dtype != torch.bfloat16: | |
| raise ValueError(f"{key} is not BF16") | |
| return tensors | |