-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain.py
84 lines (77 loc) · 2.48 KB
/
train.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""Entry point to model training and evaluation."""
from argparse import ArgumentParser, BooleanOptionalAction
from superphot_plus.config import SuperphotConfig
from superphot_plus.trainer import SuperphotTrainer
import numpy as np
def extract_cmd_args():
"""Extracts the script command-line arguments."""
default_config = SuperphotConfig(create_dirs=False)
parser = ArgumentParser(
description="Entry point to train and evaluate models using K-Fold cross validation",
)
parser.add_argument(
"--input_csvs",
help="List of CSVs containing light curve data (comma separated)",
default=",".join(default_config.input_csvs),
)
parser.add_argument(
"--sampler",
help="Name of the sampler to load fits from",
choices=["dynesty", "nuts", "svi"],
default="dynesty",
)
parser.add_argument(
"--model_type",
help="Name of the model type to train",
choices=["LightGBM", "MLP"],
default="LightGBM",
)
parser.add_argument(
"--include_redshift",
help="If flag is set, include redshift data for training",
default=False,
action=BooleanOptionalAction,
)
parser.add_argument(
"--extract_wc",
help="If flag is set, extract wrongly classified samples",
default=False,
action=BooleanOptionalAction,
)
parser.add_argument(
"--probs_file",
help="File to log test probability results",
default=default_config.probs_fn,
)
parser.add_argument(
"--fits_dir",
help="Directory holding fit parameters",
default=default_config.fits_dir,
)
parser.add_argument(
"--config_name",
help="The name of the file containing the model configuration",
required=True,
)
parser.add_argument(
"--load_checkpoint",
help="If set, load pretrained model for the respective configuration",
default=False,
action=BooleanOptionalAction,
)
return parser.parse_args()
if __name__ == "__main__":
args = extract_cmd_args()
trainer = SuperphotTrainer(
config_name=args.config_name,
fits_dir=args.fits_dir,
sampler=args.sampler,
model_type=args.model_type,
include_redshift=args.include_redshift,
probs_file=args.probs_file,
)
trainer.run(
input_csvs=args.input_csvs.split(","),
extract_wc=args.extract_wc,
load_checkpoint=args.load_checkpoint,
)