forked from cdt-data-science/cluster-scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
train.py
55 lines (48 loc) · 1.79 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
#!/usr/bin/env python3
"""A dummy script for 'training' a model with specified arguments"""
import argparse
import os
import random
import time
from glob import glob
def construct_parser():
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input', required=True, help='Path to the '
'input data for the model to read')
parser.add_argument('-o', '--output', required=True, help='Path to the '
'directory to write output to')
parser.add_argument("--lr", type=float, default=1e-4,
help="learning rate of adam")
parser.add_argument("--weight_decay", type=float, default=0.01,
help="weight_decay of adam")
return parser
def main(args):
print('Totally learning model...yup')
inpath = args.input
outpath = args.output
lr = args.lr
wd = args.weight_decay
print(f'Reading data from {inpath}')
for path in glob(f'{inpath}/*'):
print(f'Nommed: {path}')
print(f"I'm gonna use a learning rate of {lr} and weight decay of {wd}")
for ii in range(10):
print(f'Training model {ii * "."}', end='\r')
# model.learn()
time.sleep(1)
else:
print(f'Training model {ii * "."}')
accuracy = random.random()
print(f'The model accuracy was {accuracy}...very precision, such learn.')
if not os.path.exists(outpath):
print(f"{outpath} doesn't exist, creating it for you")
os.makedirs(outpath)
print(f'Writing this important information to {outpath}')
filename = f'expt_{lr}_{wd}.log'
with open(f'{outpath}/{filename}', 'w') as fh:
print(accuracy, file=fh)
print("That's all folks")
if __name__ == '__main__':
parser = construct_parser()
args = parser.parse_args()
main(args)