Inference
rotated.InferenceHandler
학습한 Rotated Object Detection 모델을 사용하여 검사를 하기 위한 InferenceHandler 클래스입니다.
build(config)
classmethod
InferenceHandler 클래스의 인스턴스를 생성합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config |
Dict
|
InferenceHandler를 build 하기 위한 config가 담겨 있는 dictionary 입니다. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
InferenceHandler |
InferenceHandler
|
빌드가 완료된 rotated.InferenceHandler 클래스의 인스턴스를 반환합니다. |
get_default_inference_option(key)
inference_option의 기본 설정 값을 반환합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key |
str
|
옵션 key |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
옵션 value |
Keys
{
"outputs.time": bool, # (default False, 인퍼런스 시 각 요소에 걸린 시간 측정 여부. True인 경우 측정)
"params.batch_size": int, # `infer_and_postprocess`에 한 번에 입력할 수 있는 최대 이미지 개수 입니다.
# 파라미터가 변경되는 경우 해당 값으로 warmup을 수행합니다.
# (default 1)
"params.confidence_threshold": float, # NMS를 수행할 때 사용할 confidence threshold 입니다. (default 0.25)
"params.max_num_of_detections": int, # NMS를 수행할 때 사용할 최대 detection 개수 입니다. (default 300)
}
get_inference_option(key)
set_inference_option(key, value)
Inference & postprocess 옵션을 설정합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key |
str
|
설정하고자 하는 옵션 key 입니다. |
required |
value |
Any
|
설정하고자 하는 옵션 value 입니다. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
None |
Keys
get_default_inference_option과 동일합니다.
infer_and_postprocess(images)
image의 List를 입력으로 받아 모델 인퍼런스와 후처리를 수행합니다. (for Runtime) 실시간 검사를 위해 연산 과정이 최적화되어 있으며, 중간 결과를 제거하고 postprocess 최종 결과만을 반환합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images |
Union[List[ndarray], List[str]]
|
|
required |
- |
List[ndarray]
|
numpy image가 들어있는 List 입니다. 각 image는 다음 제약 조건을 갖습니다. data type: uint8, uint16 channel: H x W / H x W x 1 - Gray H x W x 3 - RGB H x W x 4 - RGBA |
required |
- |
List[str]
|
image 경로가 들어있는 List 입니다. |
required |
Returns:
| Type | Description |
|---|---|
List[Dict]
|
List[Dict]: image의 postprocess 결과들이 들어있는 List 입니다. |
List[Dict]
|
```python |
List[Dict]
|
[ { # 아래 키들 중 inference_options에 설정된 출력 값(outputs)들만 포함. "detected_objects: [ # List[Dict], 설정된 object_score_threshold, object_area_threshold, max_num_of_detected_objects 의해 필터된 예측 bbox 리스트 { "bounding_box": List[float], # 예측된 bounding box의 coordinate, [left, top, width, height, radian] "class_index": int, # 예측된 bounding box의 class index "score": int, # 예측된 bounding box의 score } ] "time": { # inference에 소요된 시간을 담고있는 dictionary 입니다. (단위: ms) "imread_time": float, # 실제 image를 load하여 연구팀이 사용하는 image format (numpy)으로 변경하기까지 걸리는 시간 (각 이미지 별로 걸리는 시간) "inference_time": float, # resize, padding, tensorize, network forward 등을 포함하는 시간 (각 이미지 별로 걸리는 시간) "post_processing_time": float, # postprocess에 걸린 시간 (각 이미지 별로 걸리는 시간) }, }, ..., # times number of images |
List[Dict]
|
] |
List[Dict]
|
``` |
warmup()
현재 설정된 inference 옵션을 바탕으로 warmup을 수행합니다.
warmup은, 현재 inference_option이 잘 동작하는지 확인 + GPU를 첫 호출시 속도가 느린 이슈를 해결하기 위해,
현재 inference_option에 맞춰 더미 입력에 대한 InferenceHandler.infer_and_postprocess를 호출합니다.