Skip to content

Analysis

segmentation.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)
    "intersection_threshold": float, # Object label 또는 prediction의 correctness 판정 threshold 입니다.
                                # 값은 [0.0, 1.0] 사이의 실수로 1에 가까울수록 과검과 미검이 많아집니다. (default 0.3)
    "inference_options": dict  | None, # 인퍼런스 옵션 config (default None). 구조는 `get_default_inference_option`의 Keys 참고.
}

required

Returns:

Name Type Description
AnalysisHandler AnalysisHandler

build가 완료된 segmentation.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.mask": bool,  # (default True, output 중 mask를 계산할 지 여부. True인 경우 계산)
    "outputs.scoremap": bool,  # (default True, output 중 scoremap을 계산할 지 여부. True인 경우 계산)
    "outputs.objects": bool,  # (default True, output 중 objects를 계산할 지 여부. True인 경우 계산)
    "params.object_boundary_threshold": list[int],  # mask를 계산할 때 적용되며, 각 클래스별로 픽셀의 스코어값이 threshold보다 작은 경우 스코어가 0으로 치환 됩니다.
                                                    # 각 값은 [0, 255] 범위의 정수. (default [100, ... , 100])
                                                    # background(0번 클래스)의 값은 변경할 수 없습니다.
    "params.calc_object_area_and_apply_threshold": bool,  # True인 경우 object마다 area(=픽셀수)를 계산하고 object_area_threshold를 적용합니다.
                                                          # outputs.objects가 True일때만 적용.
                                                          # (default True)
    "params.calc_object_score_and_apply_threshold": bool,  # True인 경우 object마다 평균 score를 계산하고 object_score_threshold를 적용합니다.
                                                           # outputs.objects가 True일때만 적용.
                                                           # (default True)
    "params.object_area_threshold": list[int],  # 각 클래스별로 예측된 object의 면적이 threshold보다 작은 경우 필터링 됩니다. 각 값은 0 이상의 정수. (default [0, ... , 0])
                                                # background(0번 클래스)의 값은 변경할 수 없습니다.
    "params.object_score_threshold": list[float],  # 각 클래스별로 예측된 object의 평균 score가 threshold 보다 작은 경우 필터링 됩니다. 각 값은 [0.0, 255.0] 범위의 실수. (default [0.0, ... , 0.0])
                                                   # background(0번 클래스)의 값은 변경할 수 없습니다.
    "params.num_workers": int, # 동시성 프로그래밍에 적용되는 File I/O를 위한 worker thread의 갯수입니다.
                               # (default 12)
}

사용 예시:

handler.get_default_inference_option(key="outputs.mask")
handler.set_inference_option(key="outputs.mask", 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 중 output.mask=True & outputs.objects=True 여야 합니다.

Note2

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

segmentation.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 (including background class)
    "intersection_threshold": float, # Object label 또는 prediction의 correctness 판정 threshold 입니다.
                                # 값은 [0.0, 1.0] 사이의 실수로 1에 가까울수록 과검과 미검이 많아집니다. (default 0.3)
}

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 인 경우에만 존재
    "pixel/accuracy": float,  # pixel-wise accuracy
    "pixel/mean_iou": float,  # 각 class 별 iou 평균 (class의 균형을 강조)
    "pixel/overall_iou": float,  # 전체 클래스의 TP, FP, FN을 합산한 후 한 번만 IoU 계산한 값 (보조 지표로써 활용) -> TP / (TP + FP + FN)
        # 보조 지표로 활용하는 이유: test 시 특정 클래스가 존재하지 않을 때 예측 값이 존재한다면, 해당 클래스의 iou는 0이 되어 전체 mean_iou에 영향을 미침.
    "pixel/class_{idx}_iou": float,  # 각 {idx} class 별 pixel iou

    # labeled=True 인 경우에만 존재
    # accuracy
    "object/accuracy": float,  # object-wise accuracy
    # underkill (각 class별 underkill ratio는 class_{idx}_underkill / class_{idx}_num_labels 로 구할 수 있음.)
    "object/underkill": int,  # 라벨 object 중 검출하지 못한 라벨의 개수 (미검)
    "object/class_{idx}_underkill": int,  # 클래스가 idx인 라벨 object 중 검출하지 못한 라벨의 개수
    "object/class_{idx}_num_labels": int, # 클래스가 idx인 라벨 object의 개수
    # overkill (각 class별 overkill ratio는 class_{idx}_overkill / class_{idx}_num_predictions 로 구할 수 있음.)
    "object/overkill": int,  # 예측 object 중 틀린 예측의 개수 (과검)
    "object/class_{idx}_overkill": int,  # 클래스를 idx로 예측한 object 중 틀린 예측의 개수
    "object/class_{idx}_num_predictions": int,  # 클래스를 idx로 예측한 object의 개수
    # confusion matrix
    "object/confusion_matrix": list[list[int]],  # object-wise confusion matrix
        [
            [0, 1, 0, 1],  # 과검. class1로 예측한 과검 1개, class3으로 예측한 과검 1개.
            [1, 2, 0, 0],  # 라벨이 class1인 object 중에 미검 1개, 맞춘 것 2개
            [2, 0, 3, 0],  # 라벨이 class2인 object 중에 미검 2개, 맞춘 것 3개
            ..., # n_classes 만큼 반복
        ]
}