콘텐츠로 이동

Train

vims.Trainer

vims 모델을 학습시키기 위한 Trainer class 입니다.

Usage

demo/train.py 참고

build(config, data) classmethod

Trainer class의 instance를 생성합니다.

Parameters:

Name Type Description Default
config Dict

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

{
    "total_iterations": int,  # total training iterations
    "roi": Tuple[int, int, int, int],  # roi 셋팅. 이미지 내부에서 검사시 사용할 영역. (left, top, right, bottom)
    "batch_size": Optional[int],  # batch size. 제공하지 않으면 default batch size 사용. (default 16)
    "sequence_length": Optional[int],  # sequence length. 제공하지 않으면 default sequence length 사용. (default 64)
    "cycle_length": Optional[int], # 이미지 내에서 cycle 길이. end - start + 1.
}

required
data Dict

Trainer가 사용 할 train/validation data가 담겨 있는 dictionary 입니다.

{
    "train_images": List[List[str]],
    [
        [
            "image_dir",
            "image_dir",
        ],
        [
            "image_dir",
            "image_dir",
        ],
    ]
    "cycle_images": str, # template sampler 학습, motion paramter search에 사용할 이미지 폴더 경로 (2배 crop resize : 256*256) cycle_length * 2
}

required

Returns:

Name Type Description
Trainer Trainer

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

to_device(device)

Trainer의 device를 변경합니다. (cpu/gpu)

Parameters:

Name Type Description Default
device Union[device, str, int]

변경하고자 하는 device 입니다. int의 경우 해당 번호의 GPU를, "cpu" 문자열의 경우 cpu를 사용합니다.

required

Returns:

Name Type Description
None None

None

train_one_step()

학습을 1스텝 수행하고, 결과를 반환합니다.

Returns:

Name Type Description
Dict Dict

학습 결과가 들어있는 dictionary를 반환합니다.

{
    "step": int,  # 현재까지 진행된 총 학습 step.
    "epoch": int,  # 현재까지 진행된 총 학습 epoch.
    "epoch_step": int,  # 현재 epoch에서 몇 번째 step인지를 나타냄.
    "loss/total": float,  # 학습에 사용되는 모든 loss를 모두 더한 값.
    "step_time(sec)": float,  # 학습을 1 step 진행하는데 걸린 총 시간
    "data_time(sec)": float,  # 데이터를 로딩하는데 걸린 시간
    "model_time(sec)": float,  # 모델 학습에 걸린 시간
}

process_weight_sampling()

학습 데이터 전체에 대하여 weight sampling을 진행합니다.

Total train step 별 권장 weight sampling 마일스톤은 아래와 같습니다. - train_step 5000 : [1000, 3000] (default) - train_step 8000 : [1000, 3000, 6000] - train_step 10000 : [1000, 4000, 7000]

Returns:

Type Description
ndarray

None


train_adaptive_autoencoder()

Adaptive autoencoder 학습과정 전체를 수행합니다.


save_checkpoint(checkpoint_path, metadata=None, password=None)

현재 Trainer의 상태를 암호화하여 저장합니다.

Parameters:

Name Type Description Default
checkpoint_path str

checkpoint를 저장할 path 입니다.

required
metadata Optional[Dict]

checkpoint에 저장할 추가 metadata. Defaults to None.

None
password Optional[str]

checkpoint 파일에서 중요한 정보를 암호화 하는데 사용되는 password 입니다. None이면 암호화하지 않습니다. Defaults to None.

None

Returns: None: None

load_checkpoint(checkpoint_path, password=None)

저장한 checkpoint로부터 Trainer의 상태를 불러오고, metadata를 반환합니다.

Parameters:

Name Type Description Default
checkpoint_path str

load할 checkpoint가 저장 되어 있는 path 입니다.

required
password Optional[str]

checkpoint 파일에서 중요한 정보를 복호화 하는데 사용되는 password 입니다. None이면 복호화하지 않습니다. Defaults to None.

None

Returns:

Name Type Description
Dict Dict

save_checkpoint에서 저장했던 metadata 입니다.

warm_up()

3개의 clip을 이용하여 warm up을 수행합니다. VAD 학습의 가장 마지막 과정입니다.