Download code/tt_depthpro2/tests/mk_dec_cmp.py from changh95/DepthPro2: direct link, hf CLI and curl.
- Browser
- Download file 1.93 kB
-
https://huggingface.co/changh95/DepthPro2/resolve/main/code/tt_depthpro2/tests/mk_dec_cmp.py
- Command line
-
hf download hf://changh95/DepthPro2/code/tt_depthpro2/tests/mk_dec_cmp.py
-
curl -L -o mk_dec_cmp.py https://huggingface.co/changh95/DepthPro2/resolve/main/code/tt_depthpro2/tests/mk_dec_cmp.py
1.93 kB
| # SPDX-License-Identifier: Apache-2.0 | |
| """CPU check of a random-tap DEC run (mk_dec_run.py --shape HxWxT): the float32 reference decode of the same taps | |
| (reference/model.py) vs the saved device output, per frame (``--frames`` limits the frames decoded). | |
| python -u bundles/depthpro2/code/tt_depthpro2/tests/mk_dec_cmp.py --size L --shape 480x640x4 | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import os | |
| import sys | |
| import torch | |
| sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))) | |
| from tt_depthpro2.reference import model as R # noqa: E402 | |
| from tt_depthpro2.tests import baseline_helpers as BH # noqa: E402 | |
| from tt_depthpro2.tests.mk_dec_run import EMU_DIR, rand_taps # noqa: E402 | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--size", default="L") | |
| ap.add_argument("--shape", default="480x640x4") | |
| ap.add_argument("--frames", type=int, default=2) | |
| args = ap.parse_args() | |
| torch.set_num_threads(8) | |
| hp, wp, T = (int(v) for v in args.shape.split("x")) | |
| d = torch.load(os.path.join(EMU_DIR, f"dev_rand_{hp}x{wp}x{T}__{args.size}.pt"), weights_only=True)["inv"] | |
| w = R.load_safetensors(os.path.join(BH.size_dir(args.size), "model.safetensors")) | |
| taps = [t.to(torch.bfloat16).float() for t in rand_taps(args.size, T, hp, wp)] # the device sees bf16 taps | |
| ref = R.DepthPro2Reference(args.size, w) | |
| worst = 1.0 | |
| for f in sorted({0, T - 1} if args.frames >= 2 else {0})[:args.frames]: | |
| with torch.no_grad(): | |
| r = ref.decode([t[f:f + 1] for t in taps], (hp // 16, wp // 16))[0, 0] | |
| p, m = BH.pcc(d[f], r), BH.max_rel(d[f], r) | |
| worst = min(worst, p) | |
| print(f"{args.size} {args.shape} frame {f}: pcc {p:.7f} max_rel {m:.3e} finite {bool(torch.isfinite(d[f]).all())}", | |
| flush=True) | |
| print("OK" if worst >= 0.99999 else "LOW PCC") | |
| if __name__ == "__main__": | |
| main() | |