def main(args): paddle.seed(12345) # load config config = load_yaml(args.config_yaml) dy_model_class = load_dy_model_class(args.abs_dir) config["config_abs_dir"] = args.abs_dir # tools.vars use_gpu = config.get("runner.use_gpu", True) train_data_dir = config.get("runner.train_data_dir", None) epochs = config.get("runner.epochs", None) print_interval = config.get("runner.print_interval", None) model_save_path = config.get("runner.model_save_path", "model_output") model_init_path = config.get("runner.model_init_path", None) logger.info("**************common.configs**********") logger.info( "use_gpu: {}, train_data_dir: {}, epochs: {}, print_interval: {}, model_save_path: {}". format(use_gpu, train_data_dir, epochs, print_interval, model_save_path)) logger.info("**************common.configs**********") place = paddle.set_device('gpu' if use_gpu else 'cpu') dy_model = dy_model_class.create_model(config) load_model(model_init_path, dy_model) # example dnn model forward dy_model = paddle.jit.to_static( dy_model, input_spec=[[ paddle.static.InputSpec( shape=[None, 1], dtype='int64') for jj in range(26) ], paddle.static.InputSpec( shape=[None, 13], dtype='float32')]) save_jit_model(dy_model, model_save_path, prefix='tostatic')
def main(args): paddle.seed(12345) # load config config = load_yaml(args.config_yaml) dy_model_class = load_dy_model_class(args.abs_dir) config["config_abs_dir"] = args.abs_dir # modify config from command if args.opt: for parameter in args.opt: parameter = parameter.strip() key, value = parameter.split("=") if type(config.get(key)) is int: value = int(value) if type(config.get(key)) is bool: value = (True if value.lower() == "true" else False) config[key] = value # tools.vars use_gpu = config.get("runner.use_gpu", True) train_data_dir = config.get("runner.train_data_dir", None) epochs = config.get("runner.epochs", None) print_interval = config.get("runner.print_interval", None) model_save_path = config.get("runner.model_save_path", "model_output") model_init_path = config.get("runner.model_init_path", None) end_epoch = config.get("runner.infer_end_epoch", 0) CE = config.get("runner.CE", False) logger.info("**************common.configs**********") logger.info( "use_gpu: {}, train_data_dir: {}, epochs: {}, print_interval: {}, model_save_path: {}" .format(use_gpu, train_data_dir, epochs, print_interval, model_save_path)) logger.info("**************common.configs**********") place = paddle.set_device('gpu' if use_gpu else 'cpu') dy_model = dy_model_class.create_model(config) if not CE: model_save_path = os.path.join(model_save_path, str(end_epoch - 1)) load_model(model_init_path, dy_model) dy_model = paddle.jit.to_static( dy_model, input_spec=[[ paddle.static.InputSpec(shape=[None, 15], dtype='int'), paddle.static.InputSpec(shape=[ None, ], dtype='float32'), paddle.static.InputSpec(shape=[None, 10, 10], dtype='int'), paddle.static.InputSpec(shape=[ None, ], dtype='int') ]]) save_jit_model(dy_model, model_save_path, prefix='tostatic')