forked from yeyupiaoling/PPASR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_model.py
30 lines (23 loc) · 1.2 KB
/
export_model.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
import argparse
import functools
import yaml
from ppasr.trainer import PPASRTrainer
from ppasr.utils.utils import add_arguments, print_arguments
parser = argparse.ArgumentParser(description=__doc__)
add_arg = functools.partial(add_arguments, argparser=parser)
add_arg('configs', str, 'configs/conformer_online_zh.yml', '配置文件')
add_arg("use_gpu", bool, True, '是否使用GPU评估模型')
add_arg("save_quant", bool, False, '是否保存量化模型')
add_arg('save_model', str, 'models/', '模型保存的路径')
add_arg('resume_model', str, 'models/{}_{}/best_model/', '准备转换的模型路径')
args = parser.parse_args()
# 读取配置文件
with open(args.configs, 'r', encoding='utf-8') as f:
configs = yaml.load(f.read(), Loader=yaml.FullLoader)
print_arguments(args, configs)
# 获取训练器
trainer = PPASRTrainer(configs=configs, use_gpu=args.use_gpu)
# 导出预测模型
trainer.export(save_model_path=args.save_model,
resume_model=args.resume_model.format(configs['use_model'], configs['preprocess_conf']['feature_method']),
save_quant=args.save_quant)