Skip to content

Commit a9c244f

Browse files
committed
Init license plate pipeline
1 parent 8ed9bea commit a9c244f

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
License Plate object detection pipeline.
3+
"""
4+
5+
import logging
6+
from collections.abc import Sequence
7+
8+
import onnxruntime as ort
9+
10+
from open_image_models.detection.core.hub import PlateDetectorModel, download_model
11+
from open_image_models.detection.core.yolo_v9.inference import YoloV9ObjectDetector
12+
13+
# Setup logging
14+
LOGGER = logging.getLogger(__name__)
15+
LOGGER.setLevel(logging.INFO)
16+
17+
18+
class LicensePlateDetector(YoloV9ObjectDetector):
19+
"""
20+
Specialized detector for license plates using YoloV9 model.
21+
Inherits from YoloV9ObjectDetector and sets up license plate specific configuration.
22+
"""
23+
24+
def __init__(
25+
self,
26+
detection_model: PlateDetectorModel,
27+
conf_thresh: float = 0.25,
28+
providers: Sequence[str | tuple[str, dict]] | None = None,
29+
sess_options: ort.SessionOptions = None,
30+
) -> None:
31+
"""
32+
Initializes the LicensePlateDetector with the specified detection model and inference device.
33+
34+
Args:
35+
detection_model: Detection model to use, see `PlateDetectorModel`.
36+
conf_thresh: Confidence threshold for filtering predictions.
37+
providers: Optional sequence of providers in order of decreasing precedence. If not specified, all available
38+
providers are used.
39+
sess_options: Advanced session options for ONNX Runtime.
40+
"""
41+
# Download model if needed
42+
detector_model_path = download_model(detection_model)
43+
super().__init__(
44+
model_path=detector_model_path,
45+
conf_thresh=conf_thresh,
46+
class_labels=["License Plate"],
47+
providers=providers,
48+
sess_options=sess_options,
49+
)
50+
LOGGER.info("Initialized LicensePlateDetector with model %s", detector_model_path)

0 commit comments

Comments
 (0)