Download src/trafficvision/models/base.py from sunnycloudhust/TrafficVision: direct link, hf CLI and curl.
- Browser
- Download file 547 Bytes
-
https://huggingface.co/datasets/sunnycloudhust/TrafficVision/resolve/refs%2Fpr%2F1/src/trafficvision/models/base.py
- Command line
-
hf download hf://datasets/sunnycloudhust/TrafficVision@refs/pr/1/src/trafficvision/models/base.py
-
curl -L -o base.py https://huggingface.co/datasets/sunnycloudhust/TrafficVision/resolve/refs%2Fpr%2F1/src/trafficvision/models/base.py
547 Bytes
| """Unified adapters: RGB float CHW tensors -> original-image xyxy, labels 1..4.""" | |
| import torch | |
| class TorchDetector: | |
| def __init__(self, model, device="cpu", confidence=0.05): | |
| self.model = model.to(device).eval() | |
| self.device, self.confidence = device, confidence | |
| def predict(self, image): | |
| result = self.model([image.to(self.device)])[0] | |
| keep = result["scores"] >= self.confidence | |
| return {key: result[key][keep].detach().cpu() for key in ("boxes", "scores", "labels")} | |