format and fix pre-commit (#1120)

pull/1122/head
Hui Zhang 3 years ago committed by GitHub
parent c4a79ccea4
commit 51d7a07c6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -25,6 +25,7 @@ import os
from pathlib import Path from pathlib import Path
import soundfile import soundfile
from utils.utility import download from utils.utility import download
from utils.utility import unpack from utils.utility import unpack

@ -25,6 +25,7 @@ import os
from pathlib import Path from pathlib import Path
import soundfile import soundfile
from utils.utility import download from utils.utility import download
from utils.utility import unpack from utils.utility import unpack

@ -27,6 +27,7 @@ import os
from multiprocessing.pool import Pool from multiprocessing.pool import Pool
import soundfile import soundfile
from utils.utility import download from utils.utility import download
from utils.utility import unpack from utils.utility import unpack

@ -26,6 +26,7 @@ import os
from multiprocessing.pool import Pool from multiprocessing.pool import Pool
import soundfile import soundfile
from utils.utility import download from utils.utility import download
from utils.utility import unpack from utils.utility import unpack

@ -28,6 +28,7 @@ import json
import os import os
import soundfile import soundfile
from utils.utility import download from utils.utility import download
from utils.utility import unpack from utils.utility import unpack

@ -28,6 +28,7 @@ import json
import os import os
import soundfile import soundfile
from utils.utility import download from utils.utility import download
from utils.utility import unzip from utils.utility import unzip

@ -26,6 +26,7 @@ from multiprocessing.pool import Pool
from pathlib import Path from pathlib import Path
import soundfile import soundfile
from utils.utility import download from utils.utility import download
from utils.utility import unpack from utils.utility import unpack

@ -27,6 +27,7 @@ import string
from pathlib import Path from pathlib import Path
import soundfile import soundfile
from utils.utility import unzip from utils.utility import unzip
URL_ROOT = "" URL_ROOT = ""

@ -27,6 +27,7 @@ import shutil
import subprocess import subprocess
import soundfile import soundfile
from utils.utility import download_multi from utils.utility import download_multi
from utils.utility import getfile_insensitive from utils.utility import getfile_insensitive
from utils.utility import unpack from utils.utility import unpack

@ -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 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 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 | | [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 |

@ -11,8 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import _locale import _locale
from .asr import ASRExecutor from .asr import ASRExecutor
from .base_commands import BaseCommand from .base_commands import BaseCommand
from .base_commands import HelpCommand from .base_commands import HelpCommand

@ -16,10 +16,11 @@ import os
import numpy as np import numpy as np
from paddle import inference from paddle import inference
from scipy.special import softmax
from paddleaudio.backends import load as load_audio from paddleaudio.backends import load as load_audio
from paddleaudio.datasets import ESC50 from paddleaudio.datasets import ESC50
from paddleaudio.features import melspectrogram from paddleaudio.features import melspectrogram
from scipy.special import softmax
# yapf: disable # yapf: disable
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()

@ -15,8 +15,8 @@ import argparse
import os import os
import paddle import paddle
from paddleaudio.datasets import ESC50
from paddleaudio.datasets import ESC50
from paddlespeech.cls.models import cnn14 from paddlespeech.cls.models import cnn14
from paddlespeech.cls.models import SoundClassifier from paddlespeech.cls.models import SoundClassifier

@ -16,11 +16,11 @@ import argparse
import numpy as np import numpy as np
import paddle import paddle
import paddle.nn.functional as F import paddle.nn.functional as F
from paddleaudio.backends import load as load_audio from paddleaudio.backends import load as load_audio
from paddleaudio.datasets import ESC50 from paddleaudio.datasets import ESC50
from paddleaudio.features import LogMelSpectrogram from paddleaudio.features import LogMelSpectrogram
from paddleaudio.features import melspectrogram from paddleaudio.features import melspectrogram
from paddlespeech.cls.models import cnn14 from paddlespeech.cls.models import cnn14
from paddlespeech.cls.models import SoundClassifier from paddlespeech.cls.models import SoundClassifier

@ -15,11 +15,11 @@ import argparse
import os import os
import paddle import paddle
from paddleaudio.datasets import ESC50 from paddleaudio.datasets import ESC50
from paddleaudio.features import LogMelSpectrogram from paddleaudio.features import LogMelSpectrogram
from paddleaudio.utils import logger from paddleaudio.utils import logger
from paddleaudio.utils import Timer from paddleaudio.utils import Timer
from paddlespeech.cls.models import cnn14 from paddlespeech.cls.models import cnn14
from paddlespeech.cls.models import SoundClassifier from paddlespeech.cls.models import SoundClassifier

@ -15,6 +15,7 @@ import os
import paddle.nn as nn import paddle.nn as nn
import paddle.nn.functional as F import paddle.nn.functional as F
from paddleaudio.utils.download import load_state_dict_from_url from paddleaudio.utils.download import load_state_dict_from_url
from paddleaudio.utils.env import MODEL_HOME from paddleaudio.utils.env import MODEL_HOME

@ -356,7 +356,7 @@ class AudioSegment():
# sox, slow # sox, slow
try: try:
import soxbindings as sox import soxbindings as sox
except: except ImportError:
try: try:
from paddlespeech.s2t.utils import dynamic_pip_install from paddlespeech.s2t.utils import dynamic_pip_install
package = "sox" package = "sox"
@ -364,8 +364,9 @@ class AudioSegment():
package = "soxbindings" package = "soxbindings"
dynamic_pip_install.install(package) dynamic_pip_install.install(package)
import soxbindings as sox import soxbindings as sox
except: except Exception:
raise RuntimeError("Can not install soxbindings on your system." ) raise RuntimeError(
"Can not install soxbindings on your system.")
tfm = sox.Transformer() tfm = sox.Transformer()
tfm.set_globals(multithread=False) tfm.set_globals(multithread=False)

@ -102,9 +102,11 @@ def read_manifest(
with jsonlines.open(manifest_path, 'r') as reader: with jsonlines.open(manifest_path, 'r') as reader:
for json_data in reader: for json_data in reader:
feat_len = json_data["input"][0]["shape"][ 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"][ 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 = [ conditions = [
feat_len >= min_input_len, feat_len >= min_input_len,
feat_len <= max_input_len, feat_len <= max_input_len,

@ -20,13 +20,13 @@ from paddle.io import DistributedBatchSampler
from paddlespeech.s2t.utils.log import Log from paddlespeech.s2t.utils.log import Log
logger = Log(__name__).getlog()
__all__ = [ __all__ = [
"SortagradDistributedBatchSampler", "SortagradDistributedBatchSampler",
"SortagradBatchSampler", "SortagradBatchSampler",
] ]
logger = Log(__name__).getlog()
def _batch_shuffle(indices, batch_size, epoch, clipped=False): def _batch_shuffle(indices, batch_size, epoch, clipped=False):
"""Put similarly-sized instances into minibatches for better efficiency """Put similarly-sized instances into minibatches for better efficiency

@ -17,11 +17,11 @@ from paddlespeech.s2t.utils import dynamic_pip_install
try: try:
import swig_decoders import swig_decoders
except: except ImportError:
try: try:
package_name = 'paddlespeech_ctcdecoders' package_name = 'paddlespeech_ctcdecoders'
dynamic_pip_install.install(package_name) dynamic_pip_install.install(package_name)
except: except Exception:
raise RuntimeError( raise RuntimeError(
"Can not install package paddlespeech_ctcdecoders on your system. \ "Can not install package paddlespeech_ctcdecoders on your system. \
The DeepSpeech2 model is not supported for your system") The DeepSpeech2 model is not supported for your system")

@ -129,7 +129,7 @@ class DeepSpeech2Model(nn.Layer):
rnn_layer_size=1024, #RNN layer size (number of RNN cells). 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. 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. 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: if config is not None:
config.merge_from_other_cfg(default) config.merge_from_other_cfg(default)
return default return default

@ -17,11 +17,11 @@ from paddlespeech.s2t.utils import dynamic_pip_install
try: try:
import swig_decoders import swig_decoders
except: except ImportError:
try: try:
package_name = 'paddlespeech_ctcdecoders' package_name = 'paddlespeech_ctcdecoders'
dynamic_pip_install.install(package_name) dynamic_pip_install.install(package_name)
except: except Exception:
raise RuntimeError( raise RuntimeError(
"Can not install package paddlespeech_ctcdecoders on your system. \ "Can not install package paddlespeech_ctcdecoders on your system. \
The DeepSpeech2 model is not supported for your system") The DeepSpeech2 model is not supported for your system")

@ -28,7 +28,7 @@ try:
from paddlespeech.s2t.decoders.ctcdecoder.swig_wrapper import ctc_beam_search_decoder_batch # noqa: F401 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 ctc_greedy_decoder # noqa: F401
from paddlespeech.s2t.decoders.ctcdecoder.swig_wrapper import Scorer # noqa: F401 from paddlespeech.s2t.decoders.ctcdecoder.swig_wrapper import Scorer # noqa: F401
except: except ImportError:
try: try:
from paddlespeech.s2t.utils import dynamic_pip_install from paddlespeech.s2t.utils import dynamic_pip_install
package_name = 'paddlespeech_ctcdecoders' package_name = 'paddlespeech_ctcdecoders'

@ -221,6 +221,8 @@ class Trainer():
if hasattr(self.train_loader, "batch_sampler"): if hasattr(self.train_loader, "batch_sampler"):
batch_sampler = self.train_loader.batch_sampler batch_sampler = self.train_loader.batch_sampler
if isinstance(batch_sampler, paddle.io.DistributedBatchSampler): if isinstance(batch_sampler, paddle.io.DistributedBatchSampler):
logger.debug(
f"train_loader.batch_sample set epoch: {self.epoch}")
batch_sampler.set_epoch(self.epoch) batch_sampler.set_epoch(self.epoch)
def before_train(self): def before_train(self):

@ -147,7 +147,7 @@ class SpeedPerturbationSox():
try: try:
import soxbindings as sox import soxbindings as sox
except: except ImportError:
try: try:
from paddlespeech.s2t.utils import dynamic_pip_install from paddlespeech.s2t.utils import dynamic_pip_install
package = "sox" package = "sox"
@ -155,8 +155,10 @@ class SpeedPerturbationSox():
package = "soxbindings" package = "soxbindings"
dynamic_pip_install.install(package) dynamic_pip_install.install(package)
import soxbindings as sox import soxbindings as sox
except: except Exception:
raise RuntimeError("Can not install soxbindings on your system." ) raise RuntimeError(
"Can not install soxbindings on your system.")
self.sox = sox
if utt2ratio is not None: if utt2ratio is not None:
self.utt2ratio = {} self.utt2ratio = {}
@ -200,7 +202,7 @@ class SpeedPerturbationSox():
else: else:
ratio = self.state.uniform(self.lower, self.upper) ratio = self.state.uniform(self.lower, self.upper)
tfm = sox.Transformer() tfm = self.sox.Transformer()
tfm.set_globals(multithread=False) tfm.set_globals(multithread=False)
tfm.speed(ratio) tfm.speed(ratio)
y = tfm.build_array(input_array=x, sample_rate_in=self.sr) y = tfm.build_array(input_array=x, sample_rate_in=self.sr)

@ -5,6 +5,7 @@ import functools
from pathlib import Path from pathlib import Path
import jsonlines import jsonlines
from utils.utility import add_arguments from utils.utility import add_arguments
from utils.utility import print_arguments from utils.utility import print_arguments

Loading…
Cancel
Save