File size: 1,903 Bytes
9c890d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Run the frozen SCALE4D checkpoint on nested prefixes of 1–10 input views."""

from __future__ import annotations

import argparse
from pathlib import Path


def main() -> None:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--input", type=Path, required=True)
    parser.add_argument("--output", type=Path, required=True)
    parser.add_argument("--checkpoint", default="facebook/SCALE4D")
    parser.add_argument("--revision")
    parser.add_argument("--device", default="cuda:0")
    parser.add_argument("--views", nargs="+", type=int, default=list(range(1, 11)))
    parser.add_argument("--decoder-chunk", type=int, default=512)
    parser.add_argument("--no-flash-attn", action="store_true")
    args = parser.parse_args()
    if len(set(args.views)) != len(args.views) or any(
        not 1 <= count <= 10 for count in args.views
    ):
        parser.error("--views must contain unique counts in 1–10")
    if args.output.exists():
        parser.error("The output directory already exists")

    from evaluation.scale4d import SCALE4D
    from evaluation.scale4d_inputs import npz_clip

    clip = npz_clip(args.input)
    if clip.rgbs.shape[0] < max(args.views):
        parser.error("The input does not contain enough distinct calibrated views")
    model = SCALE4D(
        args.checkpoint,
        revision=args.revision,
        device=args.device,
        use_flash_attn=not args.no_flash_attn,
        decoder_chunk=args.decoder_chunk,
        max_input_views=max(3, max(args.views)),
    )
    args.output.mkdir(parents=True)
    for views in sorted(args.views):
        result = model.predict_clip(clip, views=views, camera="on")
        result.metadata.pop("source_path", None)
        path = result.save(args.output / f"{views:02d}_views.npz")
        print(f"Saved {views} views: {path}", flush=True)


if __name__ == "__main__":
    main()