diff --git a/docs/source/api/modelscope.pipelines.rst b/docs/source/api/modelscope.pipelines.rst index 167b5cd3..e5758046 100644 --- a/docs/source/api/modelscope.pipelines.rst +++ b/docs/source/api/modelscope.pipelines.rst @@ -1,21 +1,6 @@ modelscope.pipelines package ============================ -.. automodule:: modelscope.pipelines - :members: - :undoc-members: - :show-inheritance: - -Subpackages ------------ - -.. toctree:: - :maxdepth: 4 - - modelscope.pipelines.audio - modelscope.pipelines.cv - modelscope.pipelines.multi_modal - modelscope.pipelines.nlp Submodules ---------- @@ -25,8 +10,6 @@ modelscope.pipelines.base module .. automodule:: modelscope.pipelines.base :members: - :undoc-members: - :show-inheritance: modelscope.pipelines.builder module ----------------------------------- diff --git a/docs/source/change_log.md b/docs/source/change_log.md index 047df483..1081c148 100644 --- a/docs/source/change_log.md +++ b/docs/source/change_log.md @@ -1,3 +1,60 @@ +## v 0.2.2 (05/07/2022) +Second internal release. + +### Highlights + +### Algorithms +#### CV +* add cv-person-image-cartoon pipeline +* add action recognition pipeline +* add ocr detection pipeline +* add animal recognition model +* add cmdssl video embedding extraction pipeline + +#### NLP +* add speech AEC pipeline +* add palm2.0 +* add space model +* add MPLUG model +* add dialog_intent, dialog_modeling, dialog state tracking pipleline +* add maskedlm model and fill_mask pipeline +* add nli pipeline +* add sentence similarity pipeline +* add sentiment_classification pipeline +* add text generation pipeline +* add translation pipeline +* add chinese word segmentation pipeline +* add zero-shot classification + +#### Audio +* add tts pipeline +* add kws kwsbp pipline +* add linear aec pipeline +* add ans pipeline + +#### Multi-Modal +* add image captioning pipeline +* add multi-modal feature extraction pipeline +* add text to image synthesis pipeline +* add VQA pipeline + +### Framework +* add msdataset interface +* add hub interface and cache support +* support multiple models in single pipeline +* add default model configuration for each pipeline +* remove task field image and video, using cv instead +* dockerfile support +* multi-level tests support +* sphinx-docs use book theme +* formalize the output of pipeline and make pipeline reusable +* pipeline refactor and standardize module_name +* self-host repo support + +### Bug Fix +* support kwargs in pipeline +* fix errors in task name definition + ## v 0.1.0 (20/05/2022) First internal release for pipeline inference diff --git a/docs/source/faq.md b/docs/source/faq.md index 6ed3b305..2f6a43dc 100644 --- a/docs/source/faq.md +++ b/docs/source/faq.md @@ -41,3 +41,8 @@ reference: [https://huggingface.co/docs/tokenizers/installation#installation-fro ```shell pip install -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt ``` +### 4. zsh: no matches found: model_scope-0.2.2-py3-none-any.whl[all] +mac终端的zsh 对于[]需要做转义,执行如下命令 +```shell +pip install model_scope\[all\] -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html +``` diff --git a/docs/source/index.rst b/docs/source/index.rst index e93c7aed..11b6ee49 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -29,15 +29,15 @@ ModelScope doc change_log.md -.. toctree:: - :maxdepth: 10 - :caption: API Doc - - api/modelscope.preprocessors - api/modelscope.models - api/modelscope.pipelines - api/modelscope.fileio - api/modelscope.utils +.. .. toctree:: +.. :maxdepth: 10 +.. :caption: API Doc + +.. api/modelscope.preprocessors +.. api/modelscope.models +.. api/modelscope.pipelines +.. api/modelscope.fileio +.. api/modelscope.utils Indices and tables diff --git a/docs/source/quick_start.md b/docs/source/quick_start.md index 0d1f47ac..5306cc97 100644 --- a/docs/source/quick_start.md +++ b/docs/source/quick_start.md @@ -1,6 +1,8 @@ # 快速开始 -ModelScope Library目前支持tensorflow,pytorch深度学习框架进行模型训练、推理, 在Python 3.7+, Pytorch 1.8+, Tensorflow1.15+,Tensorflow 2.6上测试可运行。 -注: 当前(630)版本仅支持python3.7 以及linux环境,其他环境(mac,windows等)支持预计730完成。 +ModelScope Library目前支持tensorflow,pytorch深度学习框架进行模型训练、推理, 在Python 3.7+, Pytorch 1.8+, Tensorflow1.13-1.15,Tensorflow 2.x上测试可运行。 + +注: 当前(630)版本 `语音相关`的功能仅支持 python3.7,tensorflow1.13-1.15的`linux`环境使用。 其他功能可以在windows、mac上安装使用。 + ## python环境配置 首先,参考[文档](https://docs.anaconda.com/anaconda/install/) 安装配置Anaconda环境 @@ -25,7 +27,12 @@ pip install --upgrade tensorflow ### pip安装 执行如下命令: ```shell -pip install model_scope[all] -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/0.2/repo.html +pip install "model_scope[all]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html +``` + +如需体验`语音功能`,请`额外`执行如下命令: +```shell +pip install "model_scope[audio]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html ``` ### 使用源码安装 适合本地开发调试使用,修改源码后可以直接执行 @@ -38,9 +45,16 @@ cd modelscope ``` 安装依赖并设置PYTHONPATH ```shell -pip install -r requirements.txt +pip install -e ".[all]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html export PYTHONPATH=`pwd` ``` +注: 6.30版本需要把cv、nlp、multi-modal领域依赖都装上,7.30号各个领域依赖会作为选装,用户需要使用哪个领域安装对应领域依赖即可。 + +如需使用语音功能,请执行如下命令安装语音功能所需依赖 +```shell +pip install -e ".[audio]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo +``` + ### 安装验证 安装成功后,可以执行如下命令进行验证安装是否正确 ```shell diff --git a/modelscope/models/__init__.py b/modelscope/models/__init__.py index d11151b5..2e12d6ad 100644 --- a/modelscope/models/__init__.py +++ b/modelscope/models/__init__.py @@ -1,29 +1,34 @@ # Copyright (c) Alibaba, Inc. and its affiliates. +from modelscope.utils.error import (AUDIO_IMPORT_ERROR, + TENSORFLOW_IMPORT_WARNING) from .base import Model from .builder import MODELS, build_model try: from .audio.tts.am import SambertNetHifi16k from .audio.tts.vocoder import Hifigan16k + from .audio.kws import GenericKeyWordSpotting + from .audio.ans.frcrn import FRCRNModel +except ModuleNotFoundError as e: + print(AUDIO_IMPORT_ERROR.format(e)) +try: + from .nlp.csanmt_for_translation import CsanmtForTranslation except ModuleNotFoundError as e: if str(e) == "No module named 'tensorflow'": - pass + print(TENSORFLOW_IMPORT_WARNING.format('CsanmtForTranslation')) else: raise ModuleNotFoundError(e) try: - from .audio.kws import GenericKeyWordSpotting from .multi_modal import OfaForImageCaptioning from .nlp import (BertForMaskedLM, BertForSequenceClassification, - CsanmtForTranslation, SbertForNLI, - SbertForSentenceSimilarity, + SbertForNLI, SbertForSentenceSimilarity, SbertForSentimentClassification, SbertForTokenClassification, SbertForZeroShotClassification, SpaceForDialogIntent, SpaceForDialogModeling, SpaceForDialogStateTracking, StructBertForMaskedLM, VecoForMaskedLM) - from .audio.ans.frcrn import FRCRNModel except ModuleNotFoundError as e: if str(e) == "No module named 'pytorch'": pass diff --git a/modelscope/models/nlp/__init__.py b/modelscope/models/nlp/__init__.py index fb1ff063..fb97fbb5 100644 --- a/modelscope/models/nlp/__init__.py +++ b/modelscope/models/nlp/__init__.py @@ -1,5 +1,6 @@ +# Copyright (c) Alibaba, Inc. and its affiliates. +from modelscope.utils.error import TENSORFLOW_IMPORT_WARNING from .bert_for_sequence_classification import * # noqa F403 -from .csanmt_for_translation import * # noqa F403 from .masked_language_model import * # noqa F403 from .palm_for_text_generation import * # noqa F403 from .sbert_for_nli import * # noqa F403 @@ -10,3 +11,11 @@ from .sbert_for_zero_shot_classification import * # noqa F403 from .space.dialog_intent_prediction_model import * # noqa F403 from .space.dialog_modeling_model import * # noqa F403 from .space.dialog_state_tracking_model import * # noqa F403 + +try: + from .csanmt_for_translation import CsanmtForTranslation +except ModuleNotFoundError as e: + if str(e) == "No module named 'tensorflow'": + print(TENSORFLOW_IMPORT_WARNING.format('CsanmtForTranslation')) + else: + raise ModuleNotFoundError(e) diff --git a/modelscope/pipelines/__init__.py b/modelscope/pipelines/__init__.py index 74f5507f..5452df28 100644 --- a/modelscope/pipelines/__init__.py +++ b/modelscope/pipelines/__init__.py @@ -1,7 +1,12 @@ -from .audio import LinearAECPipeline -from .audio.ans_pipeline import ANSPipeline +from modelscope.utils.error import AUDIO_IMPORT_ERROR from .base import Pipeline from .builder import pipeline from .cv import * # noqa F403 from .multi_modal import * # noqa F403 from .nlp import * # noqa F403 + +try: + from .audio import LinearAECPipeline + from .audio.ans_pipeline import ANSPipeline +except ModuleNotFoundError as e: + print(AUDIO_IMPORT_ERROR.format(e)) diff --git a/modelscope/pipelines/audio/__init__.py b/modelscope/pipelines/audio/__init__.py index c4dc0100..80c03c23 100644 --- a/modelscope/pipelines/audio/__init__.py +++ b/modelscope/pipelines/audio/__init__.py @@ -1,3 +1,7 @@ +# Copyright (c) Alibaba, Inc. and its affiliates. + +from modelscope.utils.error import TENSORFLOW_IMPORT_ERROR + try: from .kws_kwsbp_pipeline import * # noqa F403 from .linear_aec_pipeline import LinearAECPipeline @@ -11,6 +15,6 @@ try: from .text_to_speech_pipeline import * # noqa F403 except ModuleNotFoundError as e: if str(e) == "No module named 'tensorflow'": - pass + print(TENSORFLOW_IMPORT_ERROR.format('tts')) else: raise ModuleNotFoundError(e) diff --git a/modelscope/pipelines/cv/__init__.py b/modelscope/pipelines/cv/__init__.py index ce769c44..18dd1e3a 100644 --- a/modelscope/pipelines/cv/__init__.py +++ b/modelscope/pipelines/cv/__init__.py @@ -1,3 +1,7 @@ +# Copyright (c) Alibaba, Inc. and its affiliates. + +from modelscope.utils.error import TENSORFLOW_IMPORT_ERROR + try: from .action_recognition_pipeline import ActionRecognitionPipeline from .animal_recog_pipeline import AnimalRecogPipeline @@ -14,6 +18,8 @@ try: from .ocr_detection_pipeline import OCRDetectionPipeline except ModuleNotFoundError as e: if str(e) == "No module named 'tensorflow'": - pass + print( + TENSORFLOW_IMPORT_ERROR.format( + 'image-cartoon image-matting ocr-detection')) else: raise ModuleNotFoundError(e) diff --git a/modelscope/pipelines/nlp/__init__.py b/modelscope/pipelines/nlp/__init__.py index c0671de7..c109d49d 100644 --- a/modelscope/pipelines/nlp/__init__.py +++ b/modelscope/pipelines/nlp/__init__.py @@ -1,3 +1,15 @@ +# Copyright (c) Alibaba, Inc. and its affiliates. + +from modelscope.utils.error import TENSORFLOW_IMPORT_WARNING + +try: + from .translation_pipeline import * # noqa F403 +except ModuleNotFoundError as e: + if str(e) == "No module named 'tensorflow'": + print(TENSORFLOW_IMPORT_WARNING.format('translation')) + else: + raise ModuleNotFoundError(e) + try: from .dialog_intent_prediction_pipeline import * # noqa F403 from .dialog_modeling_pipeline import * # noqa F403 @@ -8,7 +20,6 @@ try: from .sentiment_classification_pipeline import * # noqa F403 from .sequence_classification_pipeline import * # noqa F403 from .text_generation_pipeline import * # noqa F403 - from .translation_pipeline import * # noqa F403 from .word_segmentation_pipeline import * # noqa F403 from .zero_shot_classification_pipeline import * # noqa F403 except ModuleNotFoundError as e: diff --git a/modelscope/preprocessors/__init__.py b/modelscope/preprocessors/__init__.py index 962e9f6e..29839c2b 100644 --- a/modelscope/preprocessors/__init__.py +++ b/modelscope/preprocessors/__init__.py @@ -1,5 +1,6 @@ # Copyright (c) Alibaba, Inc. and its affiliates. +from modelscope.utils.error import AUDIO_IMPORT_ERROR, TENSORFLOW_IMPORT_ERROR from .base import Preprocessor from .builder import PREPROCESSORS, build_preprocessor from .common import Compose @@ -9,6 +10,10 @@ from .text_to_speech import * # noqa F403 try: from .audio import LinearAECAndFbank +except ModuleNotFoundError as e: + print(AUDIO_IMPORT_ERROR.format(e)) + +try: from .multi_modal import * # noqa F403 from .nlp import * # noqa F403 from .space.dialog_intent_prediction_preprocessor import * # noqa F403 @@ -16,6 +21,6 @@ try: from .space.dialog_state_tracking_preprocessor import * # noqa F403 except ModuleNotFoundError as e: if str(e) == "No module named 'tensorflow'": - pass + print(TENSORFLOW_IMPORT_ERROR.format('tts')) else: raise ModuleNotFoundError(e) diff --git a/modelscope/utils/error.py b/modelscope/utils/error.py new file mode 100644 index 00000000..ba200379 --- /dev/null +++ b/modelscope/utils/error.py @@ -0,0 +1,77 @@ +# Copyright (c) Alibaba, Inc. and its affiliates. + +# docstyle-ignore +AUDIO_IMPORT_ERROR = """ +Audio model import failed: {0}, if you want to use audio releated function, please execute +`pip install modelscope[audio] -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html` +""" + +# docstyle-ignore +PROTOBUF_IMPORT_ERROR = """ +{0} requires the protobuf library but it was not found in your environment. Checkout the instructions on the +installation page of its repo: https://github.com/protocolbuffers/protobuf/tree/master/python#installation and +follow the ones that match your environment. +""" + +# docstyle-ignore +SENTENCEPIECE_IMPORT_ERROR = """ +{0} requires the SentencePiece library but it was not found in your environment. Checkout the instructions on the +installation page of its repo: https://github.com/google/sentencepiece#installation and follow the ones +that match your environment. +""" + +# docstyle-ignore +SKLEARN_IMPORT_ERROR = """ +{0} requires the scikit-learn library but it was not found in your environment. You can install it with: +``` +pip install -U scikit-learn +``` +In a notebook or a colab, you can install it by executing a cell with +``` +!pip install -U scikit-learn +``` +""" + +# docstyle-ignore +TENSORFLOW_IMPORT_ERROR = """ +{0} requires the TensorFlow library but it was not found in your environment. Checkout the instructions on the +installation page: https://www.tensorflow.org/install and follow the ones that match your environment. +""" + +# docstyle-ignore +TENSORFLOW_IMPORT_WARNING = """ +{0} requires the TensorFlow library but it was not found in your environment. +If you don't want to use them, please ignore this message +If you want to use them, please Checkout the instructions on the +installation page: https://www.tensorflow.org/install and follow the ones that match your environment. +""" + +# docstyle-ignore +TIMM_IMPORT_ERROR = """ +{0} requires the timm library but it was not found in your environment. You can install it with pip: +`pip install timm` +""" + +# docstyle-ignore +TOKENIZERS_IMPORT_ERROR = """ +{0} requires the 🤗 Tokenizers library but it was not found in your environment. You can install it with: +``` +pip install tokenizers +``` +In a notebook or a colab, you can install it by executing a cell with +``` +!pip install tokenizers +``` +""" + +# docstyle-ignore +PYTORCH_IMPORT_ERROR = """ +{0} requires the PyTorch library but it was not found in your environment. Checkout the instructions on the +installation page: https://pytorch.org/get-started/locally/ and follow the ones that match your environment. +""" + +# docstyle-ignore +SCIPY_IMPORT_ERROR = """ +{0} requires the scipy library but it was not found in your environment. You can install it with pip: +`pip install scipy` +""" diff --git a/modelscope/utils/import_utils.py b/modelscope/utils/import_utils.py index e4192082..43c6869a 100644 --- a/modelscope/utils/import_utils.py +++ b/modelscope/utils/import_utils.py @@ -18,6 +18,12 @@ import json from packaging import version from modelscope.utils.constant import Fields +from modelscope.utils.error import (PROTOBUF_IMPORT_ERROR, + PYTORCH_IMPORT_ERROR, SCIPY_IMPORT_ERROR, + SENTENCEPIECE_IMPORT_ERROR, + SKLEARN_IMPORT_ERROR, + TENSORFLOW_IMPORT_ERROR, TIMM_IMPORT_ERROR, + TOKENIZERS_IMPORT_ERROR) from modelscope.utils.logger import get_logger if sys.version_info < (3, 8): @@ -111,19 +117,27 @@ ENV_VARS_TRUE_VALUES = {'1', 'ON', 'YES', 'TRUE'} ENV_VARS_TRUE_AND_AUTO_VALUES = ENV_VARS_TRUE_VALUES.union({'AUTO'}) USE_TF = os.environ.get('USE_TF', 'AUTO').upper() USE_TORCH = os.environ.get('USE_TORCH', 'AUTO').upper() + _torch_version = 'N/A' if USE_TORCH in ENV_VARS_TRUE_AND_AUTO_VALUES and USE_TF not in ENV_VARS_TRUE_VALUES: _torch_available = importlib.util.find_spec('torch') is not None if _torch_available: try: _torch_version = importlib_metadata.version('torch') - logger.info(f'PyTorch version {_torch_version} available.') + logger.info(f'PyTorch version {_torch_version} Found.') except importlib_metadata.PackageNotFoundError: _torch_available = False else: logger.info('Disabling PyTorch because USE_TF is set') _torch_available = False +_timm_available = importlib.util.find_spec('timm') is not None +try: + _timm_version = importlib_metadata.version('timm') + logger.debug(f'Successfully imported timm version {_timm_version}') +except importlib_metadata.PackageNotFoundError: + _timm_available = False + _tf_version = 'N/A' if USE_TF in ENV_VARS_TRUE_AND_AUTO_VALUES and USE_TORCH not in ENV_VARS_TRUE_VALUES: _tf_available = importlib.util.find_spec('tensorflow') is not None @@ -153,18 +167,11 @@ if USE_TF in ENV_VARS_TRUE_AND_AUTO_VALUES and USE_TORCH not in ENV_VARS_TRUE_VA if version.parse(_tf_version) < version.parse('2'): pass else: - logger.info(f'TensorFlow version {_tf_version} available.') + logger.info(f'TensorFlow version {_tf_version} Found.') else: logger.info('Disabling Tensorflow because USE_TORCH is set') _tf_available = False -_timm_available = importlib.util.find_spec('timm') is not None -try: - _timm_version = importlib_metadata.version('timm') - logger.debug(f'Successfully imported timm version {_timm_version}') -except importlib_metadata.PackageNotFoundError: - _timm_available = False - def is_scipy_available(): return importlib.util.find_spec('scipy') is not None @@ -211,68 +218,6 @@ def is_tf_available(): return _tf_available -# docstyle-ignore -PROTOBUF_IMPORT_ERROR = """ -{0} requires the protobuf library but it was not found in your environment. Checkout the instructions on the -installation page of its repo: https://github.com/protocolbuffers/protobuf/tree/master/python#installation and -follow the ones that match your environment. -""" - -# docstyle-ignore -SENTENCEPIECE_IMPORT_ERROR = """ -{0} requires the SentencePiece library but it was not found in your environment. Checkout the instructions on the -installation page of its repo: https://github.com/google/sentencepiece#installation and follow the ones -that match your environment. -""" - -# docstyle-ignore -SKLEARN_IMPORT_ERROR = """ -{0} requires the scikit-learn library but it was not found in your environment. You can install it with: -``` -pip install -U scikit-learn -``` -In a notebook or a colab, you can install it by executing a cell with -``` -!pip install -U scikit-learn -``` -""" - -# docstyle-ignore -TENSORFLOW_IMPORT_ERROR = """ -{0} requires the TensorFlow library but it was not found in your environment. Checkout the instructions on the -installation page: https://www.tensorflow.org/install and follow the ones that match your environment. -""" - -# docstyle-ignore -TIMM_IMPORT_ERROR = """ -{0} requires the timm library but it was not found in your environment. You can install it with pip: -`pip install timm` -""" - -# docstyle-ignore -TOKENIZERS_IMPORT_ERROR = """ -{0} requires the 🤗 Tokenizers library but it was not found in your environment. You can install it with: -``` -pip install tokenizers -``` -In a notebook or a colab, you can install it by executing a cell with -``` -!pip install tokenizers -``` -""" - -# docstyle-ignore -PYTORCH_IMPORT_ERROR = """ -{0} requires the PyTorch library but it was not found in your environment. Checkout the instructions on the -installation page: https://pytorch.org/get-started/locally/ and follow the ones that match your environment. -""" - -# docstyle-ignore -SCIPY_IMPORT_ERROR = """ -{0} requires the scipy library but it was not found in your environment. You can install it with pip: -`pip install scipy` -""" - REQUIREMENTS_MAAPING = OrderedDict([ ('protobuf', (is_protobuf_available, PROTOBUF_IMPORT_ERROR)), ('sentencepiece', (is_sentencepiece_available, diff --git a/modelscope/version.py b/modelscope/version.py index fc79d63d..020ed73d 100644 --- a/modelscope/version.py +++ b/modelscope/version.py @@ -1 +1 @@ -__version__ = '0.2.1' +__version__ = '0.2.2' diff --git a/requirements/audio.txt b/requirements/audio.txt index 4c009d27..1e1e577b 100644 --- a/requirements/audio.txt +++ b/requirements/audio.txt @@ -6,7 +6,7 @@ librosa lxml matplotlib nara_wpe -numpy +numpy<=1.18 protobuf>3,<=3.20 ptflops pytorch_wavelets==1.3.0 diff --git a/requirements/multi-modal.txt b/requirements/multi-modal.txt index b96bdd01..9fced4c2 100644 --- a/requirements/multi-modal.txt +++ b/requirements/multi-modal.txt @@ -5,3 +5,4 @@ pycocoevalcap>=1.2 pycocotools>=2.0.4 rouge_score timm +torchvision diff --git a/setup.py b/setup.py index 3b40ac8b..2edfd685 100644 --- a/setup.py +++ b/setup.py @@ -176,6 +176,10 @@ if __name__ == '__main__': for field in dir(Fields): if field.startswith('_'): continue + # skip audio requirements due to its hard dependency which + # result in mac/windows compatibility problems + if field == Fields.audio: + continue extra_requires[field], _ = parse_requirements( f'requirements/{field}.txt') all_requires.append(extra_requires[field])