|
|
|
@ -13,6 +13,9 @@
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
|
|
import distutils
|
|
|
|
|
from yacs.config import CfgNode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ExtendAction(argparse.Action):
|
|
|
|
|
"""
|
|
|
|
@ -68,7 +71,15 @@ def default_argument_parser(parser=None):
|
|
|
|
|
parser.register('action', 'extend', ExtendAction)
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
'--conf', type=open, action=LoadFromFile, help="config file.")
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"--debug",
|
|
|
|
|
type=distutils.util.strtobool,
|
|
|
|
|
default=False,
|
|
|
|
|
help="logging with debug mode.")
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"--dump_path", type=str, default=None, help="path to dump config file.")
|
|
|
|
|
|
|
|
|
|
# train group
|
|
|
|
|
train_group = parser.add_argument_group(
|
|
|
|
|
title='Train Options', description=None)
|
|
|
|
|
train_group.add_argument(
|
|
|
|
@ -103,14 +114,35 @@ def default_argument_parser(parser=None):
|
|
|
|
|
train_group.add_argument(
|
|
|
|
|
"--dump-config", metavar="FILE", help="dump config to `this` file.")
|
|
|
|
|
|
|
|
|
|
# test group
|
|
|
|
|
test_group = parser.add_argument_group(
|
|
|
|
|
title='Test Options', description=None)
|
|
|
|
|
|
|
|
|
|
test_group.add_argument(
|
|
|
|
|
"--decode_cfg",
|
|
|
|
|
metavar="DECODE_CONFIG_FILE",
|
|
|
|
|
help="decode config file.")
|
|
|
|
|
test_group.add_argument(
|
|
|
|
|
"--result_file", type=str, help="path of save the asr result")
|
|
|
|
|
test_group.add_argument(
|
|
|
|
|
"--audio_file", type=str, help="path of the input audio file")
|
|
|
|
|
|
|
|
|
|
# quant & export
|
|
|
|
|
quant_group = parser.add_argument_group(
|
|
|
|
|
title='Quant Options', description=None)
|
|
|
|
|
quant_group.add_argument(
|
|
|
|
|
"--audio_scp", type=str, help="path of the input audio scp file")
|
|
|
|
|
quant_group.add_argument(
|
|
|
|
|
"--num_utts",
|
|
|
|
|
type=int,
|
|
|
|
|
default=200,
|
|
|
|
|
help="num utts for quant calibrition.")
|
|
|
|
|
quant_group.add_argument(
|
|
|
|
|
"--export_path",
|
|
|
|
|
type=str,
|
|
|
|
|
default='export.jit.quant',
|
|
|
|
|
help="path of the jit model to save")
|
|
|
|
|
|
|
|
|
|
# profile group
|
|
|
|
|
profile_group = parser.add_argument_group(
|
|
|
|
|
title='Benchmark Options', description=None)
|
|
|
|
|
profile_group.add_argument(
|
|
|
|
@ -131,3 +163,28 @@ def default_argument_parser(parser=None):
|
|
|
|
|
help='max iteration for benchmark.')
|
|
|
|
|
|
|
|
|
|
return parser
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def config_from_args(args):
|
|
|
|
|
# https://yaml.org/type/float.html
|
|
|
|
|
config = CfgNode(new_allowed=True)
|
|
|
|
|
|
|
|
|
|
if args.config:
|
|
|
|
|
config.merge_from_file(args.config)
|
|
|
|
|
|
|
|
|
|
if args.decode_cfg:
|
|
|
|
|
decode_confs = CfgNode(new_allowed=True)
|
|
|
|
|
decode_confs.merge_from_file(args.decode_cfg)
|
|
|
|
|
config.decode = decode_confs
|
|
|
|
|
|
|
|
|
|
if args.opts:
|
|
|
|
|
config.merge_from_list(args.opts)
|
|
|
|
|
config.freeze()
|
|
|
|
|
return config
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def maybe_dump_config(dump_path, config):
|
|
|
|
|
if dump_path:
|
|
|
|
|
with open(dump_path, 'w') as f:
|
|
|
|
|
print(config, file=f)
|
|
|
|
|
print(f"save config to {dump_path}")
|
|
|
|
|