Train
core.Trainer
AnomalyDetction 모델을 학습시키기 위한 Trainer class 입니다.
Usage
demo/train.py 참고
build(config, data)
classmethod
Trainer class의 instance를 생성합니다.
Parameters:
Returns:
| Name | Type | Description |
|---|---|---|
Trainer |
Trainer
|
build가 완료된 core.Trainer class의 instance를 반환합니다. |
to_device(device)
Trainer의 device를 변경합니다. (cpu/gpu)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device |
Union[torch.device, str, int]
|
변경하고자 하는 device 입니다. int의 경우 해당 번호의 GPU, "cpu"(str)은 cpu를 사용합니다. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
None |
train_one_step()
post_train_process()
train을 마무리하기 위한 작업을 합니다. 주로 threshold를 자동으로 계산해줍니다.
Returns:
validation_enabled()
Trainer가 validation이 가능한지 bool로 반환합니다.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Trainer가 validation이 가능하면 True를, 불가능하다면 False를 반환합니다. |
get_validation_schedule(total_iterations, density_level)
classmethod
validation을 수행할 step을 반환합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
total_iterations |
int
|
총 학습 스텝입니다. |
required |
density_level |
int
|
validation을 수행할 step의 밀도입니다. [0, 1, 2] 중 1가지이며 작을수록 validation을 더 자주 수행합니다. 기본값은 1입니다. |
required |
Returns:
| Type | Description |
|---|---|
List[int]
|
List[int]: validation을 수행할 step이 담긴 list를 반환합니다. |
validate()
Validation을 수행하고, 결과를 리턴합니다.
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
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:
| Name | Type | Description |
|---|---|---|
None |
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 입니다. |