Datasets:
Download modis_s2/predict.py from riccardode/s2_res: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/datasets/riccardode/s2_res/resolve/main/modis_s2/predict.py
- Command line
-
hf download hf://datasets/riccardode/s2_res/modis_s2/predict.py
-
curl -L -o predict.py https://huggingface.co/datasets/riccardode/s2_res/resolve/main/modis_s2/predict.py
1.2 kB
| """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() | |