Path: blob/master/notebooks/TensorFlowTTS_Tacotron2_with_TFLite.ipynb
1558 views
Kernel: Python 3
Copyright 2020 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
In [1]:
Author : jaeyoo@, khanhlvg@, abattery@, thaink@ (Google Research)
Created : 2020-06-30 KST
Last updated : 2020-07-04 KST
Change logs
2020-07-04 KST : Update notebook with the lastest TensorflowTTS repo.
compatible with https://github.com/TensorSpeech/TensorflowTTS/pull/83
2020-07-02 KST : Third implementation (outputs :
tacotron2.tflite)varied-length input tensor, varied-length output tensor
Status : successfully converted (tacotron2.tflite)
Disclaimer
This colab doesn't care about the latency, so it compressed the model with quantization. (129 MB -> 33 MB)
The TFLite file doesn't have LJSpeechProcessor. So you need to run it before feeding input vectors.
tf-nightly>=2.4.0-dev20200630
Generate voice with Tacotron2
In [2]:
Out[2]:
Requirement already satisfied: tf-nightly in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (2.4.0.dev20200716)
Requirement already satisfied: astunparse==1.6.3 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tf-nightly) (1.6.3)
Requirement already satisfied: gast==0.3.3 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tf-nightly) (0.3.3)
Requirement already satisfied: wrapt>=1.11.1 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tf-nightly) (1.12.1)
Requirement already satisfied: six>=1.12.0 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tf-nightly) (1.15.0)
Requirement already satisfied: grpcio>=1.8.6 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tf-nightly) (1.30.0)
Requirement already satisfied: numpy<1.19.0,>=1.16.0 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tf-nightly) (1.18.5)
Requirement already satisfied: absl-py>=0.7.0 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tf-nightly) (0.9.0)
Requirement already satisfied: keras-preprocessing<1.2,>=1.1.1 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tf-nightly) (1.1.2)
Requirement already satisfied: protobuf>=3.9.2 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tf-nightly) (3.12.2)
Requirement already satisfied: wheel>=0.26 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tf-nightly) (0.34.2)
Requirement already satisfied: opt-einsum>=2.3.2 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tf-nightly) (3.2.1)
Requirement already satisfied: tb-nightly<2.4.0a0,>=2.3.0a0 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tf-nightly) (2.3.0a20200716)
Requirement already satisfied: google-pasta>=0.1.8 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tf-nightly) (0.2.0)
Requirement already satisfied: tf-estimator-nightly in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tf-nightly) (2.4.0.dev2020071601)
Requirement already satisfied: h5py<2.11.0,>=2.10.0 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tf-nightly) (2.10.0)
Requirement already satisfied: termcolor>=1.1.0 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tf-nightly) (1.1.0)
Requirement already satisfied: setuptools in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from protobuf>=3.9.2->tf-nightly) (49.2.0.post20200714)
Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tb-nightly<2.4.0a0,>=2.3.0a0->tf-nightly) (0.4.1)
Requirement already satisfied: werkzeug>=0.11.15 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tb-nightly<2.4.0a0,>=2.3.0a0->tf-nightly) (1.0.1)
Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tb-nightly<2.4.0a0,>=2.3.0a0->tf-nightly) (1.7.0)
Requirement already satisfied: google-auth<2,>=1.6.3 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tb-nightly<2.4.0a0,>=2.3.0a0->tf-nightly) (1.19.1)
Requirement already satisfied: markdown>=2.6.8 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tb-nightly<2.4.0a0,>=2.3.0a0->tf-nightly) (3.2.2)
Requirement already satisfied: requests<3,>=2.21.0 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from tb-nightly<2.4.0a0,>=2.3.0a0->tf-nightly) (2.24.0)
Requirement already satisfied: requests-oauthlib>=0.7.0 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from google-auth-oauthlib<0.5,>=0.4.1->tb-nightly<2.4.0a0,>=2.3.0a0->tf-nightly) (1.3.0)
Requirement already satisfied: pyasn1-modules>=0.2.1 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from google-auth<2,>=1.6.3->tb-nightly<2.4.0a0,>=2.3.0a0->tf-nightly) (0.2.8)
Requirement already satisfied: cachetools<5.0,>=2.0.0 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from google-auth<2,>=1.6.3->tb-nightly<2.4.0a0,>=2.3.0a0->tf-nightly) (4.1.1)
Requirement already satisfied: rsa<5,>=3.1.4; python_version >= "3" in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from google-auth<2,>=1.6.3->tb-nightly<2.4.0a0,>=2.3.0a0->tf-nightly) (4.6)
Requirement already satisfied: importlib-metadata; python_version < "3.8" in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from markdown>=2.6.8->tb-nightly<2.4.0a0,>=2.3.0a0->tf-nightly) (1.7.0)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from requests<3,>=2.21.0->tb-nightly<2.4.0a0,>=2.3.0a0->tf-nightly) (1.25.9)
Requirement already satisfied: certifi>=2017.4.17 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from requests<3,>=2.21.0->tb-nightly<2.4.0a0,>=2.3.0a0->tf-nightly) (2020.6.20)
Requirement already satisfied: chardet<4,>=3.0.2 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from requests<3,>=2.21.0->tb-nightly<2.4.0a0,>=2.3.0a0->tf-nightly) (3.0.4)
Requirement already satisfied: idna<3,>=2.5 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from requests<3,>=2.21.0->tb-nightly<2.4.0a0,>=2.3.0a0->tf-nightly) (2.10)
Requirement already satisfied: oauthlib>=3.0.0 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tb-nightly<2.4.0a0,>=2.3.0a0->tf-nightly) (3.1.0)
Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from pyasn1-modules>=0.2.1->google-auth<2,>=1.6.3->tb-nightly<2.4.0a0,>=2.3.0a0->tf-nightly) (0.4.8)
Requirement already satisfied: zipp>=0.5 in /home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages (from importlib-metadata; python_version < "3.8"->markdown>=2.6.8->tb-nightly<2.4.0a0,>=2.3.0a0->tf-nightly) (3.1.0)
In [3]:
Out[3]:
/home/lap13839/anaconda3/envs/tflite/lib/python3.7/site-packages/tensorflow_addons/utils/ensure_tf_install.py:44: UserWarning: You are currently using a nightly version of TensorFlow (2.4.0-dev20200716).
TensorFlow Addons offers no support for the nightly versions of TensorFlow. Some things might work, some other might not.
If you encounter a bug, do not file an issue on GitHub.
UserWarning,
2.4.0-dev20200716
In [4]:
In [6]:
Out[6]:
Model: "tacotron2v2"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
encoder (TFTacotronEncoder) multiple 8218624
_________________________________________________________________
decoder_cell (TFTacotronDeco multiple 18246402
_________________________________________________________________
post_net (TFTacotronPostnet) multiple 5460480
_________________________________________________________________
residual_projection (Dense) multiple 41040
=================================================================
Total params: 31,966,546
Trainable params: 31,956,306
Non-trainable params: 10,240
_________________________________________________________________
Convert to TF Lite
In [10]:
In [11]:
In [12]:
Out[12]:
Model size is 33.242188 MBs.
In [13]:
Inference from TFLite
In [14]:
In [15]:
Out[15]:
{'name': 'input_ids', 'index': 0, 'shape': array([1, 1], dtype=int32), 'shape_signature': array([ 1, -1], dtype=int32), 'dtype': <class 'numpy.int32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}
{'name': 'input_lengths', 'index': 1, 'shape': array([1], dtype=int32), 'shape_signature': array([1], dtype=int32), 'dtype': <class 'numpy.int32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}
{'name': 'speaker_ids', 'index': 2, 'shape': array([1], dtype=int32), 'shape_signature': array([1], dtype=int32), 'dtype': <class 'numpy.int32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}
In [16]:
Out[16]:
In [17]:
Out[17]:
In [18]:
Out[18]:
{'name': 'input_ids', 'index': 0, 'shape': array([1, 1], dtype=int32), 'shape_signature': array([ 1, -1], dtype=int32), 'dtype': <class 'numpy.int32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}
{'name': 'input_lengths', 'index': 1, 'shape': array([1], dtype=int32), 'shape_signature': array([1], dtype=int32), 'dtype': <class 'numpy.int32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}
{'name': 'speaker_ids', 'index': 2, 'shape': array([1], dtype=int32), 'shape_signature': array([1], dtype=int32), 'dtype': <class 'numpy.int32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}
In [19]:
Out[19]:
In [20]:
Out[20]:
In [ ]: