Skip to content

Commit

Permalink
format and fix pre-commit (#1120)
Browse files Browse the repository at this point in the history
  • Loading branch information
zh794390558 committed Dec 14, 2021
1 parent c4a79cc commit 51d7a07
Show file tree
Hide file tree
Showing 26 changed files with 41 additions and 23 deletions.
1 change: 1 addition & 0 deletions dataset/aidatatang_200zh/aidatatang_200zh.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from pathlib import Path

import soundfile

from utils.utility import download
from utils.utility import unpack

Expand Down
1 change: 1 addition & 0 deletions dataset/aishell/aishell.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from pathlib import Path

import soundfile

from utils.utility import download
from utils.utility import unpack

Expand Down
1 change: 1 addition & 0 deletions dataset/librispeech/librispeech.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from multiprocessing.pool import Pool

import soundfile

from utils.utility import download
from utils.utility import unpack

Expand Down
1 change: 1 addition & 0 deletions dataset/mini_librispeech/mini_librispeech.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from multiprocessing.pool import Pool

import soundfile

from utils.utility import download
from utils.utility import unpack

Expand Down
1 change: 1 addition & 0 deletions dataset/musan/musan.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import os

import soundfile

from utils.utility import download
from utils.utility import unpack

Expand Down
1 change: 1 addition & 0 deletions dataset/rir_noise/rir_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import os

import soundfile

from utils.utility import download
from utils.utility import unzip

Expand Down
1 change: 1 addition & 0 deletions dataset/thchs30/thchs30.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from pathlib import Path

import soundfile

from utils.utility import download
from utils.utility import unpack

Expand Down
1 change: 1 addition & 0 deletions dataset/timit/timit.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from pathlib import Path

import soundfile

from utils.utility import unzip

URL_ROOT = ""
Expand Down
1 change: 1 addition & 0 deletions dataset/voxforge/voxforge.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import subprocess

import soundfile

from utils.utility import download_multi
from utils.utility import getfile_insensitive
from utils.utility import unpack
Expand Down
1 change: 0 additions & 1 deletion docs/source/released_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,3 @@ PANN | ESC-50 |[pann-esc50]("./examples/esc50/cls0")|[panns_cnn6.tar.gz](https:/
| [Ds2 Offline Aishell model](https://deepspeech.bj.bcebos.com/mandarin_models/aishell_model_v1.8_to_v2.x.tar.gz) | Aishell Dataset | Char-based | 234 MB | 2 Conv + 3 bidirectional GRU layers | 0.0804 | - | 151 h |
| [Ds2 Offline Librispeech model](https://deepspeech.bj.bcebos.com/eng_models/librispeech_v1.8_to_v2.x.tar.gz) | Librispeech Dataset | Word-based | 307 MB | 2 Conv + 3 bidirectional sharing weight RNN layers | - | 0.0685 | 960 h |
| [Ds2 Offline Baidu en8k model](https://deepspeech.bj.bcebos.com/eng_models/baidu_en8k_v1.8_to_v2.x.tar.gz) | Baidu Internal English Dataset | Word-based | 273 MB | 2 Conv + 3 bidirectional GRU layers | - | 0.0541 | 8628 h |

2 changes: 1 addition & 1 deletion paddlespeech/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import _locale

from .asr import ASRExecutor
from .base_commands import BaseCommand
from .base_commands import HelpCommand
Expand Down
3 changes: 2 additions & 1 deletion paddlespeech/cls/exps/panns/deploy/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

import numpy as np
from paddle import inference
from scipy.special import softmax

from paddleaudio.backends import load as load_audio
from paddleaudio.datasets import ESC50
from paddleaudio.features import melspectrogram
from scipy.special import softmax

# yapf: disable
parser = argparse.ArgumentParser()
Expand Down
2 changes: 1 addition & 1 deletion paddlespeech/cls/exps/panns/export_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import os

import paddle
from paddleaudio.datasets import ESC50

from paddleaudio.datasets import ESC50
from paddlespeech.cls.models import cnn14
from paddlespeech.cls.models import SoundClassifier

Expand Down
2 changes: 1 addition & 1 deletion paddlespeech/cls/exps/panns/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import numpy as np
import paddle
import paddle.nn.functional as F

from paddleaudio.backends import load as load_audio
from paddleaudio.datasets import ESC50
from paddleaudio.features import LogMelSpectrogram
from paddleaudio.features import melspectrogram

from paddlespeech.cls.models import cnn14
from paddlespeech.cls.models import SoundClassifier

Expand Down
2 changes: 1 addition & 1 deletion paddlespeech/cls/exps/panns/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import os

import paddle

from paddleaudio.datasets import ESC50
from paddleaudio.features import LogMelSpectrogram
from paddleaudio.utils import logger
from paddleaudio.utils import Timer

from paddlespeech.cls.models import cnn14
from paddlespeech.cls.models import SoundClassifier

Expand Down
1 change: 1 addition & 0 deletions paddlespeech/cls/models/panns/panns.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import paddle.nn as nn
import paddle.nn.functional as F

from paddleaudio.utils.download import load_state_dict_from_url
from paddleaudio.utils.env import MODEL_HOME

Expand Down
7 changes: 4 additions & 3 deletions paddlespeech/s2t/frontend/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,16 +356,17 @@ def change_speed(self, speed_rate):
# sox, slow
try:
import soxbindings as sox
except:
except ImportError:
try:
from paddlespeech.s2t.utils import dynamic_pip_install
package = "sox"
dynamic_pip_install.install(package)
package = "soxbindings"
dynamic_pip_install.install(package)
import soxbindings as sox
except:
raise RuntimeError("Can not install soxbindings on your system." )
except Exception:
raise RuntimeError(
"Can not install soxbindings on your system.")

tfm = sox.Transformer()
tfm.set_globals(multithread=False)
Expand Down
6 changes: 4 additions & 2 deletions paddlespeech/s2t/frontend/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ def read_manifest(
with jsonlines.open(manifest_path, 'r') as reader:
for json_data in reader:
feat_len = json_data["input"][0]["shape"][
0] if "input" in json_data and "shape" in json_data["input"][0] else 1.0
0] if "input" in json_data and "shape" in json_data["input"][
0] else 1.0
token_len = json_data["output"][0]["shape"][
0] if "output" in json_data and "shape" in json_data["output"][0] else 1.0
0] if "output" in json_data and "shape" in json_data["output"][
0] else 1.0
conditions = [
feat_len >= min_input_len,
feat_len <= max_input_len,
Expand Down
4 changes: 2 additions & 2 deletions paddlespeech/s2t/io/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@

from paddlespeech.s2t.utils.log import Log

logger = Log(__name__).getlog()

__all__ = [
"SortagradDistributedBatchSampler",
"SortagradBatchSampler",
]

logger = Log(__name__).getlog()


def _batch_shuffle(indices, batch_size, epoch, clipped=False):
"""Put similarly-sized instances into minibatches for better efficiency
Expand Down
4 changes: 2 additions & 2 deletions paddlespeech/s2t/models/ds2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

try:
import swig_decoders
except:
except ImportError:
try:
package_name = 'paddlespeech_ctcdecoders'
dynamic_pip_install.install(package_name)
except:
except Exception:
raise RuntimeError(
"Can not install package paddlespeech_ctcdecoders on your system. \
The DeepSpeech2 model is not supported for your system")
Expand Down
2 changes: 1 addition & 1 deletion paddlespeech/s2t/models/ds2/deepspeech2.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def params(cls, config: Optional[CfgNode]=None) -> CfgNode:
rnn_layer_size=1024, #RNN layer size (number of RNN cells).
use_gru=True, #Use gru if set True. Use simple rnn if set False.
share_rnn_weights=True, #Whether to share input-hidden weights between forward and backward directional RNNs.Notice that for GRU, weight sharing is not supported.
ctc_grad_norm_type=None,))
ctc_grad_norm_type=None, ))
if config is not None:
config.merge_from_other_cfg(default)
return default
Expand Down
4 changes: 2 additions & 2 deletions paddlespeech/s2t/models/ds2_online/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

try:
import swig_decoders
except:
except ImportError:
try:
package_name = 'paddlespeech_ctcdecoders'
dynamic_pip_install.install(package_name)
except:
except Exception:
raise RuntimeError(
"Can not install package paddlespeech_ctcdecoders on your system. \
The DeepSpeech2 model is not supported for your system")
Expand Down
2 changes: 1 addition & 1 deletion paddlespeech/s2t/modules/ctc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from paddlespeech.s2t.decoders.ctcdecoder.swig_wrapper import ctc_beam_search_decoder_batch # noqa: F401
from paddlespeech.s2t.decoders.ctcdecoder.swig_wrapper import ctc_greedy_decoder # noqa: F401
from paddlespeech.s2t.decoders.ctcdecoder.swig_wrapper import Scorer # noqa: F401
except:
except ImportError:
try:
from paddlespeech.s2t.utils import dynamic_pip_install
package_name = 'paddlespeech_ctcdecoders'
Expand Down
2 changes: 2 additions & 0 deletions paddlespeech/s2t/training/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ def maybe_batch_sampler_step(self):
if hasattr(self.train_loader, "batch_sampler"):
batch_sampler = self.train_loader.batch_sampler
if isinstance(batch_sampler, paddle.io.DistributedBatchSampler):
logger.debug(
f"train_loader.batch_sample set epoch: {self.epoch}")
batch_sampler.set_epoch(self.epoch)

def before_train(self):
Expand Down
10 changes: 6 additions & 4 deletions paddlespeech/s2t/transform/perturb.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,18 @@ def __init__(

try:
import soxbindings as sox
except:
except ImportError:
try:
from paddlespeech.s2t.utils import dynamic_pip_install
package = "sox"
dynamic_pip_install.install(package)
package = "soxbindings"
dynamic_pip_install.install(package)
import soxbindings as sox
except:
raise RuntimeError("Can not install soxbindings on your system." )
except Exception:
raise RuntimeError(
"Can not install soxbindings on your system.")
self.sox = sox

if utt2ratio is not None:
self.utt2ratio = {}
Expand Down Expand Up @@ -200,7 +202,7 @@ def __call__(self, x, uttid=None, train=True):
else:
ratio = self.state.uniform(self.lower, self.upper)

tfm = sox.Transformer()
tfm = self.sox.Transformer()
tfm.set_globals(multithread=False)
tfm.speed(ratio)
y = tfm.build_array(input_array=x, sample_rate_in=self.sr)
Expand Down
1 change: 1 addition & 0 deletions utils/manifest_key_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path

import jsonlines

from utils.utility import add_arguments
from utils.utility import print_arguments

Expand Down

0 comments on commit 51d7a07

Please sign in to comment.