Skip to content

Analysis

detection.AnalysisHandler

모델을 빌드하지 않고 저장된 모델 인퍼런스 결과를 이용해서 analysis를 수행하는 클래스입니다.

Usage

demo/analysis.py 참고

build(config) classmethod

AnalysisHandler class의 instance를 생성합니다.

Parameters:

Name Type Description Default
config Dict

AnalysisHandler를 build 하기 위한 config가 담겨 있는 dictionary 입니다.

{
    "n_classes": int,  # number of data classes (including background class)
    "inference_options": Optional[Dict], # 인퍼런스 옵션 config (default None). 구조는 `get_default_inference_option`의 Keys 참고.
}

required

Returns:

Name Type Description
AnalysisHandler AnalysisHandler

build가 완료된 detection.AnalysisHandler class의 instance를 반환합니다.

get_default_inference_option(key)

Postprocess 옵션의 기본 설정 값을 반환합니다.

Parameters:

Name Type Description Default
key str

옵션 key

required

Returns:

Name Type Description
Any Any

옵션 value

Keys

사용 가능한 key와 value 목록:

{
    "outputs.detected_boxes": bool,  # (default True, 예측된 박스들을 스코어, 면적, 개수로 필터링을 할 지 여부. True인 경우 필터링)
    "outputs.time": bool,  # (default False, 인퍼런스 시 각 요소에 걸린 시간 측정 여부. True인 경우 측정)
    "params.object_score_threshold": List[int],  # 각 클래스의 score threshold 값. 예측 box의 score가 threshold보다 작은 경우 필터링 됩니다.
                                          # 각 값은 [0, 100] 범위의 정수. (default [30, ... , 30])
    "params.object_area_threshold": List[int],  # 각 클래스의 area threshold 값. 예측 box의 면적이 threshold보다 작은 경우 필터링 됩니다.
                                         # 각 값은 0 이상의 정수. (default [0, ... , 0])
    "params.max_num_boxes": List[int],  # 각 클래스의 최대 예측 박스 개수. 예측 box의 개수가 이 값을 넘을 경우 score가 낮은 순으로 제거됩니다.
                                        # 각 값은 -1 이상의 정수이며, 값이 -1인 경우 개수 필터링을 적용하지 않습니다. (default [-1, ... , -1])
}

사용 예시:

error, _ = handler.get_default_inference_option(key="outputs.detected_boxes")
error, _ = handler.set_inference_option(key="outputs.detected_boxes", value=False)

get_inference_option(key)

현재 설정된 postprocess 옵션 값을 읽습니다.

Parameters:

Name Type Description Default
key str

옵션 key

required

Returns:

Name Type Description
Any Any

옵션 value

Keys

get_default_inference_option과 동일합니다.

set_inference_option(key, value)

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과 동일합니다.

analyze(images, labeled)

저장된 network output으로 부터 images들에 대한 analysis 결과 계산

Args & Returns: InferenceHandler.analyze()와 동일하며, 결과 predictions에서 time은 제외됩니다.

Note1

analyze() 함수를 사용하기 위해서는 inference_options 중 outputs.detected_boxes=True 여야 합니다.

Note2

모델 인퍼런스까지 재수행하려면 InferenceHandler.analyze()를 사용하세요.

detection.SummaryHandler

모델을 빌드하지 않고 저장된 analysis 결과를 이용해서 analysis summary를 수행하는 클래스입니다.

Usage

demo/inference.py & demo/analysis.py 참고

build(config) classmethod

SummaryHandler class의 instance를 생성합니다.

Parameters:

Name Type Description Default
config Dict

SummaryHandler를 build 하기 위한 config가 담겨 있는 dictionary 입니다.

{
    "n_classes": int,  # number of data classes
}

required

Returns:

Name Type Description
SummaryHandler SummaryHandler

build가 완료된 segmentation.SummaryHandler class의 instance를 반환합니다.

summarize_analysis(images, labeled)

images들에 대한 analysis summary 계산

Parameters:

Name Type Description Default
images Dict[str, Dict]

analysis에 사용할 데이터 리스트.

{
    "{image_id}": {
        "save_dir": str,  # 해당 이미지의 analysis 결과 저장 directory
    },
    ...,  # times number of images
}

required
labeled bool

label 존재 여부. label 존재 여부에 따라 analysis 결과 Dict 구성 요소가 달라집니다.

required

Returns:

Name Type Description
Dict Dict

images들에 대한 analysis summary

{
    # labeled=True 인 경우에만 존재
    # accuracy
    "object/accuracy": float,  # object-wise accuracy
    # underkill
    "object/underkill": int,  # 라벨 object 중 검출하지 못한 라벨의 개수 (미검)
    "object/class_{idx}_underkill": int,  # 클래스가 idx인 라벨 object 중 검출하지 못한 라벨의 개수
    # overkill
    "object/overkill": int,  # 예측 object 중 틀린 예측의 개수 (과검)
    "object/class_{idx}_overkill": int,  # 클래스가 idx인 예측 object 중 틀린 예측의 개수
    # f1
    "object/mean_f1": float,  # object-wise mean f1-score
    "object/class_{idx}_f1": float,  # 클래스가 idx인 box에 대한 object-wise mean f1-score
    # confusion matrix
    "object/confusion_matrix": List[List[int]],  # object-wise confusion matrix, 마지막 dimension은 wrong을 의미하는 etra dimension (n_class + 1)
        [
            # n_class == 3이라고 할 때
            [1, 0, 0, 1],  # 라벨이 class0인 object 중 미검 1개, 맞춘것 1개
            [0, 2, 0, 4],  # 라벨이 class2인 object 중에 미검 4개, 맞춘 것 2개
            [0, 0, 3, 0],  # 라벨이 class2인 object 중에 미검 2개, 맞춘 것 3개
            [5, 0, 3, 0],  # class0이라고 예측한 과검 5개, class2라고 예측한 과검 3개
        ]
}