InferenceHandler
safety.engine.api.InferenceHandler
NPU edge 추론 기반으로 Safety 기능을 수행하는 InferenceHandler class 입니다.
Usage
demo/inference.py 참고
build(config)
classmethod
InferenceHandler instance를 생성합니다.
Parameters:
Returns:
| Name | Type | Description |
|---|---|---|
InferenceHandler |
InferenceHandler
|
build가 완료된 instance. |
Note
default_alarm_options, default_object_options는 API에서 기본적으로 비활성화합니다 (enabled=False).
infer(images, camera_ids, timestamps)
현재 설정된 inference 옵션을 바탕으로 inference를 수행합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
list[ndarray]
|
inference를 수행할 BGR uint8 image list (shape: [H, W, 3]) |
required |
camera_ids
|
list[int]
|
images의 각 image에 대한 camera_id list |
required |
timestamps
|
list[int]
|
images의 각 image에 대한 timestamp list (단위: 밀리초) |
required |
Returns:
Raises:
| Type | Description |
|---|---|
InvalidNumberOfInputsError
|
images, camera_ids, timestamps의 길이가 서로 다를 때 |
UnregisteredCameraIdError
|
등록되지 않은 camera_id가 포함된 경우 |
InvalidTimestampError
|
timestamp가 음수이거나 같은 camera_id에 대해 중복일 때 |
register_camera(camera_id)
검사할 camera_id를 등록합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
camera_id
|
int
|
등록할 camera_id |
required |
Raises:
| Type | Description |
|---|---|
InvalidCameraIdError
|
camera_id가 비음수 int가 아닐 때 |
AlreadyRegisteredCameraIdError
|
이미 등록된 camera_id일 때 |
release_camera(camera_id)
등록된 camera_id를 해제합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
camera_id
|
int
|
해제할 camera_id |
required |
Raises:
| Type | Description |
|---|---|
UnregisteredCameraIdError
|
등록되지 않은 camera_id일 때 |
get_registered_camera_ids()
get_default_tracker_option(camera_id)
기본 tracker option을 반환합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
camera_id
|
int
|
사용하지 않음, API 일관성을 위해 존재. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: tracker option |
get_tracker_option(camera_id)
등록된 camera_id에 대한 tracker option을 반환합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
camera_id
|
int
|
tracker option을 반환할 camera_id |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: tracker option |
Raises:
| Type | Description |
|---|---|
UnregisteredCameraIdError
|
등록되지 않은 camera_id일 때 |
set_tracker_option(camera_id, tracker_option)
등록된 camera_id에 대한 tracker option을 설정합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
camera_id
|
int
|
tracker option을 설정할 camera_id |
required |
tracker_option
|
dict[str, Any]
|
tracker option |
required |
Raises:
| Type | Description |
|---|---|
UnregisteredCameraIdError
|
등록되지 않은 camera_id일 때 |
get_default_object_options(camera_id)
기본 object options을 반환합니다 (enabled=False 강제).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
camera_id
|
int
|
사용하지 않음, API 일관성을 위해 존재. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict]
|
dict[str, dict]: 각 object class별 default option dict |
Usage
Note
enabled=False 인 class 의 object 는 event/alarm 평가 단계에서 drop —
events / alarms / event_status 키가 추가되지 않습니다. detection 자체는
detected_objects 에 그대로 남아 caller 가 raw bbox 를 render 할 수 있습니다.
area_threshold 미만 / score_threshold 미만 / frame 면적의 80% 초과 도
동일하게 drop.
get_object_options(camera_id)
등록된 camera_id에 대한 object options을 반환합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
camera_id
|
int
|
object options을 반환할 camera_id |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict]
|
dict[str, dict]: object options |
Raises:
| Type | Description |
|---|---|
UnregisteredCameraIdError
|
등록되지 않은 camera_id일 때 |
set_object_options(camera_id, object_options)
등록된 camera_id에 대한 object options을 설정합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
camera_id
|
int
|
object options을 설정할 camera_id |
required |
object_options
|
dict[str, dict]
|
object options |
required |
Raises:
| Type | Description |
|---|---|
UnregisteredCameraIdError
|
등록되지 않은 camera_id일 때 |
get_default_event_options(camera_id)
기본 event options을 반환합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
camera_id
|
int
|
사용하지 않음, API 일관성을 위해 존재. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict]
|
dict[str, dict]: API event type을 key로 하는 default event options |
get_event_options(camera_id)
등록된 camera_id에 대한 event options을 반환합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
camera_id
|
int
|
event options을 반환할 camera_id |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict]
|
dict[str, dict]: API event type을 key로 하는 event options |
Raises:
| Type | Description |
|---|---|
UnregisteredCameraIdError
|
등록되지 않은 camera_id일 때 |
set_event_options(camera_id, event_options)
등록된 camera_id에 대한 event options을 설정합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
camera_id
|
int
|
event options을 설정할 camera_id |
required |
event_options
|
dict[str, dict]
|
API event type을 key로 하는 event options |
required |
Raises:
| Type | Description |
|---|---|
UnregisteredCameraIdError
|
등록되지 않은 camera_id일 때 |
get_default_alarm_options(camera_id)
기본 alarm options을 반환합니다 (enabled=False 강제).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
camera_id
|
int
|
사용하지 않음, API 일관성을 위해 존재. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict]
|
dict[str, dict]: API event type을 key로 하는 default alarm options |
get_alarm_options(camera_id)
등록된 camera_id에 대한 alarm options을 반환합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
camera_id
|
int
|
alarm options을 반환할 camera_id |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict]
|
dict[str, dict]: API event type을 key로 하는 alarm options |
Raises:
| Type | Description |
|---|---|
UnregisteredCameraIdError
|
등록되지 않은 camera_id일 때 |
set_alarm_options(camera_id, alarm_options)
등록된 camera_id에 대한 alarm options을 설정합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
camera_id
|
int
|
alarm options을 설정할 camera_id |
required |
alarm_options
|
dict[str, dict]
|
API event type을 key로 하는 alarm options |
required |
Raises:
| Type | Description |
|---|---|
UnregisteredCameraIdError
|
등록되지 않은 camera_id일 때 |
get_monitoring_area(camera_id)
등록된 camera_id 에 대한 monitoring area 를 반환합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
camera_id
|
int
|
monitoring area 를 반환할 camera_id. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[list[list[int]]]]
|
Raises:
| Type | Description |
|---|---|
UnregisteredCameraIdError
|
등록되지 않은 camera_id 일 때. |
set_monitoring_area(camera_id, monitoring_area)
등록된 camera_id 에 대한 monitoring area 를 설정합니다.
includes 가 비어있으면 (또는 키 자체 미지정) include 검사는 스킵되어 모든 obj 가 통과합니다.
excludes 가 비어있으면 exclude 검사는 스킵됩니다. 둘 다 비어있으면 filter 는 no-op 입니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
camera_id
|
int
|
monitoring area 를 설정할 camera_id. |
required |
monitoring_area
|
dict[str, list[list[list[int]]]]
|
형태는
:meth: |
required |
Raises:
| Type | Description |
|---|---|
InvalidMonitoringAreaError
|
monitoring_area dict 가 아니거나 polygon 형식이 잘못됐을 때. |
UnregisteredCameraIdError
|
등록되지 않은 camera_id 일 때. |
get_default_inference_option(model, key)
(model, key) 에 대한 inference option 의 기본값을 반환합니다.
Inference option 은 모델 재컴파일 없이 런타임에 후처리 knob 을 조정하는 global API 입니다 (camera_id 없음). 지원 범위는 다음과 같습니다.
Parameters:
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
|
Raises:
| Type | Description |
|---|---|
InvalidInferenceOptionError
|
지원하지 않는 |
get_inference_option(model, key)
(model, key) 에 대한 현재 설정된 inference option 값을 반환합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
:meth: |
required |
key
|
str
|
옵션 키. :meth: |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
현재 값의 사본. |
Raises:
| Type | Description |
|---|---|
InvalidInferenceOptionError
|
지원하지 않는 |
set_inference_option(model, key, value)
(model, key) 에 대한 inference option 을 설정합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
:meth: |
required |
key
|
str
|
옵션 키. :meth: |
required |
value
|
Any
|
설정할 값. 형식/범위는 |
required |
Raises:
| Type | Description |
|---|---|
InvalidInferenceOptionError
|
지원하지 않는 |
InvalidMlcFilterThresholdError
|
|