Skip to content

Active Learning (Query)

mlops.segmentation.MLOpsActiveLearningHandler

Active Learning을 위한 data aquisition을 하는 ActiveLearningHandler class 입니다.

Usage
# 액티브 러닝 핸들러 빌드
handler_build_config = {
    "checkpoint_path": CHECKPOINT_PATH,
    "password": PASSWORD,
    "device": DEVICE,
    "label_ratio": LABEL_RATIO,
}
error, active_learning_handler = MLOpsActiveLearningHandler.build(handler_build_config)
assert error >= 0
print("Build MLOpsActiveLearningHandler")

# 인퍼런스 후, 버퍼에 결과 저장
n_unlabeled_data = len(DATA["unlabeled_images"])
for i in range(n_unlabeled_data):
    image_path = DATA["unlabeled_images"][i]["path"]
    error, _ = active_learning_handler.infer(images=[image_path])
    assert error >= 0
print(f"Infer and save {n_unlabeled_data} images.")

# 버퍼에 저장된 결과로, 쿼리 수행
error, output = active_learning_handler.query()
assert error >= 0
print(f"{len(output)} images are selected by querying")
print(output)

# 쿼리 옵션 변경
query_options = {"label_ratio": 0.05}
error, _ = active_learning_handler.set_options(query_options)
print(f"Set query options:")
for key, value in query_options.items():
    print(f"{key}: {value}")

# 버퍼에 저장된 결과로, 쿼리 재수행
error, output = active_learning_handler.query()
assert error >= 0
print(f"{len(output)} images are selected by querying")
print(output)

# 결과 버퍼 초기화
error, _ = active_learning_handler.reset_results()
assert error >= 0
print("Reset infered results.")

build(config) classmethod

AciveLearningHandler class의 instance를 생성합니다.

Parameters:

Name Type Description Default
config Dict

AciveLearningHandler를 build 하기 위한 config가 담겨 있는 dictionary 입니다. { "checkpoint_path": str, # Uncertainty Model이 학습된 체크포인트 경로 "password": Optional[str], # 체크포인트 패스워드 (default None) "device": Union[int, str], # GPU 번호 (int) or "cpu" (str) (default "cpu") "label_ratio": float, # 전체 데이터 중 라벨링할 데이터의 비율 }

required

Returns:

Name Type Description
ActiveLearningHandler MLOpsActiveLearningHandler

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

infer(images)

image의 List를 입력으로 받아 task model과 uncertainty model을 인퍼런스하고 결과를 내부에 저장합니다.

Parameters:

Name Type Description Default
images Union[List[np.ndarray], List[str]]

List[np.ndarray]: numpy image가 들어있는 List 입니다. 각 image는 다음 제약 조건을 갖습니다. data type: uint8 channel: H x W / H x W x 1 - Gray H x W x 3 - RGB H x W x 4 - RGBA List[str]: image 경로가 들어있는 List 입니다.

required

query()

내부에 저장된 inference 결과들을 이용하여, inference 했던 데이터들 중 어떤 데이터를 라벨하는게 좋을지 추천해줍니다.

Returns:

Name Type Description
List List

라벨할 데이터의 index list

reset_results()

내부에 저장된 인퍼런스 결과를 지웁니다.

set_options(config)

Active Learning qeury 관련 option을 설정합니다.

Parameters:

Name Type Description Default
config Dict

설정하고자 하는 active learning 옵션 정보가 들어있는 dictonary 입니다. 지원하는 옵션은 다음과 같습니다. { "label_ratio": float, # 전체 데이터 중 라벨링할 데이터의 비율 }

required