From 3cff3dd0de08622bde224cbeb408818f529da27c Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Fri, 6 Aug 2021 16:52:55 +0200 Subject: [PATCH 1/2] Add an --export_quantize flag to control TFLite export quantization --- training/coqui_stt_training/train.py | 5 ++++- training/coqui_stt_training/util/config.py | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/training/coqui_stt_training/train.py b/training/coqui_stt_training/train.py index 42b1767c..22baa57c 100644 --- a/training/coqui_stt_training/train.py +++ b/training/coqui_stt_training/train.py @@ -1116,7 +1116,10 @@ def export(): input_tensors=inputs.values(), output_tensors=outputs.values(), ) - converter.optimizations = [tf.lite.Optimize.DEFAULT] + + if Config.export_quantize: + converter.optimizations = [tf.lite.Optimize.DEFAULT] + # AudioSpectrogram and Mfcc ops are custom but have built-in kernels in TFLite converter.allow_custom_ops = True tflite_model = converter.convert() diff --git a/training/coqui_stt_training/util/config.py b/training/coqui_stt_training/util/config.py index b426fb7a..0b072243 100755 --- a/training/coqui_stt_training/util/config.py +++ b/training/coqui_stt_training/util/config.py @@ -22,7 +22,7 @@ class _ConfigSingleton: _config = None def __getattr__(self, name): - if not _ConfigSingleton._config: + if _ConfigSingleton._config is None: raise RuntimeError("Global configuration not yet initialized.") if not hasattr(_ConfigSingleton._config, name): raise RuntimeError( @@ -478,6 +478,10 @@ class _SttConfig(Coqpit): export_tflite: bool = field( default=False, metadata=dict(help="export a graph ready for TF Lite engine") ) + export_quantize: bool = field( + default=True, + metadata=dict(help="export a quantized model (optimized for size)"), + ) n_steps: int = field( default=16, metadata=dict( From f71e32735ffdbc05ee60397ef823ba2cdf15a843 Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Fri, 6 Aug 2021 16:55:42 +0200 Subject: [PATCH 2/2] Add a more explicit error message when alphabet is not specified --- training/coqui_stt_training/train.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/training/coqui_stt_training/train.py b/training/coqui_stt_training/train.py index 22baa57c..6be4ef55 100644 --- a/training/coqui_stt_training/train.py +++ b/training/coqui_stt_training/train.py @@ -1259,6 +1259,10 @@ def early_training_checks(): "for loading and saving." ) + if not Config.alphabet_config_path and not Config.bytes_output_mode: + log_error("Missing --alphabet_config_path flag, can't continue") + sys.exit(1) + def main(): initialize_globals_from_cli()