Download inference_example.py from LLL640/RepostGuard-Lite-M2-train-v3: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/LLL640/RepostGuard-Lite-M2-train-v3/resolve/main/inference_example.py
- Command line
-
hf download hf://LLL640/RepostGuard-Lite-M2-train-v3/inference_example.py
-
curl -L -o inference_example.py https://huggingface.co/LLL640/RepostGuard-Lite-M2-train-v3/resolve/main/inference_example.py
1.15 kB
| from __future__ import annotations | |
| import argparse | |
| from pathlib import Path | |
| import torch | |
| from huggingface_hub import snapshot_download | |
| from safetensors.torch import load_file | |
| from repostguard.config import load_config | |
| from repostguard.models import build_model | |
| def main() -> None: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--revision", default="v1.0.0") | |
| parser.add_argument("--device", default="cpu") | |
| args = parser.parse_args() | |
| root = Path( | |
| snapshot_download( | |
| repo_id="LLL640/RepostGuard-Lite-M2-train-v3", | |
| revision=args.revision, | |
| ) | |
| ) | |
| config = load_config(root / "resolved_config.yaml") | |
| model = build_model(config, load_pretrained=False) | |
| model.load_state_dict(load_file(root / "model.safetensors"), strict=True) | |
| model = model.to(args.device).eval() | |
| # Replace this tensor with repository preprocessing for a real RGB image. | |
| image = torch.zeros(1, 3, 224, 224, device=args.device) | |
| with torch.inference_mode(): | |
| score = torch.sigmoid(model(image)["logits"]) | |
| print(float(score.item())) | |
| if __name__ == "__main__": | |
| main() | |