Python API Reference

class opendetect.Detector(model='rfdetr-m', *, model_path=None, input_size=None, hardware_acceleration=True, tensor_rt=False, mixed_precision=False, threshold=0.3, num_select=300, class_ids=None, auto_download=True, cache_dir=None, show_download_progress=False)[source]

Bases: object

Parameters:
  • model (str)

  • model_path (str | Path | None)

  • input_size (tuple[int, int] | None)

  • hardware_acceleration (bool)

  • tensor_rt (bool)

  • mixed_precision (bool)

  • threshold (float)

  • num_select (int)

  • class_ids (list[int] | None)

  • auto_download (bool)

  • cache_dir (str | Path | None)

  • show_download_progress (bool)

property backend: DetectorModel
property class_names: list[str] | None
resolve_class_ids_from_names(names)[source]
Parameters:

names (list[str])

Return type:

list[int]

set_class_filter(class_ids)[source]
Parameters:

class_ids (list[int] | None)

Return type:

list[int] | None

list_classes()[source]
Return type:

list[tuple[int, str]]

predict(image, *, color='bgr')[source]
Parameters:
  • image (numpy.ndarray)

  • color (str)

Return type:

dict[str, numpy.ndarray]

annotate(image, detections=None, *, color='bgr')[source]
Parameters:
  • image (numpy.ndarray)

  • detections (dict[str, numpy.ndarray] | None)

  • color (str)

Return type:

numpy.ndarray

predict_and_annotate(image, *, color='bgr')[source]
Parameters:
  • image (numpy.ndarray)

  • color (str)

Return type:

tuple[dict[str, numpy.ndarray], numpy.ndarray]

infer_image_file(image_path, *, output_path=None)[source]
Parameters:
  • image_path (str | Path)

  • output_path (str | Path | None)

Return type:

tuple[dict[str, numpy.ndarray], numpy.ndarray]

infer_video_file(video_path, *, output_path, max_frames=None)[source]
Parameters:
  • video_path (str | Path)

  • output_path (str | Path)

  • max_frames (int | None)

Return type:

int

class opendetect.LoadedModelInfo(model_id: 'str | None', implementation: 'str', input_size: 'tuple[int, int]', model_path: 'Path', source: 'str')[source]

Bases: object

Parameters:
  • model_id (str | None)

  • implementation (str)

  • input_size (tuple[int, int])

  • model_path (Path)

  • source (str)

model_id: str | None
implementation: str
input_size: tuple[int, int]
model_path: Path
source: str
class opendetect.ModelSpec(model_id: 'str', implementation: 'str', input_size: 'tuple[int, int]', artifact_path: 'str', aliases: 'tuple[str, ...]' = (), description: 'str' = '', base_url: 'str | None' = None)[source]

Bases: object

Parameters:
  • model_id (str)

  • implementation (str)

  • input_size (tuple[int, int])

  • artifact_path (str)

  • aliases (tuple[str, ...])

  • description (str)

  • base_url (str | None)

model_id: str
implementation: str
input_size: tuple[int, int]
artifact_path: str
aliases: tuple[str, ...] = ()
description: str = ''
base_url: str | None = None
property filename: str
opendetect.download_model(model, *, cache_dir=None, force=False, show_progress=True, timeout_sec=60)[source]
Parameters:
  • model (str | ModelSpec)

  • cache_dir (Path | str | None)

  • force (bool)

  • show_progress (bool)

  • timeout_sec (int)

Return type:

Path

opendetect.get_model_spec(model)[source]
Parameters:

model (str)

Return type:

ModelSpec

opendetect.list_model_ids()[source]
Return type:

list[str]

opendetect.list_models()[source]
Return type:

list[ModelSpec]

opendetect.load_detector(model='rfdetr-m', **kwargs)[source]
Parameters:

model (str)

Return type:

Detector

opendetect.model_url(spec, base_url=None)[source]
Parameters:
Return type:

str

Detector

class opendetect.detector.Detector(model='rfdetr-m', *, model_path=None, input_size=None, hardware_acceleration=True, tensor_rt=False, mixed_precision=False, threshold=0.3, num_select=300, class_ids=None, auto_download=True, cache_dir=None, show_download_progress=False)[source]

