"""Run inference for one exported scene.""" import argparse from pathlib import Path import time import torch from .io import ROOT, load_model, load_sample, predict, write_prediction def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--sample", type=Path, required=True, help="Directory containing inputs.npz and metadata.json") parser.add_argument("--output", type=Path, default=Path("prediction.tif")) parser.add_argument("--device", choices=("cpu", "cuda"), default="cpu") parser.add_argument("--precision", choices=("fp32", "bf16"), default="fp32") parser.add_argument("--threads", type=int, default=2) parser.add_argument("--model-dir", type=Path, default=ROOT) args = parser.parse_args() torch.set_num_threads(args.threads) started = time.monotonic() model = load_model(args.device, args.model_dir) inputs, metadata = load_sample(args.sample, args.device, args.model_dir) result = predict(model, inputs, args.precision) write_prediction(args.output, result, metadata) print(f"{metadata['id']}: saved {args.output} ({time.monotonic()-started:.1f} s)") if __name__ == "__main__": main()