-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlearn_seqs.py
More file actions
64 lines (48 loc) · 2.23 KB
/
learn_seqs.py
File metadata and controls
64 lines (48 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# ----------------------------------------------------------------------------------------------------------------------
'''
author: jaime cardenas
title: learn_seqs.py
description: script to train, validate, and test the model
'''
# ----------------------------------------------------------------------------------------------------------------------
from pathlib import Path
from box import Box
import argparse
import yaml
import os
from utils.train_utils.training_run import TrainingRun
# ----------------------------------------------------------------------------------------------------------------------
def main(args):
'''
main script that instantiates TrainingRun object to train and test the model.
'''
# initialize the training run
training_run = TrainingRun(args)
# ----------------------------------------------------------------------------------------------------------------------
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--config", type=Path, help="Path to the YAML config file")
config, _ = parser.parse_known_args()
def merge_dicts(defaults, overrides):
"""Recursively merges overrides into default config."""
merged = defaults.copy()
for key, value in overrides.items():
if isinstance(value, dict) and key in merged:
merged[key] = merge_dicts(merged[key], value) # recursive merge for nested dicts
else:
merged[key] = value # override value
return merged
default_config = Path(os.path.abspath(__file__)).parent / Path("config/train.yml")
if not default_config.exists():
raise FileNotFoundError(f"could not find path to default config at {default_config}.")
with open(default_config, "r") as d:
args = yaml.safe_load(d)
# Load YAML configuration if file exists
if config.config.exists():
with open(config.config, "r") as f:
user_args = yaml.safe_load(f)
args = merge_dicts(args, user_args) # have user configs override defaults, if custom config specified
# convert to box to have nested attributes that are easier to keep track of
args = Box(args)
main(args)
# ----------------------------------------------------------------------------------------------------------------------