-
Notifications
You must be signed in to change notification settings - Fork 0
/
train
47 lines (34 loc) · 1.08 KB
/
train
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
#!/usr/bin/env python3.6
import logging
import os
import sys
import traceback
import papermill as pm
from pathlib import Path
logger = logging.getLogger(__name__)
error_file = "/opt/ml/output/failure"
output_directory = "/opt/ml/output"
model_directory = "/opt/ml/model"
code_directory = "/opt/program/src"
def main():
parameters = {}
try:
logger.debug("Start execution")
execute("notebook.ipynb", parameters)
logger.debug("End execution successfully")
except Exception:
os.makedirs(output_directory)
with open(error_file, "w") as f:
error = traceback.format_exc()
logger.exception("Error during execution:")
f.write(error)
sys.exit(255)
def execute(notebook, parameters={}):
Path(model_directory).mkdir(parents=True, exist_ok=True)
input_path = os.path.join(code_directory, notebook)
output_path = os.path.join(model_directory, notebook)
pm.execute_notebook(
input_path, output_path, parameters=parameters, cwd=code_directory
)
if __name__ == "__main__":
main()