diff --git a/.travis/unittest.sh b/.travis/unittest.sh index 8e3071d05be0b8041dc04acf0d7c7ceb06298c44..c152a1bc57e156f4a1856d6dc9aa0d787d929bc9 100755 --- a/.travis/unittest.sh +++ b/.travis/unittest.sh @@ -1,5 +1,14 @@ #!/bin/bash + + +abort(){ + echo "Run unittest failed" 1>&2 + echo "Please check your code" 1>&2 + exit 1 +} + + unittest(){ cd $1 > /dev/null find . -path ./tools/venv -prune -false -o -name 'tests' -type d -print0 | \ @@ -8,17 +17,22 @@ unittest(){ cd - > /dev/null } -abort(){ - echo "Run unittest failed" 1>&2 - echo "Please check your code" 1>&2 - exit 1 +coverage(){ + cd $1 > /dev/null + find . -path ./tools/venv -prune -false -o -name 'tests' -type d -print0 | \ + xargs -0 -I{} -n1 bash -c \ + 'python3 -m coverage run --branch {}' + python3 -m coverage report -m + python3 -m coverage html + cd - > /dev/null } trap 'abort' 0 set -e source tools/venv/bin/activate -pip3 install pytest -unittest . +#pip3 install pytest +#unittest . +coverage . trap : 0 diff --git a/deepspeech/exps/u2/model.py b/deepspeech/exps/u2/model.py index 0a09eeda106db2bd2a76a4c63c5f1e551fcf7c7a..6221b93183e89cda7d6c515d48d9eb66e3fd0d12 100644 --- a/deepspeech/exps/u2/model.py +++ b/deepspeech/exps/u2/model.py @@ -74,7 +74,7 @@ class U2Trainer(Trainer): def __init__(self, config, args): super().__init__(config, args) - def train_batch(self, batch_data): + def train_batch(self, batch_data, msg): train_conf = self.config.training self.model.train() @@ -93,12 +93,9 @@ class U2Trainer(Trainer): 'train_att_loss': float(attention_loss), 'train_ctc_loss': float(ctc_loss), } - msg = "Train: Rank: {}, ".format(dist.get_rank()) - msg += "epoch: {}, ".format(self.epoch) - msg += "step: {}, ".format(self.iteration) msg += "time: {:>.3f}s, ".format(iteration_time) - msg += f"batch size: {self.config.data.batch_size}, " - msg += f"accum: {train_config.accum_grad}, " + msg += "batch size: {}, ".format(self.config.data.batch_size) + msg += "accum: {}, ".format(train_conf.accum_grad) msg += ', '.join('{}: {:>.6f}'.format(k, v) for k, v in losses_np.items()) if self.iteration % train_conf.log_interval == 0: diff --git a/deepspeech/models/deepspeech2.py b/deepspeech/models/deepspeech2.py index 727f64c02cd4922612a099194266a3f1f4c3f695..7cba2f2cb8c23d3d48fa71ffd2cd79041745b017 100644 --- a/deepspeech/models/deepspeech2.py +++ b/deepspeech/models/deepspeech2.py @@ -16,6 +16,7 @@ import logging from typing import Optional from yacs.config import CfgNode +import paddle from paddle import nn from deepspeech.modules.conv import ConvStack diff --git a/deepspeech/models/u2.py b/deepspeech/models/u2.py index c875a5ab546d90c54482bd449fb16abe77e00236..95c13d4028273719c90d849a3506b3871aba521c 100644 --- a/deepspeech/models/u2.py +++ b/deepspeech/models/u2.py @@ -761,8 +761,10 @@ class U2Model(U2BaseModel): Returns: DeepSpeech2Model: The model built from pretrained result. """ - config.input_dim = self.dataset.feature_size - config.output_dim = self.dataset.vocab_size + config.defrost() + config.input_dim = dataset.feature_size + config.output_dim = dataset.vocab_size + config.freeze() model = cls.from_config(config) if checkpoint_path: diff --git a/deepspeech/training/trainer.py b/deepspeech/training/trainer.py index b03508cb8e71e76b5990e5ba7a7070bdfff2a76f..982faa989dfc0956f709670aea9b5760c15ea698 100644 --- a/deepspeech/training/trainer.py +++ b/deepspeech/training/trainer.py @@ -181,13 +181,12 @@ class Trainer(): msg += "epoch: {}, ".format(self.epoch) msg += "step: {}, ".format(self.iteration) msg += "dataloader time: {:>.3f}s, ".format(dataload_time) - self.logger.info(msg) self.iteration += 1 - self.train_batch(batch) + self.train_batch(batch, msg) data_start_time = time.time() except Exception as e: self.logger.error(e) - pass + raise e self.valid() self.save() diff --git a/examples/tiny/s1/local/export.sh b/examples/tiny/s1/local/export.sh new file mode 100644 index 0000000000000000000000000000000000000000..864ecb2d5bf754c1af1ea2c4787f7d24e66c83ef --- /dev/null +++ b/examples/tiny/s1/local/export.sh @@ -0,0 +1,20 @@ +#! /usr/bin/env bash + +if [ $# != 2 ];then + echo "usage: export ckpt_path jit_model_path" + exit -1 +fi + +python3 -u ${BIN_DIR}/export.py \ +--config conf/conformer.yaml \ +--checkpoint_path ${1} \ +--export_path ${2} + + +if [ $? -ne 0 ]; then + echo "Failed in evaluation!" + exit 1 +fi + + +exit 0 diff --git a/examples/tiny/s1/local/test.sh b/examples/tiny/s1/local/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..6dbb1c388986cbd60248ffe368369d3d3513e358 --- /dev/null +++ b/examples/tiny/s1/local/test.sh @@ -0,0 +1,22 @@ +#! /usr/bin/env bash + +# download language model +bash local/download_lm_en.sh +if [ $? -ne 0 ]; then + exit 1 +fi + +CUDA_VISIBLE_DEVICES=0 \ +python3 -u ${BIN_DIR}/test.py \ +--device 'gpu' \ +--nproc 1 \ +--config conf/conformer.yaml \ +--output ckpt + +if [ $? -ne 0 ]; then + echo "Failed in evaluation!" + exit 1 +fi + + +exit 0 diff --git a/examples/tiny/s1/local/train.sh b/examples/tiny/s1/local/train.sh index c2e62c613c94ef7f06f94cbd11126b9d6ba26d10..6511614a99bacba58b69fadf6482e39d6f206fba 100644 --- a/examples/tiny/s1/local/train.sh +++ b/examples/tiny/s1/local/train.sh @@ -1,7 +1,5 @@ #! /usr/bin/env bash -export FLAGS_sync_nccl_allreduce=0 - CUDA_VISIBLE_DEVICES=0 \ python3 -u ${BIN_DIR}/train.py \ --device 'gpu' \ diff --git a/requirements.txt b/requirements.txt index bfc45d0b8413914c143a603795c4f128299cdd97..40b4cef38cf7e75acc33e7726827839203ca9d5f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +coverage pre-commit python_speech_features resampy==0.2.2