Skip to content

Commit 37ea12a

Browse files
committed
🚀 reformat and update base model
1 parent 130124c commit 37ea12a

39 files changed

+2687
-1397
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ For tensorflow 2.4.x, run `pip3 install -U 'TensorFlowASR[tf2.4]'` or `pip3 inst
8787

8888
For tensorflow 2.5.x, run `pip3 install -U 'TensorFlowASR[tf2.5]'` or `pip3 install -U 'TensorFlowASR[tf2.5-gpu]'`
8989

90+
For tensorflow 2.6.x, run `pip3 install -U 'TensorFlowASR[tf2.6]'` or `pip3 install -U 'TensorFlowASR[tf2.6-gpu]'`
91+
9092
### Installing from source
9193

9294
```bash
9395
git clone https://github.com/TensorSpeech/TensorFlowASR.git
9496
cd TensorFlowASR
95-
pip3 install '.[tf2.3]' # or '.[tf2.3-gpu]' or '.[tf2.4]' or '.[tf2.4-gpu]' or '.[tf2.5]' or '.[tf2.5-gpu]'
97+
pip3 install -e '.[tf2.6]' # see other options in setup.py file
9698
```
9799

98100
For anaconda3:

examples/conformer/saved_model.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Copyright 2020 Huy Le Nguyen (@usimarit)
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import argparse
16+
import os
17+
18+
from tensorflow_asr.utils import env_util
19+
20+
logger = env_util.setup_environment()
21+
import tensorflow as tf
22+
23+
DEFAULT_YAML = os.path.join(os.path.abspath(os.path.dirname(__file__)), "config.yml")
24+
25+
tf.keras.backend.clear_session()
26+
27+
parser = argparse.ArgumentParser(prog="Conformer Testing")
28+
29+
parser.add_argument(
30+
"--config",
31+
type=str,
32+
default=DEFAULT_YAML,
33+
help="The file path of model configuration file",
34+
)
35+
36+
parser.add_argument(
37+
"--h5",
38+
type=str,
39+
default=None,
40+
help="Path to saved h5 weights",
41+
)
42+
43+
parser.add_argument(
44+
"--sentence_piece",
45+
default=False,
46+
action="store_true",
47+
help="Whether to use `SentencePiece` model",
48+
)
49+
50+
parser.add_argument(
51+
"--subwords",
52+
default=False,
53+
action="store_true",
54+
help="Use subwords",
55+
)
56+
57+
parser.add_argument(
58+
"--output_dir",
59+
type=str,
60+
default=None,
61+
help="Output directory for saved model",
62+
)
63+
64+
args = parser.parse_args()
65+
66+
assert args.h5
67+
assert args.output_dir
68+
69+
from tensorflow_asr.configs.config import Config
70+
from tensorflow_asr.featurizers.speech_featurizers import TFSpeechFeaturizer
71+
from tensorflow_asr.featurizers.text_featurizers import CharFeaturizer, SentencePieceFeaturizer, SubwordFeaturizer
72+
from tensorflow_asr.models.transducer.conformer import Conformer
73+
74+
config = Config(args.config)
75+
speech_featurizer = TFSpeechFeaturizer(config.speech_config)
76+
77+
if args.sentence_piece:
78+
logger.info("Use SentencePiece ...")
79+
text_featurizer = SentencePieceFeaturizer(config.decoder_config)
80+
elif args.subwords:
81+
logger.info("Use subwords ...")
82+
text_featurizer = SubwordFeaturizer(config.decoder_config)
83+
else:
84+
logger.info("Use characters ...")
85+
text_featurizer = CharFeaturizer(config.decoder_config)
86+
87+
tf.random.set_seed(0)
88+
89+
# build model
90+
conformer = Conformer(**config.model_config, vocabulary_size=text_featurizer.num_classes)
91+
conformer.make(speech_featurizer.shape)
92+
conformer.load_weights(args.h5, by_name=True)
93+
conformer.summary(line_length=100)
94+
conformer.add_featurizers(speech_featurizer, text_featurizer)
95+
96+
97+
class aModule(tf.Module):
98+
def __init__(self, model):
99+
super().__init__()
100+
self.model = model
101+
102+
@tf.function(
103+
input_signature=[
104+
{
105+
"inputs": tf.TensorSpec(shape=[None, None, 80, 1], dtype=tf.float32, name="inputs"),
106+
"inputs_length": tf.TensorSpec(shape=[None], dtype=tf.int32, name="inputs_length"),
107+
}
108+
]
109+
)
110+
def pred(self, input_batch):
111+
result = self.model.recognize(input_batch)
112+
return {"ASR": result}
113+
114+
115+
module = aModule(conformer)
116+
tf.saved_model.save(module, args.output_dir, signatures={"serving_default": module.pred})

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tool.black]
2+
line-length = 127

requirements.txt

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,67 @@
1-
cython
2-
numpy
3-
scipy
4-
sklearn
5-
pandas
6-
tensorflow-datasets>=4.2.0
7-
tensorflow-addons>=0.11.1
8-
setuptools>=47.1.1
9-
librosa>=0.8.0
10-
soundfile>=0.10.3
11-
PyYAML>=5.3.1
12-
matplotlib>=3.2.1
13-
sox>=1.4.1
14-
tqdm>=4.54.1
15-
colorama>=0.4.4
16-
nlpaug>=1.1.1
17-
nltk>=3.5
18-
sentencepiece>=0.1.94
1+
absl-py==0.12.0
2+
appdirs==1.4.4
3+
astroid==2.6.6
4+
attrs==21.2.0
5+
audioread==2.1.9
6+
black==21.7b0
7+
certifi==2021.5.30
8+
cffi==1.14.6
9+
charset-normalizer==2.0.4
10+
click==8.0.1
11+
colorama==0.4.4
12+
cycler==0.10.0
13+
Cython==0.29.24
14+
decorator==5.0.9
15+
dill==0.3.4
16+
flake8==3.9.2
17+
future==0.18.2
18+
googleapis-common-protos==1.53.0
19+
idna==3.2
20+
isort==5.9.3
21+
joblib==1.0.1
22+
kiwisolver==1.3.1
23+
lazy-object-proxy==1.6.0
24+
librosa==0.8.1
25+
llvmlite==0.36.0
26+
matplotlib==3.4.3
27+
mccabe==0.6.1
28+
mypy-extensions==0.4.3
29+
nlpaug==1.1.7
30+
nltk==3.6.2
31+
numba==0.53.1
32+
numpy==1.19.5
33+
packaging==21.0
34+
pandas==1.3.1
35+
pathspec==0.9.0
36+
Pillow==8.3.1
37+
pooch==1.4.0
38+
promise==2.3
39+
protobuf==3.17.3
40+
pycodestyle==2.7.0
41+
pycparser==2.20
42+
pyflakes==2.3.1
43+
pyparsing==2.4.7
44+
python-dateutil==2.8.2
45+
pytz==2021.1
46+
PyYAML==5.4.1
47+
regex==2021.8.3
48+
requests==2.26.0
49+
resampy==0.2.2
50+
scikit-learn==0.24.2
51+
scipy==1.7.1
52+
sentencepiece==0.1.96
53+
six==1.15.0
54+
sklearn==0.0
55+
SoundFile==0.10.3.post1
56+
sox==1.4.1
57+
tensorflow-addons==0.13.0
58+
tensorflow-datasets==4.4.0
59+
tensorflow-metadata==1.2.0
60+
termcolor==1.1.0
61+
threadpoolctl==2.2.0
62+
toml==0.10.2
63+
tomli==1.2.1
64+
tqdm==4.62.1
65+
typeguard==2.12.1
66+
urllib3==1.26.6
67+
wrapt==1.12.1

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[flake8]
2-
ignore = E402,E701,E702,E704,E251,W503,W504,C901
2+
ignore = E402,E701,E702,E704,E251,E203,W503,W504,C901
33
max-line-length = 127
44

55
[pep8]
6-
ignore = E402,E701,E702,E704,E251,W503,W504,C901
6+
ignore = E402,E701,E702,E704,E251,E203,W503,W504,C901
77
max-line-length = 127
88
indent-size = 4

setup.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
setuptools.setup(
2424
name="TensorFlowASR",
25-
version="1.0.2",
25+
version="1.0.3",
2626
author="Huy Le Nguyen",
2727
author_email="[email protected]",
2828
description="Almost State-of-the-art Automatic Speech Recognition using Tensorflow 2",
@@ -32,12 +32,14 @@
3232
packages=setuptools.find_packages(include=["tensorflow_asr*"]),
3333
install_requires=requirements,
3434
extras_require={
35-
"tf2.3": ["tensorflow>=2.3.0,<2.4", "tensorflow-text>2.3.0,<2.4", "tensorflow-io>=0.16.0,<0.17"],
36-
"tf2.3-gpu": ["tensorflow-gpu>=2.3.0,<2.4", "tensorflow-text>=2.3.0,<2.4", "tensorflow-io>=0.16.0,<0.17"],
37-
"tf2.4": ["tensorflow>=2.4.0,<2.5", "tensorflow-text>=2.4.0,<2.5", "tensorflow-io>=0.17.0,<0.18"],
38-
"tf2.4-gpu": ["tensorflow-gpu>=2.4.0,<2.5", "tensorflow-text>=2.4.0,<2.5", "tensorflow-io>=0.17.0,<0.18"],
39-
"tf2.5": ["tensorflow>=2.5.0,<2.6", "tensorflow-text>=2.5.0,<2.6", "tensorflow-io>=0.18.0,<0.19"],
40-
"tf2.5-gpu": ["tensorflow-gpu>=2.5.0,<2.6", "tensorflow-text>=2.5.0,<2.6", "tensorflow-io>=0.18.0,<0.19"]
35+
"tf2.3": ["tensorflow~=2.3.0", "tensorflow-text~=2.3.0", "tensorflow-io~=0.16.0"],
36+
"tf2.3-gpu": ["tensorflow-gpu~=2.3.0", "tensorflow-text~=2.3.0", "tensorflow-io~=0.16.0"],
37+
"tf2.4": ["tensorflow~=2.4.0", "tensorflow-text~=2.4.0", "tensorflow-io~=0.17.0"],
38+
"tf2.4-gpu": ["tensorflow-gpu~=2.4.0", "tensorflow-text~=2.4.0", "tensorflow-io~=0.17.0"],
39+
"tf2.5": ["tensorflow~=2.5.0", "tensorflow-text~=2.5.0", "tensorflow-io~=0.18.0"],
40+
"tf2.5-gpu": ["tensorflow-gpu~=2.5.0", "tensorflow-text~=2.5.0", "tensorflow-io~=0.18.0"],
41+
"tf2.6": ["tensorflow~=2.6.0", "tensorflow-text~=2.6.0rc0", "tensorflow-io~=0.20.0"],
42+
"tf2.6-gpu": ["tensorflow-gpu~=2.6.0", "tensorflow-text~=2.6.0rc0", "tensorflow-io~=0.20.0"],
4143
},
4244
classifiers=[
4345
"Programming Language :: Python :: 3.6",
@@ -46,7 +48,7 @@
4648
"Intended Audience :: Science/Research",
4749
"Operating System :: POSIX :: Linux",
4850
"License :: OSI Approved :: Apache Software License",
49-
"Topic :: Software Development :: Libraries :: Python Modules"
51+
"Topic :: Software Development :: Libraries :: Python Modules",
5052
],
51-
python_requires='>=3.6',
53+
python_requires=">=3.6",
5254
)

0 commit comments

Comments
 (0)