Bases: object

Parameters:
  • model (str)

  • model_path (str | Path | None)

  • input_size (tuple[int, int] | None)

  • hardware_acceleration (bool)

  • tensor_rt (bool)

  • mixed_precision (bool)

  • threshold (float)

  • num_select (int)

  • class_ids (list[int] | None)

  • auto_download (bool)

  • cache_dir (str | Path | None)

  • show_download_progress (bool)

property backend: DetectorModel
property class_names: list[str] | None
resolve_class_ids_from_names(names)[source]
Parameters:

names (list[str])

Return type:

list[int]

set_class_filter(class_ids)[source]
Parameters:

class_ids (list[int] | None)

Return type:

list[int] | None

list_classes()[source]
Return type:

list[tuple[int, str]]

predict(image, *, color='bgr')[source]
Parameters:
  • image (numpy.ndarray)

  • color (str)

Return type:

dict[str, numpy.ndarray]

annotate(image, detections=None, *, color='bgr')[source]
Parameters:
  • image (numpy.ndarray)

  • detections (dict[str, numpy.ndarray] | None)

  • color (str)

Return type:

numpy.ndarray

predict_and_annotate(image, *, color='bgr')[source]
Parameters:
  • image (numpy.ndarray)

  • color (str)

Return type:

tuple[dict[str, numpy.ndarray], numpy.ndarray]

infer_image_file(image_path, *, output_path=None)[source]
Parameters:
  • image_path (str | Path)

  • output_path (str | Path | None)

Return type:

tuple[dict[str, numpy.ndarray], numpy.ndarray]

infer_video_file(video_path, *, output_path, max_frames=None)[source]
Parameters:
  • video_path (str | Path)

  • output_path (str | Path)

  • max_frames (int | None)

Return type:

int

opendetect.detector.load_detector(model='rfdetr-m', **kwargs)[source]
Parameters:

model (str)

Return type:

Detector

Registry and Download

class opendetect.registry.ModelSpec(model_id: 'str', implementation: 'str', input_size: 'tuple[int, int]', artifact_path: 'str', aliases: 'tuple[str, ...]' = (), description: 'str' = '', base_url: 'str | None' = None)[source]

Bases: object

Parameters:
  • model_id (str)

  • implementation (str)

  • input_size (tuple[int, int])

  • artifact_path (str)

  • aliases (tuple[str, ...])

  • description (str)

  • base_url (str | None)

model_id: str
implementation: str
input_size: tuple[int, int]
artifact_path: str
aliases: tuple[str, ...] = ()
description: str = ''
base_url: str | None = None
property filename: str
opendetect.registry.model_base_url()[source]
Return type:

str

opendetect.registry.model_url(spec, base_url=None)[source]
Parameters:
Return type:

str

opendetect.registry.list_models()[source]
Return type:

list[ModelSpec]

opendetect.registry.list_model_ids()[source]
Return type:

list[str]

opendetect.registry.default_model_id(implementation)[source]
Parameters:

implementation (str)

Return type:

str

opendetect.registry.resolve_model_id(model)[source]
Parameters:

model (str)

Return type:

str

opendetect.registry.get_model_spec(model)[source]
Parameters:

model (str)

Return type:

ModelSpec

opendetect.registry.get_model_spec_by_id(model_id)[source]
Parameters:

model_id (str)

Return type:

ModelSpec

opendetect.download.default_cache_dir()[source]
Return type:

Path

opendetect.download.download_url_to_file(url, destination, *, expected_sha256=None, show_progress=True, timeout_sec=60)[source]
Parameters:
  • url (str)

  • destination (Path)

  • expected_sha256 (str | None)

  • show_progress (bool)

  • timeout_sec (int)

Return type:

Path

opendetect.download.download_model(model, *, cache_dir=None, force=False, show_progress=True, timeout_sec=60)[source]
Parameters:
  • model (str | ModelSpec)

  • cache_dir (Path | str | None)

  • force (bool)

  • show_progress (bool)

  • timeout_sec (int)

Return type:

Path