Train VAD
SaigeVAD.VadTrainer
Bases: VadTrainer
VAD 모델을 학습시키기 위한 VadTrainer class입니다. - 참고: main_train_vad.py를 사용하여 python 환경에서 train pipeline을 실행할 수 있습니다. Usage:
from SaigeVAD.engine.saigevad_api import VadTrainer, VadTrainConfigMaker
checkpoint_path = "./sample.saigevad"
password = "saigevad_model" #None일 경우 암호화 X
config = {
"train_data": {
"clip_path": "/NFS/database_personal/bts/VAD/voc/221207/vad_training_sample/clips",
"frame_dir": [
"test1_00",
"test1_01",
"test1_04",
"test1_06",
],
},
"config": {
"cycle_list": [
"test1_00-00000000", # {clip name}-{start frame cycle 1}
"test1_00-00000027", # {clip name}-{end frame cycle 1}
"test1_00-00000035", # {clip name}-{start frame cycle 2}
"test1_00-00000059", # {clip name}-{end frame cycle 2}
"test1_04-00000000", # {clip name}-{start frame cycle 3}
"test1_04-00000029", # {clip name}-{end frame cycle 3}
],
"iteration": 5000,
"network_model": "shallow",
"num_workers": 8,
},
"metadata": {
"common_settings": {
"roi_xyxy": [1149, 557, 1278, 746], # (left, top, right, bottom)
"fixed_roi_xyxy": [1200, 557, 1458, 909], # (left, top, right, bottom): default to None
"fps": 25,
"mask_mode": None, # "binary", "semi_binary
"cycle_length": 29, # int
},
},
}
# config 변환
error, train_config_maker = VadTrainConfigMaker.build(config=config)
error, config_dict = train_config_maker.make_train_config()
# Trainer 빌드
error, trainer = VadTrainer.build(config=config_dict)
# 0번 GPU로 이동
error, _= trainer.to_device(0)
# 1000 스텝 학습
for _ in range(1000):
error, train_result = trainer.train_one_step()
# weight sampling 수행
error, weight_sampling_result = trainer.process_weight_sampling()
# adaptive autoencoder 학습
error, _= trainer.train_adaptive_autoencoder()
# warm up 수행
error, _= trainer.warm_up()
# VAD 최종 체크포인트 저장
error, _= trainer.save_checkpoint(
checkpoint_path=checkpoint_path,
password=password,
)
build(config, task='developer')
classmethod
학습을 위해 VadTrainer class의 instance를 생성합니다.
Parameters:
Returns:
| Name | Type | Description |
|---|---|---|
VadTrainer |
학습 config가 담겨 있는 dictionary 입니다. |
to_device(device)
VadTrainer가 train 하는 device를 변경합니다. (gpu only)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device |
Union[int, str]
|
변경하고자 하는 device 입니다. |
required |
train_one_step()
VAD 학습을 1스텝 진행합니다.
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
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
|
np.ndarray: Weight sampling 관련 정보가 담겨있는 array입니다. |
train_adaptive_autoencoder()
Adaptive autoencoder 학습과정 전체를 수행합니다.
warm_up()
3개의 clip을 이용하여 warm up을 수행합니다. VAD 학습의 가장 마지막 과정입니다.
save_checkpoint(checkpoint_path, password=None)
현재 VadTrainer의 상태를 dictionary로 저장합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint_path |
str
|
checkpoint를 저장할 path 입니다. |
required |
password |
str
|
checkpoint 파일에서 중요한 정보를 암호화 하는데 사용되는 password 입니다. None이면 암호화하지 않습니다. Defaults to None. |
None
|