diff --git a/.gitignore b/.gitignore index e4134a08..cd2360e1 100644 --- a/.gitignore +++ b/.gitignore @@ -18,5 +18,7 @@ tools/sox-14.4.2 tools/soxbindings tools/montreal-forced-aligner/ tools/Montreal-Forced-Aligner/ +tools/sctk +tools/sctk-20159b5/ *output/ diff --git a/deepspeech/exps/deepspeech2/bin/train.py b/deepspeech/exps/deepspeech2/bin/train.py index 69ff043a..6740f288 100644 --- a/deepspeech/exps/deepspeech2/bin/train.py +++ b/deepspeech/exps/deepspeech2/bin/train.py @@ -27,7 +27,7 @@ def main_sp(config, args): def main(config, args): - if args.device == "gpu" and args.nprocs > 1: + if args.nprocs > 0: dist.spawn(main_sp, args=(config, args), nprocs=args.nprocs) else: main_sp(config, args) diff --git a/deepspeech/exps/deepspeech2/model.py b/deepspeech/exps/deepspeech2/model.py index 7bf02930..79a67634 100644 --- a/deepspeech/exps/deepspeech2/model.py +++ b/deepspeech/exps/deepspeech2/model.py @@ -19,6 +19,7 @@ from contextlib import nullcontext from pathlib import Path from typing import Optional +import jsonlines import numpy as np import paddle from paddle import distributed as dist @@ -305,9 +306,10 @@ class DeepSpeech2Tester(DeepSpeech2Trainer): len_refs += len_ref num_ins += 1 if fout: - fout.write(utt + " " + result + "\n") - logger.info("\nTarget Transcription: %s\nOutput Transcription: %s" % - (target, result)) + fout.write({"utt": utt, "ref": target, "hyp": result}) + logger.info(f"Utt: {utt}") + logger.info(f"Ref: {target}") + logger.info(f"Hyp: {result}") logger.info("Current error rate [%s] = %f" % (cfg.error_rate_type, error_rate_func(target, result))) @@ -350,7 +352,7 @@ class DeepSpeech2Tester(DeepSpeech2Trainer): cfg = self.config error_rate_type = None errors_sum, len_refs, num_ins = 0.0, 0, 0 - with open(self.args.result_file, 'w') as fout: + with jsonlines.open(self.args.result_file, 'w') as fout: for i, batch in enumerate(self.test_loader): utts, audio, audio_len, texts, texts_len = batch metrics = self.compute_metrics(utts, audio, audio_len, texts, @@ -403,7 +405,7 @@ class DeepSpeech2Tester(DeepSpeech2Trainer): def setup(self): """Setup the experiment. """ - paddle.set_device(self.args.device) + paddle.set_device('gpu' if self.args.nprocs > 0 else 'cpu') self.setup_output_dir() self.setup_checkpointer() @@ -635,7 +637,7 @@ class DeepSpeech2ExportTester(DeepSpeech2Tester): def setup(self): """Setup the experiment. """ - paddle.set_device(self.args.device) + paddle.set_device('gpu' if self.args.nprocs > 0 else 'cpu') self.setup_output_dir() diff --git a/deepspeech/exps/u2/bin/train.py b/deepspeech/exps/u2/bin/train.py index b664401a..17fb08a6 100644 --- a/deepspeech/exps/u2/bin/train.py +++ b/deepspeech/exps/u2/bin/train.py @@ -32,7 +32,7 @@ def main_sp(config, args): def main(config, args): - if args.device == "gpu" and args.nprocs > 1: + if args.nprocs > 0: dist.spawn(main_sp, args=(config, args), nprocs=args.nprocs) else: main_sp(config, args) diff --git a/deepspeech/exps/u2/model.py b/deepspeech/exps/u2/model.py index 6bf01900..5cb0962a 100644 --- a/deepspeech/exps/u2/model.py +++ b/deepspeech/exps/u2/model.py @@ -22,6 +22,7 @@ from contextlib import nullcontext from pathlib import Path from typing import Optional +import jsonlines import numpy as np import paddle from paddle import distributed as dist @@ -466,9 +467,10 @@ class U2Tester(U2Trainer): len_refs += len_ref num_ins += 1 if fout: - fout.write(utt + " " + result + "\n") - logger.info("\nTarget Transcription: %s\nOutput Transcription: %s" % - (target, result)) + fout.write({"utt": utt, "ref": target, "hyp": result}) + logger.info(f"Utt: {utt}") + logger.info(f"Ref: {target}") + logger.info(f"Hyp: {result}") logger.info("One example error rate [%s] = %f" % (cfg.error_rate_type, error_rate_func(target, result))) @@ -493,7 +495,7 @@ class U2Tester(U2Trainer): errors_sum, len_refs, num_ins = 0.0, 0, 0 num_frames = 0.0 num_time = 0.0 - with open(self.args.result_file, 'w') as fout: + with jsonlines.open(self.args.result_file, 'w') as fout: for i, batch in enumerate(self.test_loader): metrics = self.compute_metrics(*batch, fout=fout) num_frames += metrics['num_frames'] @@ -653,7 +655,7 @@ class U2Tester(U2Trainer): def setup(self): """Setup the experiment. """ - paddle.set_device(self.args.device) + paddle.set_device('gpu' if self.args.nprocs > 0 else 'cpu') self.setup_output_dir() self.setup_checkpointer() diff --git a/deepspeech/exps/u2_kaldi/bin/train.py b/deepspeech/exps/u2_kaldi/bin/train.py index 1dcd154d..d909727f 100644 --- a/deepspeech/exps/u2_kaldi/bin/train.py +++ b/deepspeech/exps/u2_kaldi/bin/train.py @@ -36,7 +36,7 @@ def main_sp(config, args): def main(config, args): - if args.device == "gpu" and args.nprocs > 1: + if args.nprocs > 0: dist.spawn(main_sp, args=(config, args), nprocs=args.nprocs) else: main_sp(config, args) diff --git a/deepspeech/exps/u2_kaldi/model.py b/deepspeech/exps/u2_kaldi/model.py index bc7cd4fd..d38afe25 100644 --- a/deepspeech/exps/u2_kaldi/model.py +++ b/deepspeech/exps/u2_kaldi/model.py @@ -21,6 +21,7 @@ from contextlib import nullcontext from pathlib import Path from typing import Optional +import jsonlines import numpy as np import paddle from paddle import distributed as dist @@ -445,9 +446,10 @@ class U2Tester(U2Trainer): len_refs += len_ref num_ins += 1 if fout: - fout.write(utt + " " + result + "\n") - logger.info("\nTarget Transcription: %s\nOutput Transcription: %s" % - (target, result)) + fout.write({"utt": utt, "ref": target, "hyp": result}) + logger.info(f"Utt: {utt}") + logger.info(f"Ref: {target}") + logger.info(f"Hyp: {result}") logger.info("One example error rate [%s] = %f" % (cfg.error_rate_type, error_rate_func(target, result))) @@ -472,7 +474,7 @@ class U2Tester(U2Trainer): errors_sum, len_refs, num_ins = 0.0, 0, 0 num_frames = 0.0 num_time = 0.0 - with open(self.args.result_file, 'w') as fout: + with jsonlines.open(self.args.result_file, 'w') as fout: for i, batch in enumerate(self.test_loader): metrics = self.compute_metrics(*batch, fout=fout) num_frames += metrics['num_frames'] @@ -637,7 +639,7 @@ class U2Tester(U2Trainer): def setup(self): """Setup the experiment. """ - paddle.set_device(self.args.device) + paddle.set_device('gpu' if self.args.nprocs > 0 else 'cpu') self.setup_output_dir() self.setup_checkpointer() diff --git a/deepspeech/exps/u2_st/bin/train.py b/deepspeech/exps/u2_st/bin/train.py index 86a0f000..1e6a746b 100644 --- a/deepspeech/exps/u2_st/bin/train.py +++ b/deepspeech/exps/u2_st/bin/train.py @@ -30,7 +30,7 @@ def main_sp(config, args): def main(config, args): - if args.device == "gpu" and args.nprocs > 1: + if args.nprocs > 0: dist.spawn(main_sp, args=(config, args), nprocs=args.nprocs) else: main_sp(config, args) diff --git a/deepspeech/exps/u2_st/model.py b/deepspeech/exps/u2_st/model.py index 4f95bc42..e4e70292 100644 --- a/deepspeech/exps/u2_st/model.py +++ b/deepspeech/exps/u2_st/model.py @@ -21,6 +21,7 @@ from contextlib import nullcontext from pathlib import Path from typing import Optional +import jsonlines import numpy as np import paddle from paddle import distributed as dist @@ -479,8 +480,10 @@ class U2STTester(U2STTrainer): len_refs += len(target.split()) num_ins += 1 if fout: - fout.write(utt + " " + result + "\n") - logger.info("\nReference: %s\nHypothesis: %s" % (target, result)) + fout.write({"utt": utt, "ref": target, "hyp": result}) + logger.info(f"Utt: {utt}") + logger.info(f"Ref: {target}") + logger.info(f"Hyp: {result}") logger.info("One example BLEU = %s" % (bleu_func([result], [[target]]).prec_str)) @@ -508,7 +511,7 @@ class U2STTester(U2STTrainer): len_refs, num_ins = 0, 0 num_frames = 0.0 num_time = 0.0 - with open(self.args.result_file, 'w') as fout: + with jsonlines.open(self.args.result_file, 'w') as fout: for i, batch in enumerate(self.test_loader): metrics = self.compute_translation_metrics( *batch, bleu_func=bleu_func, fout=fout) @@ -661,7 +664,7 @@ class U2STTester(U2STTrainer): def setup(self): """Setup the experiment. """ - paddle.set_device(self.args.device) + paddle.set_device('gpu' if self.args.nprocs > 0 else 'cpu') self.setup_output_dir() self.setup_checkpointer() diff --git a/deepspeech/frontend/utility.py b/deepspeech/frontend/utility.py index c6781cd4..f7e2cb21 100644 --- a/deepspeech/frontend/utility.py +++ b/deepspeech/frontend/utility.py @@ -12,13 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. """Contains data helper functions.""" -import codecs import json import math from typing import List from typing import Optional from typing import Text +import jsonlines import numpy as np from deepspeech.utils.log import Log @@ -92,26 +92,22 @@ def read_manifest( """ manifest = [] - for json_line in codecs.open(manifest_path, 'r', 'utf-8'): - try: - json_data = json.loads(json_line) - except Exception as e: - raise IOError("Error reading manifest: %s" % str(e)) - - feat_len = json_data["feat_shape"][ - 0] if 'feat_shape' in json_data else 1.0 - token_len = json_data["token_shape"][ - 0] if 'token_shape' in json_data else 1.0 - conditions = [ - feat_len >= min_input_len, - feat_len <= max_input_len, - token_len >= min_output_len, - token_len <= max_output_len, - token_len / feat_len >= min_output_input_ratio, - token_len / feat_len <= max_output_input_ratio, - ] - if all(conditions): - manifest.append(json_data) + with jsonlines.open(manifest_path, 'r') as reader: + for json_data in reader: + feat_len = json_data["feat_shape"][ + 0] if 'feat_shape' in json_data else 1.0 + token_len = json_data["token_shape"][ + 0] if 'token_shape' in json_data else 1.0 + conditions = [ + feat_len >= min_input_len, + feat_len <= max_input_len, + token_len >= min_output_len, + token_len <= max_output_len, + token_len / feat_len >= min_output_input_ratio, + token_len / feat_len <= max_output_input_ratio, + ] + if all(conditions): + manifest.append(json_data) return manifest diff --git a/deepspeech/training/cli.py b/deepspeech/training/cli.py index 07c213db..e079293c 100644 --- a/deepspeech/training/cli.py +++ b/deepspeech/training/cli.py @@ -14,6 +14,20 @@ import argparse +class ExtendAction(argparse.Action): + """ + [Since Python 3.8, the "extend" is available directly in stdlib] + (https://docs.python.org/3.8/library/argparse.html#action). + If you only have to support 3.8+ then defining it yourself is no longer required. + Usage of stdlib "extend" action is exactly the same way as this answer originally described: + """ + + def __call__(self, parser, namespace, values, option_string=None): + items = getattr(namespace, self.dest) or [] + items.extend(values) + setattr(namespace, self.dest, items) + + def default_argument_parser(): r"""A simple yet genral argument parser for experiments with parakeet. @@ -30,7 +44,7 @@ def default_argument_parser(): The ``--checkpoint_path`` specifies the checkpoint to load from. - The ``--device`` and ``--nprocs`` specifies how to run the training. + The ``--nprocs`` specifies how to run the training. See Also @@ -42,6 +56,7 @@ def default_argument_parser(): the parser """ parser = argparse.ArgumentParser() + parser.register('action', 'extend', ExtendAction) train_group = parser.add_argument_group( title='Train Options', description=None) @@ -51,12 +66,6 @@ def default_argument_parser(): default=None, help="seed to use for paddle, np and random. None or 0 for random, else set seed." ) - train_group.add_argument( - "--device", - type=str, - default='gpu', - choices=["cpu", "gpu"], - help="device cpu and gpu are supported.") train_group.add_argument( "--nprocs", type=int, @@ -70,10 +79,10 @@ def default_argument_parser(): "--checkpoint_path", type=str, help="path to load checkpoint") train_group.add_argument( "--opts", - type=str, - default=[], - nargs='+', - help="overwrite --config file, passing in LIST[KEY VALUE] pairs") + action='extend', + nargs=2, + metavar=('key', 'val'), + help="overwrite --config field, passing (KEY VALUE) pairs") train_group.add_argument( "--dump-config", metavar="FILE", help="dump config to `this` file.") diff --git a/deepspeech/training/trainer.py b/deepspeech/training/trainer.py index 8b1adcd0..15259f0e 100644 --- a/deepspeech/training/trainer.py +++ b/deepspeech/training/trainer.py @@ -86,7 +86,7 @@ class Trainer(): >>> config.merge_from_list(args.opts) >>> config.freeze() >>> - >>> if args.nprocs > 1 and args.device == "gpu": + >>> if args.nprocs > 0: >>> dist.spawn(main_sp, args=(config, args), nprocs=args.nprocs) >>> else: >>> main_sp(config, args) @@ -119,7 +119,7 @@ class Trainer(): def setup(self): """Setup the experiment. """ - paddle.set_device(self.args.device) + paddle.set_device('gpu' if self.args.nprocs > 0 else 'cpu') if self.parallel: self.init_parallel() @@ -139,7 +139,7 @@ class Trainer(): """A flag indicating whether the experiment should run with multiprocessing. """ - return self.args.device == "gpu" and self.args.nprocs > 1 + return self.args.nprocs > 1 def init_parallel(self): """Init environment for multiprocess training. diff --git a/deepspeech/utils/tensor_utils.py b/deepspeech/utils/tensor_utils.py index bb7f58de..61798816 100644 --- a/deepspeech/utils/tensor_utils.py +++ b/deepspeech/utils/tensor_utils.py @@ -94,9 +94,19 @@ def pad_sequence(sequences: List[paddle.Tensor], length = tensor.shape[0] # use index notation to prevent duplicate references to the tensor if batch_first: - out_tensor[i, :length, ...] = tensor + # TODO (Hui Zhang): set_value op not supprot `end==start` + # out_tensor[i, :length, ...] = tensor + if length != 0: + out_tensor[i, :length, ...] = tensor + else: + out_tensor[i, length, ...] = tensor else: - out_tensor[:length, i, ...] = tensor + # TODO (Hui Zhang): set_value op not supprot `end==start` + # out_tensor[:length, i, ...] = tensor + if length != 0: + out_tensor[:length, i, ...] = tensor + else: + out_tensor[length, i, ...] = tensor return out_tensor diff --git a/examples/v18_to_v2x/.gitignore b/examples/1xt2x/.gitignore similarity index 100% rename from examples/v18_to_v2x/.gitignore rename to examples/1xt2x/.gitignore diff --git a/examples/1xt2x/README.md b/examples/1xt2x/README.md new file mode 100644 index 00000000..1f5fe8e3 --- /dev/null +++ b/examples/1xt2x/README.md @@ -0,0 +1,11 @@ +# 1xt2x + +Convert Deepspeech 1.8 released model to 2.x. + +## Model +* Deepspeech2x + +## Exp +* baidu_en8k +* aishell +* librispeech diff --git a/examples/v18_to_v2x/exp_aishell/.gitignore b/examples/1xt2x/aishell/.gitignore similarity index 100% rename from examples/v18_to_v2x/exp_aishell/.gitignore rename to examples/1xt2x/aishell/.gitignore diff --git a/examples/v18_to_v2x/exp_aishell/conf/augmentation.json b/examples/1xt2x/aishell/conf/augmentation.json similarity index 100% rename from examples/v18_to_v2x/exp_aishell/conf/augmentation.json rename to examples/1xt2x/aishell/conf/augmentation.json diff --git a/examples/v18_to_v2x/exp_aishell/conf/deepspeech2.yaml b/examples/1xt2x/aishell/conf/deepspeech2.yaml similarity index 100% rename from examples/v18_to_v2x/exp_aishell/conf/deepspeech2.yaml rename to examples/1xt2x/aishell/conf/deepspeech2.yaml diff --git a/examples/v18_to_v2x/exp_aishell/local/data.sh b/examples/1xt2x/aishell/local/data.sh similarity index 100% rename from examples/v18_to_v2x/exp_aishell/local/data.sh rename to examples/1xt2x/aishell/local/data.sh diff --git a/examples/v18_to_v2x/exp_aishell/local/download_lm_ch.sh b/examples/1xt2x/aishell/local/download_lm_ch.sh similarity index 100% rename from examples/v18_to_v2x/exp_aishell/local/download_lm_ch.sh rename to examples/1xt2x/aishell/local/download_lm_ch.sh diff --git a/examples/v18_to_v2x/exp_aishell/local/download_model.sh b/examples/1xt2x/aishell/local/download_model.sh similarity index 100% rename from examples/v18_to_v2x/exp_aishell/local/download_model.sh rename to examples/1xt2x/aishell/local/download_model.sh diff --git a/examples/v18_to_v2x/exp_aishell/local/test.sh b/examples/1xt2x/aishell/local/test.sh similarity index 86% rename from examples/v18_to_v2x/exp_aishell/local/test.sh rename to examples/1xt2x/aishell/local/test.sh index 9fd0bc8d..2ae0740b 100755 --- a/examples/v18_to_v2x/exp_aishell/local/test.sh +++ b/examples/1xt2x/aishell/local/test.sh @@ -8,10 +8,6 @@ fi ngpu=$(echo $CUDA_VISIBLE_DEVICES | awk -F "," '{print NF}') echo "using $ngpu gpus..." -device=gpu -if [ ${ngpu} == 0 ];then - device=cpu -fi config_path=$1 ckpt_prefix=$2 model_type=$3 @@ -23,8 +19,7 @@ if [ $? -ne 0 ]; then fi python3 -u ${BIN_DIR}/test.py \ ---device ${device} \ ---nproc 1 \ +--nproc ${ngpu} \ --config ${config_path} \ --result_file ${ckpt_prefix}.rsl \ --checkpoint_path ${ckpt_prefix} \ diff --git a/examples/v18_to_v2x/exp_baidu_en8k/path.sh b/examples/1xt2x/aishell/path.sh similarity index 100% rename from examples/v18_to_v2x/exp_baidu_en8k/path.sh rename to examples/1xt2x/aishell/path.sh diff --git a/examples/v18_to_v2x/exp_aishell/run.sh b/examples/1xt2x/aishell/run.sh similarity index 100% rename from examples/v18_to_v2x/exp_aishell/run.sh rename to examples/1xt2x/aishell/run.sh diff --git a/examples/v18_to_v2x/exp_baidu_en8k/.gitignore b/examples/1xt2x/baidu_en8k/.gitignore similarity index 100% rename from examples/v18_to_v2x/exp_baidu_en8k/.gitignore rename to examples/1xt2x/baidu_en8k/.gitignore diff --git a/examples/v18_to_v2x/exp_baidu_en8k/conf/augmentation.json b/examples/1xt2x/baidu_en8k/conf/augmentation.json similarity index 100% rename from examples/v18_to_v2x/exp_baidu_en8k/conf/augmentation.json rename to examples/1xt2x/baidu_en8k/conf/augmentation.json diff --git a/examples/v18_to_v2x/exp_baidu_en8k/conf/deepspeech2.yaml b/examples/1xt2x/baidu_en8k/conf/deepspeech2.yaml similarity index 100% rename from examples/v18_to_v2x/exp_baidu_en8k/conf/deepspeech2.yaml rename to examples/1xt2x/baidu_en8k/conf/deepspeech2.yaml diff --git a/examples/v18_to_v2x/exp_baidu_en8k/local/data.sh b/examples/1xt2x/baidu_en8k/local/data.sh similarity index 100% rename from examples/v18_to_v2x/exp_baidu_en8k/local/data.sh rename to examples/1xt2x/baidu_en8k/local/data.sh diff --git a/examples/v18_to_v2x/exp_baidu_en8k/local/download_lm_en.sh b/examples/1xt2x/baidu_en8k/local/download_lm_en.sh similarity index 100% rename from examples/v18_to_v2x/exp_baidu_en8k/local/download_lm_en.sh rename to examples/1xt2x/baidu_en8k/local/download_lm_en.sh diff --git a/examples/v18_to_v2x/exp_baidu_en8k/local/download_model.sh b/examples/1xt2x/baidu_en8k/local/download_model.sh similarity index 100% rename from examples/v18_to_v2x/exp_baidu_en8k/local/download_model.sh rename to examples/1xt2x/baidu_en8k/local/download_model.sh diff --git a/examples/v18_to_v2x/exp_baidu_en8k/local/test.sh b/examples/1xt2x/baidu_en8k/local/test.sh similarity index 86% rename from examples/v18_to_v2x/exp_baidu_en8k/local/test.sh rename to examples/1xt2x/baidu_en8k/local/test.sh index b5b68c59..4d00f30b 100755 --- a/examples/v18_to_v2x/exp_baidu_en8k/local/test.sh +++ b/examples/1xt2x/baidu_en8k/local/test.sh @@ -8,10 +8,6 @@ fi ngpu=$(echo $CUDA_VISIBLE_DEVICES | awk -F "," '{print NF}') echo "using $ngpu gpus..." -device=gpu -if [ ${ngpu} == 0 ];then - device=cpu -fi config_path=$1 ckpt_prefix=$2 model_type=$3 @@ -23,8 +19,7 @@ if [ $? -ne 0 ]; then fi python3 -u ${BIN_DIR}/test.py \ ---device ${device} \ ---nproc 1 \ +--nproc ${ngpu} \ --config ${config_path} \ --result_file ${ckpt_prefix}.rsl \ --checkpoint_path ${ckpt_prefix} \ diff --git a/examples/v18_to_v2x/exp_librispeech/path.sh b/examples/1xt2x/baidu_en8k/path.sh similarity index 100% rename from examples/v18_to_v2x/exp_librispeech/path.sh rename to examples/1xt2x/baidu_en8k/path.sh diff --git a/examples/v18_to_v2x/exp_baidu_en8k/run.sh b/examples/1xt2x/baidu_en8k/run.sh similarity index 100% rename from examples/v18_to_v2x/exp_baidu_en8k/run.sh rename to examples/1xt2x/baidu_en8k/run.sh diff --git a/examples/v18_to_v2x/exp_librispeech/.gitignore b/examples/1xt2x/librispeech/.gitignore similarity index 100% rename from examples/v18_to_v2x/exp_librispeech/.gitignore rename to examples/1xt2x/librispeech/.gitignore diff --git a/examples/v18_to_v2x/exp_librispeech/conf/augmentation.json b/examples/1xt2x/librispeech/conf/augmentation.json similarity index 100% rename from examples/v18_to_v2x/exp_librispeech/conf/augmentation.json rename to examples/1xt2x/librispeech/conf/augmentation.json diff --git a/examples/v18_to_v2x/exp_librispeech/conf/deepspeech2.yaml b/examples/1xt2x/librispeech/conf/deepspeech2.yaml similarity index 100% rename from examples/v18_to_v2x/exp_librispeech/conf/deepspeech2.yaml rename to examples/1xt2x/librispeech/conf/deepspeech2.yaml diff --git a/examples/v18_to_v2x/exp_librispeech/local/data.sh b/examples/1xt2x/librispeech/local/data.sh similarity index 100% rename from examples/v18_to_v2x/exp_librispeech/local/data.sh rename to examples/1xt2x/librispeech/local/data.sh diff --git a/examples/v18_to_v2x/exp_librispeech/local/download_lm_en.sh b/examples/1xt2x/librispeech/local/download_lm_en.sh similarity index 100% rename from examples/v18_to_v2x/exp_librispeech/local/download_lm_en.sh rename to examples/1xt2x/librispeech/local/download_lm_en.sh diff --git a/examples/v18_to_v2x/exp_librispeech/local/download_model.sh b/examples/1xt2x/librispeech/local/download_model.sh similarity index 100% rename from examples/v18_to_v2x/exp_librispeech/local/download_model.sh rename to examples/1xt2x/librispeech/local/download_model.sh diff --git a/examples/v18_to_v2x/exp_librispeech/local/test.sh b/examples/1xt2x/librispeech/local/test.sh similarity index 86% rename from examples/v18_to_v2x/exp_librispeech/local/test.sh rename to examples/1xt2x/librispeech/local/test.sh index b5b68c59..4d00f30b 100755 --- a/examples/v18_to_v2x/exp_librispeech/local/test.sh +++ b/examples/1xt2x/librispeech/local/test.sh @@ -8,10 +8,6 @@ fi ngpu=$(echo $CUDA_VISIBLE_DEVICES | awk -F "," '{print NF}') echo "using $ngpu gpus..." -device=gpu -if [ ${ngpu} == 0 ];then - device=cpu -fi config_path=$1 ckpt_prefix=$2 model_type=$3 @@ -23,8 +19,7 @@ if [ $? -ne 0 ]; then fi python3 -u ${BIN_DIR}/test.py \ ---device ${device} \ ---nproc 1 \ +--nproc ${ngpu} \ --config ${config_path} \ --result_file ${ckpt_prefix}.rsl \ --checkpoint_path ${ckpt_prefix} \ diff --git a/examples/v18_to_v2x/exp_aishell/path.sh b/examples/1xt2x/librispeech/path.sh similarity index 100% rename from examples/v18_to_v2x/exp_aishell/path.sh rename to examples/1xt2x/librispeech/path.sh diff --git a/examples/v18_to_v2x/exp_librispeech/run.sh b/examples/1xt2x/librispeech/run.sh similarity index 100% rename from examples/v18_to_v2x/exp_librispeech/run.sh rename to examples/1xt2x/librispeech/run.sh diff --git a/examples/v18_to_v2x/src_deepspeech2x/__init__.py b/examples/1xt2x/src_deepspeech2x/__init__.py similarity index 100% rename from examples/v18_to_v2x/src_deepspeech2x/__init__.py rename to examples/1xt2x/src_deepspeech2x/__init__.py diff --git a/examples/v18_to_v2x/src_deepspeech2x/bin/test.py b/examples/1xt2x/src_deepspeech2x/bin/test.py similarity index 100% rename from examples/v18_to_v2x/src_deepspeech2x/bin/test.py rename to examples/1xt2x/src_deepspeech2x/bin/test.py diff --git a/examples/v18_to_v2x/src_deepspeech2x/models/__init__.py b/examples/1xt2x/src_deepspeech2x/models/__init__.py similarity index 100% rename from examples/v18_to_v2x/src_deepspeech2x/models/__init__.py rename to examples/1xt2x/src_deepspeech2x/models/__init__.py diff --git a/examples/v18_to_v2x/src_deepspeech2x/models/ds2/__init__.py b/examples/1xt2x/src_deepspeech2x/models/ds2/__init__.py similarity index 100% rename from examples/v18_to_v2x/src_deepspeech2x/models/ds2/__init__.py rename to examples/1xt2x/src_deepspeech2x/models/ds2/__init__.py diff --git a/examples/v18_to_v2x/src_deepspeech2x/models/ds2/deepspeech2.py b/examples/1xt2x/src_deepspeech2x/models/ds2/deepspeech2.py similarity index 100% rename from examples/v18_to_v2x/src_deepspeech2x/models/ds2/deepspeech2.py rename to examples/1xt2x/src_deepspeech2x/models/ds2/deepspeech2.py diff --git a/examples/v18_to_v2x/src_deepspeech2x/models/ds2/rnn.py b/examples/1xt2x/src_deepspeech2x/models/ds2/rnn.py similarity index 100% rename from examples/v18_to_v2x/src_deepspeech2x/models/ds2/rnn.py rename to examples/1xt2x/src_deepspeech2x/models/ds2/rnn.py diff --git a/examples/v18_to_v2x/src_deepspeech2x/test_model.py b/examples/1xt2x/src_deepspeech2x/test_model.py similarity index 99% rename from examples/v18_to_v2x/src_deepspeech2x/test_model.py rename to examples/1xt2x/src_deepspeech2x/test_model.py index 09fa099c..9f0cd836 100644 --- a/examples/v18_to_v2x/src_deepspeech2x/test_model.py +++ b/examples/1xt2x/src_deepspeech2x/test_model.py @@ -401,7 +401,7 @@ class DeepSpeech2Tester(DeepSpeech2Trainer): def setup(self): """Setup the experiment. """ - paddle.set_device(self.args.device) + paddle.set_device('gpu' if self.args.nprocs > 0 else 'cpu') self.setup_output_dir() self.setup_checkpointer() diff --git a/examples/aishell/s0/local/export.sh b/examples/aishell/s0/local/export.sh index 2e09e5f5..a5e62c28 100755 --- a/examples/aishell/s0/local/export.sh +++ b/examples/aishell/s0/local/export.sh @@ -13,13 +13,7 @@ ckpt_path_prefix=$2 jit_model_export_path=$3 model_type=$4 -device=gpu -if [ ${ngpu} == 0 ];then - device=cpu -fi - python3 -u ${BIN_DIR}/export.py \ ---device ${device} \ --nproc ${ngpu} \ --config ${config_path} \ --checkpoint_path ${ckpt_path_prefix} \ diff --git a/examples/aishell/s0/local/test.sh b/examples/aishell/s0/local/test.sh index 9fd0bc8d..2ae0740b 100755 --- a/examples/aishell/s0/local/test.sh +++ b/examples/aishell/s0/local/test.sh @@ -8,10 +8,6 @@ fi ngpu=$(echo $CUDA_VISIBLE_DEVICES | awk -F "," '{print NF}') echo "using $ngpu gpus..." -device=gpu -if [ ${ngpu} == 0 ];then - device=cpu -fi config_path=$1 ckpt_prefix=$2 model_type=$3 @@ -23,8 +19,7 @@ if [ $? -ne 0 ]; then fi python3 -u ${BIN_DIR}/test.py \ ---device ${device} \ ---nproc 1 \ +--nproc ${ngpu} \ --config ${config_path} \ --result_file ${ckpt_prefix}.rsl \ --checkpoint_path ${ckpt_prefix} \ diff --git a/examples/aishell/s0/local/test_export.sh b/examples/aishell/s0/local/test_export.sh index b6d58097..a9a6b122 100755 --- a/examples/aishell/s0/local/test_export.sh +++ b/examples/aishell/s0/local/test_export.sh @@ -8,10 +8,6 @@ fi ngpu=$(echo $CUDA_VISIBLE_DEVICES | awk -F "," '{print NF}') echo "using $ngpu gpus..." -device=gpu -if [ ${ngpu} == 0 ];then - device=cpu -fi config_path=$1 jit_model_export_path=$2 model_type=$3 @@ -23,8 +19,7 @@ if [ $? -ne 0 ]; then fi python3 -u ${BIN_DIR}/test_export.py \ ---device ${device} \ ---nproc 1 \ +--nproc ${ngpu} \ --config ${config_path} \ --result_file ${jit_model_export_path}.rsl \ --export_path ${jit_model_export_path} \ diff --git a/examples/aishell/s0/local/train.sh b/examples/aishell/s0/local/train.sh index 668ad0ea..edbf3383 100755 --- a/examples/aishell/s0/local/train.sh +++ b/examples/aishell/s0/local/train.sh @@ -12,11 +12,6 @@ config_path=$1 ckpt_name=$2 model_type=$3 -device=gpu -if [ ${ngpu} == 0 ];then - device=cpu -fi - mkdir -p exp # seed may break model convergence @@ -26,7 +21,6 @@ if [ ${seed} != 0 ]; then fi python3 -u ${BIN_DIR}/train.py \ ---device ${device} \ --nproc ${ngpu} \ --config ${config_path} \ --output exp/${ckpt_name} \ diff --git a/examples/aishell/s1/local/align.sh b/examples/aishell/s1/local/align.sh index ad6c84bc..279461aa 100755 --- a/examples/aishell/s1/local/align.sh +++ b/examples/aishell/s1/local/align.sh @@ -8,10 +8,6 @@ fi ngpu=$(echo $CUDA_VISIBLE_DEVICES | awk -F "," '{print NF}') echo "using $ngpu gpus..." -device=gpu -if [ ${ngpu} == 0 ];then - device=cpu -fi config_path=$1 ckpt_prefix=$2 @@ -22,8 +18,7 @@ mkdir -p ${output_dir} # align dump in `result_file` # .tier, .TextGrid dump in `dir of result_file` python3 -u ${BIN_DIR}/alignment.py \ ---device ${device} \ ---nproc 1 \ +--nproc ${ngpu} \ --config ${config_path} \ --result_file ${output_dir}/${type}.align \ --checkpoint_path ${ckpt_prefix} \ diff --git a/examples/aishell/s1/local/export.sh b/examples/aishell/s1/local/export.sh index f99a15ba..b562218e 100755 --- a/examples/aishell/s1/local/export.sh +++ b/examples/aishell/s1/local/export.sh @@ -12,13 +12,7 @@ config_path=$1 ckpt_path_prefix=$2 jit_model_export_path=$3 -device=gpu -if [ ${ngpu} == 0 ];then - device=cpu -fi - python3 -u ${BIN_DIR}/export.py \ ---device ${device} \ --nproc ${ngpu} \ --config ${config_path} \ --checkpoint_path ${ckpt_path_prefix} \ diff --git a/examples/aishell/s1/local/test.sh b/examples/aishell/s1/local/test.sh index f7e99ad7..c87412c9 100755 --- a/examples/aishell/s1/local/test.sh +++ b/examples/aishell/s1/local/test.sh @@ -8,11 +8,6 @@ fi ngpu=$(echo $CUDA_VISIBLE_DEVICES | awk -F "," '{print NF}') echo "using $ngpu gpus..." -device=gpu -if [ ${ngpu} == 0 ];then - device=cpu -fi - config_path=$1 ckpt_prefix=$2 @@ -39,8 +34,7 @@ for type in attention ctc_greedy_search; do output_dir=${ckpt_prefix} mkdir -p ${output_dir} python3 -u ${BIN_DIR}/test.py \ - --device ${device} \ - --nproc 1 \ + --nproc ${ngpu} \ --config ${config_path} \ --result_file ${output_dir}/${type}.rsl \ --checkpoint_path ${ckpt_prefix} \ @@ -58,8 +52,7 @@ for type in ctc_prefix_beam_search attention_rescoring; do output_dir=${ckpt_prefix} mkdir -p ${output_dir} python3 -u ${BIN_DIR}/test.py \ - --device ${device} \ - --nproc 1 \ + --nproc ${ngpu} \ --config ${config_path} \ --result_file ${output_dir}/${type}.rsl \ --checkpoint_path ${ckpt_prefix} \ diff --git a/examples/aishell/s1/local/train.sh b/examples/aishell/s1/local/train.sh index 5097d4d0..71af3a00 100755 --- a/examples/aishell/s1/local/train.sh +++ b/examples/aishell/s1/local/train.sh @@ -12,11 +12,6 @@ source ${MAIN_ROOT}/utils/parse_options.sh || exit 1; ngpu=$(echo $CUDA_VISIBLE_DEVICES | awk -F "," '{print NF}') echo "using $ngpu gpus..." -device=gpu -if [ ${ngpu} == 0 ];then - device=cpu -fi - if [ ${seed} != 0 ]; then export FLAGS_cudnn_deterministic=True echo "using seed $seed & FLAGS_cudnn_deterministic=True ..." @@ -34,7 +29,6 @@ mkdir -p exp python3 -u ${BIN_DIR}/train.py \ --seed ${seed} \ ---device ${device} \ --nproc ${ngpu} \ --config ${config_path} \ --output exp/${ckpt_name} \ diff --git a/examples/callcenter/s1/local/align.sh b/examples/callcenter/s1/local/align.sh index f2c878c2..b679e2ea 100755 --- a/examples/callcenter/s1/local/align.sh +++ b/examples/callcenter/s1/local/align.sh @@ -8,10 +8,6 @@ fi ngpu=$(echo $CUDA_VISIBLE_DEVICES | awk -F "," '{print NF}') echo "using $ngpu gpus..." -device=gpu -if [ ${ngpu} == 0 ];then - device=cpu -fi config_path=$1 ckpt_prefix=$2 @@ -20,7 +16,6 @@ ckpt_name=$(basename ${ckpt_prefxi}) mkdir -p exp - batch_size=1 output_dir=${ckpt_prefix} mkdir -p ${output_dir} @@ -28,8 +23,7 @@ mkdir -p ${output_dir} # align dump in `result_file` # .tier, .TextGrid dump in `dir of result_file` python3 -u ${BIN_DIR}/alignment.py \ ---device ${device} \ ---nproc 1 \ +--nproc ${ngpu} \ --config ${config_path} \ --result_file ${output_dir}/${type}.align \ --checkpoint_path ${ckpt_prefix} \ diff --git a/examples/callcenter/s1/local/export.sh b/examples/callcenter/s1/local/export.sh index d171899c..d5f912e9 100755 --- a/examples/callcenter/s1/local/export.sh +++ b/examples/callcenter/s1/local/export.sh @@ -12,13 +12,7 @@ config_path=$1 ckpt_path_prefix=$2 jit_model_export_path=$3 -device=gpu -if [ ${ngpu} == 0 ];then - device=cpu -fi - python3 -u ${BIN_DIR}/export.py \ ---device ${device} \ --nproc ${ngpu} \ --config ${config_path} \ --checkpoint_path ${ckpt_path_prefix} \ diff --git a/examples/callcenter/s1/local/test.sh b/examples/callcenter/s1/local/test.sh index 7a5b1cdb..dca3137d 100755 --- a/examples/callcenter/s1/local/test.sh +++ b/examples/callcenter/s1/local/test.sh @@ -8,10 +8,6 @@ fi ngpu=$(echo $CUDA_VISIBLE_DEVICES | awk -F "," '{print NF}') echo "using $ngpu gpus..." -device=gpu -if [ ${ngpu} == 0 ];then - device=cpu -fi config_path=$1 ckpt_prefix=$2 @@ -32,8 +28,7 @@ for type in attention ctc_greedy_search; do output_dir=${ckpt_prefix} mkdir -p ${output_dir} python3 -u ${BIN_DIR}/test.py \ - --device ${device} \ - --nproc 1 \ + --nproc ${ngpu} \ --config ${config_path} \ --result_file ${output_dir}/${type}.rsl \ --checkpoint_path ${ckpt_prefix} \ @@ -51,8 +46,7 @@ for type in ctc_prefix_beam_search attention_rescoring; do output_dir=${ckpt_prefix} mkdir -p ${output_dir} python3 -u ${BIN_DIR}/test.py \ - --device ${device} \ - --nproc 1 \ + --nproc ${ngpu} \ --config ${config_path} \ --result_file ${output_dir}/${type}.rsl \ --checkpoint_path ${ckpt_prefix} \ diff --git a/examples/callcenter/s1/local/train.sh b/examples/callcenter/s1/local/train.sh index d5dc15b0..eb8f8662 100755 --- a/examples/callcenter/s1/local/train.sh +++ b/examples/callcenter/s1/local/train.sh @@ -11,10 +11,6 @@ echo "using $ngpu gpus..." config_path=$1 ckpt_name=$2 -device=gpu -if [ ${ngpu} == 0 ];then - device=cpu -fi echo "using ${device}..." mkdir -p exp @@ -26,7 +22,6 @@ if [ ${seed} != 0 ]; then fi python3 -u ${BIN_DIR}/train.py \ ---device ${device} \ --nproc ${ngpu} \ --config ${config_path} \ --output exp/${ckpt_name} \ diff --git a/examples/librispeech/s0/local/export.sh b/examples/librispeech/s0/local/export.sh index 2e09e5f5..a5e62c28 100755 --- a/examples/librispeech/s0/local/export.sh +++ b/examples/librispeech/s0/local/export.sh @@ -13,13 +13,7 @@ ckpt_path_prefix=$2 jit_model_export_path=$3 model_type=$4 -device=gpu -if [ ${ngpu} == 0 ];then - device=cpu -fi - python3 -u ${BIN_DIR}/export.py \ ---device ${device} \ --nproc ${ngpu} \ --config ${config_path} \ --checkpoint_path ${ckpt_path_prefix} \ diff --git a/examples/librispeech/s0/local/test.sh b/examples/librispeech/s0/local/test.sh index b5b68c59..4d00f30b 100755 --- a/examples/librispeech/s0/local/test.sh +++ b/examples/librispeech/s0/local/test.sh @@ -8,10 +8,6 @@ fi ngpu=$(echo $CUDA_VISIBLE_DEVICES | awk -F "," '{print NF}') echo "using $ngpu gpus..." -device=gpu -if [ ${ngpu} == 0 ];then - device=cpu -fi config_path=$1 ckpt_prefix=$2 model_type=$3 @@ -23,8 +19,7 @@ if [ $? -ne 0 ]; then fi python3 -u ${BIN_DIR}/test.py \ ---device ${device} \ ---nproc 1 \ +--nproc ${ngpu} \ --config ${config_path} \ --result_file ${ckpt_prefix}.rsl \ --checkpoint_path ${ckpt_prefix} \ diff --git a/examples/librispeech/s0/local/train.sh b/examples/librispeech/s0/local/train.sh index 6aee372a..519df7fe 100755 --- a/examples/librispeech/s0/local/train.sh +++ b/examples/librispeech/s0/local/train.sh @@ -12,12 +12,6 @@ config_path=$1 ckpt_name=$2 model_type=$3 -device=gpu -if [ ${ngpu} == 0 ];then - device=cpu -fi -echo "using ${device}..." - mkdir -p exp # seed may break model convergence @@ -27,7 +21,6 @@ if [ ${seed} != 0 ]; then fi python3 -u ${BIN_DIR}/train.py \ ---device ${device} \ --nproc ${ngpu} \ --config ${config_path} \ --output exp/${ckpt_name} \ diff --git a/examples/librispeech/s1/cmd.sh b/examples/librispeech/s1/cmd.sh new file mode 100644 index 00000000..7b70ef5e --- /dev/null +++ b/examples/librispeech/s1/cmd.sh @@ -0,0 +1,89 @@ +# ====== About run.pl, queue.pl, slurm.pl, and ssh.pl ====== +# Usage: .pl [options] JOB=1: +# e.g. +# run.pl --mem 4G JOB=1:10 echo.JOB.log echo JOB +# +# Options: +# --time