-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
43 lines (37 loc) · 1.81 KB
/
main.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
"""
Created on 25/12/2018
@author: nidragedd
This is the main file to use
"""
import os
import argparse
from config import config
from config.config import Configuration
from models.train import trainer
from models.predict import magic_oracle
if __name__ == "__main__":
# Mandatory arguments to run the program
ap = argparse.ArgumentParser()
ap.add_argument("-m", "--model", required=True, help="Name of the model, must be a valid choice")
ap.add_argument("-o", "--objective", required=True, help="Choice between [train, predict]")
ap.add_argument("-w", "--working-dir", required=False,
help="Use it to set another working directory than the one where this module is executed")
args = vars(ap.parse_args())
if args["model"] not in trainer.ALLOWED_MODELS_NAMES:
raise Exception("Model must be a choice between those values: {}".format(trainer.ALLOWED_MODELS_NAMES))
if args["objective"] != "train" and args["objective"] != "predict":
raise Exception("Objective must be a choice between either 'train' or 'predict' value")
if "working-dir" in args:
working_dir = args["working-dir"]
else:
working_dir = os.path.abspath(os.path.dirname(__file__))
config_dir = os.path.join(working_dir, 'config')
config.configure_logging(os.path.join(config_dir, 'logging-console.json'))
# Load program configuration from external JSON format file (assumed to be placed under a 'config' directory
# within the working directory (specified or computed)
prog_config = Configuration(os.path.join(config_dir, 'config.json'))
prog_config.set_working_dir(working_dir)
if args["objective"] == "train":
trainer.do_training(prog_config, args["model"])
elif args["objective"] == "predict":
magic_oracle.do_magic(prog_config, args["model"])