def main(): if len(sys.argv) != 2: print('USAGE: run_model.py [param_file]') sys.exit(-1) log_keras_version_info() param_file = sys.argv[1] param_dict = pyhocon.ConfigFactory.parse_file(param_file) params = Params(replace_none(param_dict)) log_dir = params.get("model_serialization_prefix", None) # pylint: disable=no-member if log_dir is not None: sys.stdout = TeeLogger(log_dir + "_stdout.log", sys.stdout) sys.stderr = TeeLogger(log_dir + "_stderr.log", sys.stderr) handler = logging.FileHandler(log_dir + "_python_logging.log") handler.setLevel(logging.INFO) handler.setFormatter( logging.Formatter( '%(asctime)s - %(levelname)s - %(name)s - %(message)s')) logging.getLogger().addHandler(handler) shutil.copyfile(param_file, log_dir + "_model_params.json") model_type = params.pop_choice('model_class', concrete_models.keys()) model_class = concrete_models[model_type] model = model_class(params) if model.can_train(): logger.info("Training model") model.train() else: logger.info( "Not enough training inputs. Assuming you wanted to load a model instead." ) # TODO(matt): figure out a way to specify which epoch you want to load a model from. model.load_model() K.clear_session()
def serve(port: int, config_file: str): # read in the Typesafe-style config file solver_params = ConfigFactory.parse_file(config_file) params = Params(replace_none(solver_params)) model_type = params.pop_choice('model_class', concrete_models.keys()) solver_class = concrete_models[model_type] solver = solver_class(params) global mySolver mySolver = SolverServer(solver) # start the server on the specified port print("starting server") app.run(host='0.0.0.0')