콘텐츠로 이동

Inference

SaigeVAD.VadInferenceEngine

Bases: inference_engine_handler.VadInferenceEngineHandler

학습한 VAD 모델을 사용하여 검사를 하기 위핸 VadInferenceEngine class입니다. roi 보정 on/off를 위해서는 is_roi_calibration setter를 이용합니다.

Usage
from SaigeVAD.SaigeToolkit.SaigeToolkit.util.config import read_yml
from SaigeVAD.tools.config_maker import create_train_config_and_reference_images
from SaigeVAD.engine.saigevad_api import VadInferenceEngine

config_path = "./config/sample_inference_config_database.yml"
model_path = "./sample.saigevad"
password = "password" #or None
save_dir = "./test_results"

config = read_yml(config_path)

#config을 사용하는 경우 engine 빌드
error, vad_inference_engine = VadInferenceEngine.build(
                                                                model_path=None,
                                                                config=config,
                                                                password=password
                                                            )

#model file을 사용하는 경우
error, vad_inference_engine = VadInferenceEngine.build(
                                                                model_path=model_path,
                                                                password=password
                                                            )

# gpu assign
vad_inference_engine.to_device(device="0")

# critical_threshold 적용 (10으로 변경)
vad_inference_engine.n_sigma = 10

# ROI calibration 기능 Off (On은 True)
vad_inference_engine.is_roi_calibration = False

# N 개의 frame에 대하여 inference 수행
error, results = vad_inference_engine.inference(input_data, frame_timestamp)

# inference 결과로부터 heatmap 저장
error, heatmap_path_list = vad_inference_engine.save_heatmap(results, save_dir)

build(model_path, config=None, n_sigma=None, password=None) classmethod

검사를 위해 InferenceHandler class의 instance를 생성합니다. config 혹은 model_path 둘 중 하나는 필수입니다.

Parameters:

Name Type Description Default
model_path str

InferenceHandler를 build 하기 위한 VAD model path입니다.

required
config Dict

InferenceHandler를 build 하기 위한 config가 담겨 있는 dictionary 입니다.. Defaults to None.

None
n_sigma int

Threshold 계산을 위한 n_sigma 입니다. Defaults to None.

None
password str

VAD model 복호화를 위해 필요한 password입니다. Defaults to None.

None

Returns:

Name Type Description
VadInferenceEngine

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


to_device(device)

Engine이 검사하는 device를 변경합니다. (gpu only)

Parameters:

Name Type Description Default
device Union[int, str]

변경하고자 하는 device 입니다.

required

inference(input_data, frame_timestamp, profile_mode=False)

input image data에 대하여 검사를 수행합니다. 모델 파일에 clustering 관련 정보가 자동으로 clustering을 적용합니다.

Parameters:

Name Type Description Default
input_data Union[np.ndarray, torch.Tensor]

검사 대상 이미지입니다.

required
frame_timestamp List[str]

검사 이미지의 time stamp 입니다.

required
profile_mode bool

연구팀 디버깅을 위한 값입니다. Defaults to False.

False

Returns:

Name Type Description
ResultContainer ResultContainer

input_data에 대한 검사 결과가 들어있습니다.


save_heatmap(results, save_dir_path)

이상감지된 이미지에 대하여 heatmap을 저장합니다.

Parameters:

Name Type Description Default
results ResultContainer

검사 결과가 들어있습니다.

required
save_dir_path str

heatmap 이미지 저장을 위한 폴더 경로 입니다.

required

Returns:

Name Type Description
Dict Dict

heatmap 이미지 경로 정보를 담은 dictionary 입니다.

output = {
    "original_image": List[str], # original 이미지 경로 정보입니다.
    "heatmap_image": List[str], # heatmap 이미지 경로 정보입니다.
}