diff --git a/paddlespeech/s2t/decoders/__init__.py b/paddlespeech/s2t/decoders/__init__.py index f04a6d19..185a92b8 100644 --- a/paddlespeech/s2t/decoders/__init__.py +++ b/paddlespeech/s2t/decoders/__init__.py @@ -11,4 +11,3 @@ # 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. -from .ctcdecoder import swig_wrapper diff --git a/paddlespeech/s2t/models/ds2/__init__.py b/paddlespeech/s2t/models/ds2/__init__.py index 39bea5bf..efa50863 100644 --- a/paddlespeech/s2t/models/ds2/__init__.py +++ b/paddlespeech/s2t/models/ds2/__init__.py @@ -13,5 +13,17 @@ # limitations under the License. from .deepspeech2 import DeepSpeech2InferModel from .deepspeech2 import DeepSpeech2Model +from paddlespeech.s2t.utils import dynamic_pip_install + +try: + import swig_decoders +except: + try: + package_name = 'paddlespeech_ctcdecoders' + dynamic_pip_install.install(package_name) + except: + raise RuntimeError( + "Can not install package paddlespeech_ctcdecoders on your system. \ + The DeepSpeech2 model is not supported for your system") __all__ = ['DeepSpeech2Model', 'DeepSpeech2InferModel'] diff --git a/paddlespeech/s2t/models/ds2_online/__init__.py b/paddlespeech/s2t/models/ds2_online/__init__.py index 255000ee..65ddd512 100644 --- a/paddlespeech/s2t/models/ds2_online/__init__.py +++ b/paddlespeech/s2t/models/ds2_online/__init__.py @@ -13,5 +13,17 @@ # limitations under the License. from .deepspeech2 import DeepSpeech2InferModelOnline from .deepspeech2 import DeepSpeech2ModelOnline +from paddlespeech.s2t.utils import dynamic_pip_install + +try: + import swig_decoders +except: + try: + package_name = 'paddlespeech_ctcdecoders' + dynamic_pip_install.install(package_name) + except: + raise RuntimeError( + "Can not install package paddlespeech_ctcdecoders on your system. \ + The DeepSpeech2 model is not supported for your system") __all__ = ['DeepSpeech2ModelOnline', 'DeepSpeech2InferModelOnline'] diff --git a/paddlespeech/s2t/modules/ctc.py b/paddlespeech/s2t/modules/ctc.py index 120abd2b..774bcc62 100644 --- a/paddlespeech/s2t/modules/ctc.py +++ b/paddlespeech/s2t/modules/ctc.py @@ -28,8 +28,20 @@ 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_greedy_decoder # noqa: F401 from paddlespeech.s2t.decoders.ctcdecoder.swig_wrapper import Scorer # noqa: F401 -except Exception as e: - logger.info("ctcdecoder not installed!") +except: + try: + from paddlespeech.s2t.utils import dynamic_pip_install + package_name = 'paddlespeech_ctcdecoders' + dynamic_pip_install.install(package_name) + 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 Exception as e: + logger.info("paddlespeech_ctcdecoders not installed!") + +#try: +#except Exception as e: +# logger.info("ctcdecoder not installed!") __all__ = ['CTCDecoder'] @@ -51,7 +63,7 @@ class CTCDecoderBase(nn.Layer): dropout_rate (float): dropout rate (0.0 ~ 1.0) reduction (bool): reduce the CTC loss into a scalar, True for 'sum' or 'none' batch_average (bool): do batch dim wise average. - grad_norm_type (str): Default, None. one of 'instance', 'batch', 'frame', None. + grad_norm_type (str): Default, None. one of 'instance', 'batch', 'frame', None. """ assert check_argument_types() super().__init__() diff --git a/paddlespeech/s2t/utils/dynamic_pip_install.py b/paddlespeech/s2t/utils/dynamic_pip_install.py new file mode 100644 index 00000000..39e9c35f --- /dev/null +++ b/paddlespeech/s2t/utils/dynamic_pip_install.py @@ -0,0 +1,22 @@ +# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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 pip + + +def install(package_name): + if int(pip.__version__.split('.')[0]) > 9: + from pip._internal import main + else: + from pip import main + main(['install', package_name]) diff --git a/setup.py b/setup.py index c1ae00ce..3841183c 100644 --- a/setup.py +++ b/setup.py @@ -45,7 +45,6 @@ requirements = { "nltk", "pandas", "paddleaudio", - "paddlespeech_ctcdecoders", "paddlespeech_feat", "praatio~=4.1", "pypi-kenlm", @@ -71,6 +70,7 @@ requirements = { "ConfigArgParse", "coverage", "gpustat", + "paddlespeech_ctcdecoders", "phkit", "Pillow", "pybind11",