-
Notifications
You must be signed in to change notification settings - Fork 10
/
model_spec.py
executable file
·40 lines (29 loc) · 1.02 KB
/
model_spec.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
"""
A very simple class to wrap a single run in a WorkUnit.
"""
import os
import pickle
class ModelSpec(object):
RESULTS_RELATIVE_DIR = os.environ['LOCAL_AZ_DIR'] + 'saved_models/'
def __init__(self, name, model_fn, epochs):
self.name = name
self.model_fn = model_fn
self.epochs = epochs
def get_directory(self):
return self.RESULTS_RELATIVE_DIR\
+ self.work_unit.get_directory()\
+ self.name + '/'
def get_results_obj_path(self):
return self.get_directory() + 'latest_results.pickle'
def get_results_obj(self):
results_obj_path = self.get_results_obj_path()
with open(results_obj_path) as f:
results_obj = pickle.load(f)
results_obj['spec_info'] = {
'work_spec_name': self.work_unit.work_spec.name,
'work_unit_name': self.work_unit.name,
'model_spec_name': self.name,
}
return results_obj
def create_model(self, *args):
return self.model_fn(*args)