You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

multi_modal.py 15 kB

[to #42322933]update ofa caption model 将caption pipeline的实现从pipeline下沉到model,并拆解preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/9081211 * [to #41669377] docs and tools refinement and release 1. add build_doc linter script 2. add sphinx-docs support 3. add development doc and api doc 4. change version to 0.1.0 for the first internal release version Link: https://code.aone.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8775307 * [to #41669377] add pipeline tutorial and fix bugs 1. add pipleine tutorial 2. fix bugs when using pipeline with certain model and preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8814301 * refine doc * refine doc * upload ofa for caption(with source code but not whl) * remove data in gitignore * append uncommitted data dir in ofa * remove ofa_dir , use ofa.whl instead. * update BPE * rollback changes used in debugging. * Merge branch 'master' into ofa/image_caption # Conflicts: # docs/README.md # docs/source/conf.py # docs/source/index.rst # docs/source/tutorials/pipeline.md # maas_lib/models/nlp/sequence_classification_model.py # maas_lib/pipelines/builder.py # maas_lib/version.py # setup.py # tests/pipelines/test_text_classification.py * 1. fix a bug in pipelines/builder.py. 2. modify model_path to model in image_captioning.py. * 1. rename test_image_captioning.py. * format all files using pre-commit. * add fairseq in requirements.txt * add fairseq in requirements.txt * change fairseq path to git repo to a whl on oss in ofa.txt. * change module_name to 'ofa' * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/builder.py * optim requirements for ofa / refine image_captioning.py * uncommited change. * feat: Fix confilct, auto commit by WebIDE * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/multi_modal/__init__.py # modelscope/pipelines/multi_modal/image_captioning.py # tests/pipelines/test_image_captioning.py * merge master * merge master * merge master * rename * Merge remote-tracking branch 'origin/master' into ofa/nlu * add caption model * Merge remote-tracking branch 'origin/master' into ofa/nlu * update ofa caption model * fix some typo, update unittest * use local test image * use local test image * refactor, ofa -> multi_model * merge master * 删除 image_caption_pipeline.py
3 years ago
[to #42322933] add image_caption_pipeline with OFA 1. add OFA whl for image caption pipeline 2. fix a bug in pipelines/builder.py Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8930942 * [to #41669377] docs and tools refinement and release 1. add build_doc linter script 2. add sphinx-docs support 3. add development doc and api doc 4. change version to 0.1.0 for the first internal release version Link: https://code.aone.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8775307 * [to #41669377] add pipeline tutorial and fix bugs 1. add pipleine tutorial 2. fix bugs when using pipeline with certain model and preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8814301 * refine doc * refine doc * upload ofa for caption(with source code but not whl) * remove data in gitignore * append uncommitted data dir in ofa * remove ofa_dir , use ofa.whl instead. * update BPE * rollback changes used in debugging. * Merge branch 'master' into ofa/image_caption # Conflicts: # docs/README.md # docs/source/conf.py # docs/source/index.rst # docs/source/tutorials/pipeline.md # maas_lib/models/nlp/sequence_classification_model.py # maas_lib/pipelines/builder.py # maas_lib/version.py # setup.py # tests/pipelines/test_text_classification.py * 1. fix a bug in pipelines/builder.py. 2. modify model_path to model in image_captioning.py. * 1. rename test_image_captioning.py. * format all files using pre-commit. * add fairseq in requirements.txt * add fairseq in requirements.txt * change fairseq path to git repo to a whl on oss in ofa.txt. * change module_name to 'ofa' * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/builder.py * optim requirements for ofa / refine image_captioning.py * uncommited change. * feat: Fix confilct, auto commit by WebIDE
3 years ago
[to #42322933] add image_caption_pipeline with OFA 1. add OFA whl for image caption pipeline 2. fix a bug in pipelines/builder.py Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8930942 * [to #41669377] docs and tools refinement and release 1. add build_doc linter script 2. add sphinx-docs support 3. add development doc and api doc 4. change version to 0.1.0 for the first internal release version Link: https://code.aone.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8775307 * [to #41669377] add pipeline tutorial and fix bugs 1. add pipleine tutorial 2. fix bugs when using pipeline with certain model and preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8814301 * refine doc * refine doc * upload ofa for caption(with source code but not whl) * remove data in gitignore * append uncommitted data dir in ofa * remove ofa_dir , use ofa.whl instead. * update BPE * rollback changes used in debugging. * Merge branch 'master' into ofa/image_caption # Conflicts: # docs/README.md # docs/source/conf.py # docs/source/index.rst # docs/source/tutorials/pipeline.md # maas_lib/models/nlp/sequence_classification_model.py # maas_lib/pipelines/builder.py # maas_lib/version.py # setup.py # tests/pipelines/test_text_classification.py * 1. fix a bug in pipelines/builder.py. 2. modify model_path to model in image_captioning.py. * 1. rename test_image_captioning.py. * format all files using pre-commit. * add fairseq in requirements.txt * add fairseq in requirements.txt * change fairseq path to git repo to a whl on oss in ofa.txt. * change module_name to 'ofa' * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/builder.py * optim requirements for ofa / refine image_captioning.py * uncommited change. * feat: Fix confilct, auto commit by WebIDE
3 years ago
[to #42322933] add image_caption_pipeline with OFA 1. add OFA whl for image caption pipeline 2. fix a bug in pipelines/builder.py Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8930942 * [to #41669377] docs and tools refinement and release 1. add build_doc linter script 2. add sphinx-docs support 3. add development doc and api doc 4. change version to 0.1.0 for the first internal release version Link: https://code.aone.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8775307 * [to #41669377] add pipeline tutorial and fix bugs 1. add pipleine tutorial 2. fix bugs when using pipeline with certain model and preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8814301 * refine doc * refine doc * upload ofa for caption(with source code but not whl) * remove data in gitignore * append uncommitted data dir in ofa * remove ofa_dir , use ofa.whl instead. * update BPE * rollback changes used in debugging. * Merge branch 'master' into ofa/image_caption # Conflicts: # docs/README.md # docs/source/conf.py # docs/source/index.rst # docs/source/tutorials/pipeline.md # maas_lib/models/nlp/sequence_classification_model.py # maas_lib/pipelines/builder.py # maas_lib/version.py # setup.py # tests/pipelines/test_text_classification.py * 1. fix a bug in pipelines/builder.py. 2. modify model_path to model in image_captioning.py. * 1. rename test_image_captioning.py. * format all files using pre-commit. * add fairseq in requirements.txt * add fairseq in requirements.txt * change fairseq path to git repo to a whl on oss in ofa.txt. * change module_name to 'ofa' * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/builder.py * optim requirements for ofa / refine image_captioning.py * uncommited change. * feat: Fix confilct, auto commit by WebIDE
3 years ago
3 years ago
[to #42322933]update ofa caption model 将caption pipeline的实现从pipeline下沉到model,并拆解preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/9081211 * [to #41669377] docs and tools refinement and release 1. add build_doc linter script 2. add sphinx-docs support 3. add development doc and api doc 4. change version to 0.1.0 for the first internal release version Link: https://code.aone.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8775307 * [to #41669377] add pipeline tutorial and fix bugs 1. add pipleine tutorial 2. fix bugs when using pipeline with certain model and preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8814301 * refine doc * refine doc * upload ofa for caption(with source code but not whl) * remove data in gitignore * append uncommitted data dir in ofa * remove ofa_dir , use ofa.whl instead. * update BPE * rollback changes used in debugging. * Merge branch 'master' into ofa/image_caption # Conflicts: # docs/README.md # docs/source/conf.py # docs/source/index.rst # docs/source/tutorials/pipeline.md # maas_lib/models/nlp/sequence_classification_model.py # maas_lib/pipelines/builder.py # maas_lib/version.py # setup.py # tests/pipelines/test_text_classification.py * 1. fix a bug in pipelines/builder.py. 2. modify model_path to model in image_captioning.py. * 1. rename test_image_captioning.py. * format all files using pre-commit. * add fairseq in requirements.txt * add fairseq in requirements.txt * change fairseq path to git repo to a whl on oss in ofa.txt. * change module_name to 'ofa' * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/builder.py * optim requirements for ofa / refine image_captioning.py * uncommited change. * feat: Fix confilct, auto commit by WebIDE * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/multi_modal/__init__.py # modelscope/pipelines/multi_modal/image_captioning.py # tests/pipelines/test_image_captioning.py * merge master * merge master * merge master * rename * Merge remote-tracking branch 'origin/master' into ofa/nlu * add caption model * Merge remote-tracking branch 'origin/master' into ofa/nlu * update ofa caption model * fix some typo, update unittest * use local test image * use local test image * refactor, ofa -> multi_model * merge master * 删除 image_caption_pipeline.py
3 years ago
3 years ago
[to #42322933] add image_caption_pipeline with OFA 1. add OFA whl for image caption pipeline 2. fix a bug in pipelines/builder.py Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8930942 * [to #41669377] docs and tools refinement and release 1. add build_doc linter script 2. add sphinx-docs support 3. add development doc and api doc 4. change version to 0.1.0 for the first internal release version Link: https://code.aone.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8775307 * [to #41669377] add pipeline tutorial and fix bugs 1. add pipleine tutorial 2. fix bugs when using pipeline with certain model and preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8814301 * refine doc * refine doc * upload ofa for caption(with source code but not whl) * remove data in gitignore * append uncommitted data dir in ofa * remove ofa_dir , use ofa.whl instead. * update BPE * rollback changes used in debugging. * Merge branch 'master' into ofa/image_caption # Conflicts: # docs/README.md # docs/source/conf.py # docs/source/index.rst # docs/source/tutorials/pipeline.md # maas_lib/models/nlp/sequence_classification_model.py # maas_lib/pipelines/builder.py # maas_lib/version.py # setup.py # tests/pipelines/test_text_classification.py * 1. fix a bug in pipelines/builder.py. 2. modify model_path to model in image_captioning.py. * 1. rename test_image_captioning.py. * format all files using pre-commit. * add fairseq in requirements.txt * add fairseq in requirements.txt * change fairseq path to git repo to a whl on oss in ofa.txt. * change module_name to 'ofa' * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/builder.py * optim requirements for ofa / refine image_captioning.py * uncommited change. * feat: Fix confilct, auto commit by WebIDE
3 years ago
[to #42322933]update ofa caption model 将caption pipeline的实现从pipeline下沉到model,并拆解preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/9081211 * [to #41669377] docs and tools refinement and release 1. add build_doc linter script 2. add sphinx-docs support 3. add development doc and api doc 4. change version to 0.1.0 for the first internal release version Link: https://code.aone.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8775307 * [to #41669377] add pipeline tutorial and fix bugs 1. add pipleine tutorial 2. fix bugs when using pipeline with certain model and preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8814301 * refine doc * refine doc * upload ofa for caption(with source code but not whl) * remove data in gitignore * append uncommitted data dir in ofa * remove ofa_dir , use ofa.whl instead. * update BPE * rollback changes used in debugging. * Merge branch 'master' into ofa/image_caption # Conflicts: # docs/README.md # docs/source/conf.py # docs/source/index.rst # docs/source/tutorials/pipeline.md # maas_lib/models/nlp/sequence_classification_model.py # maas_lib/pipelines/builder.py # maas_lib/version.py # setup.py # tests/pipelines/test_text_classification.py * 1. fix a bug in pipelines/builder.py. 2. modify model_path to model in image_captioning.py. * 1. rename test_image_captioning.py. * format all files using pre-commit. * add fairseq in requirements.txt * add fairseq in requirements.txt * change fairseq path to git repo to a whl on oss in ofa.txt. * change module_name to 'ofa' * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/builder.py * optim requirements for ofa / refine image_captioning.py * uncommited change. * feat: Fix confilct, auto commit by WebIDE * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/multi_modal/__init__.py # modelscope/pipelines/multi_modal/image_captioning.py # tests/pipelines/test_image_captioning.py * merge master * merge master * merge master * rename * Merge remote-tracking branch 'origin/master' into ofa/nlu * add caption model * Merge remote-tracking branch 'origin/master' into ofa/nlu * update ofa caption model * fix some typo, update unittest * use local test image * use local test image * refactor, ofa -> multi_model * merge master * 删除 image_caption_pipeline.py
3 years ago
3 years ago
[to #42322933]update ofa caption model 将caption pipeline的实现从pipeline下沉到model,并拆解preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/9081211 * [to #41669377] docs and tools refinement and release 1. add build_doc linter script 2. add sphinx-docs support 3. add development doc and api doc 4. change version to 0.1.0 for the first internal release version Link: https://code.aone.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8775307 * [to #41669377] add pipeline tutorial and fix bugs 1. add pipleine tutorial 2. fix bugs when using pipeline with certain model and preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8814301 * refine doc * refine doc * upload ofa for caption(with source code but not whl) * remove data in gitignore * append uncommitted data dir in ofa * remove ofa_dir , use ofa.whl instead. * update BPE * rollback changes used in debugging. * Merge branch 'master' into ofa/image_caption # Conflicts: # docs/README.md # docs/source/conf.py # docs/source/index.rst # docs/source/tutorials/pipeline.md # maas_lib/models/nlp/sequence_classification_model.py # maas_lib/pipelines/builder.py # maas_lib/version.py # setup.py # tests/pipelines/test_text_classification.py * 1. fix a bug in pipelines/builder.py. 2. modify model_path to model in image_captioning.py. * 1. rename test_image_captioning.py. * format all files using pre-commit. * add fairseq in requirements.txt * add fairseq in requirements.txt * change fairseq path to git repo to a whl on oss in ofa.txt. * change module_name to 'ofa' * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/builder.py * optim requirements for ofa / refine image_captioning.py * uncommited change. * feat: Fix confilct, auto commit by WebIDE * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/multi_modal/__init__.py # modelscope/pipelines/multi_modal/image_captioning.py # tests/pipelines/test_image_captioning.py * merge master * merge master * merge master * rename * Merge remote-tracking branch 'origin/master' into ofa/nlu * add caption model * Merge remote-tracking branch 'origin/master' into ofa/nlu * update ofa caption model * fix some typo, update unittest * use local test image * use local test image * refactor, ofa -> multi_model * merge master * 删除 image_caption_pipeline.py
3 years ago
[to #42322933] add image_caption_pipeline with OFA 1. add OFA whl for image caption pipeline 2. fix a bug in pipelines/builder.py Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8930942 * [to #41669377] docs and tools refinement and release 1. add build_doc linter script 2. add sphinx-docs support 3. add development doc and api doc 4. change version to 0.1.0 for the first internal release version Link: https://code.aone.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8775307 * [to #41669377] add pipeline tutorial and fix bugs 1. add pipleine tutorial 2. fix bugs when using pipeline with certain model and preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8814301 * refine doc * refine doc * upload ofa for caption(with source code but not whl) * remove data in gitignore * append uncommitted data dir in ofa * remove ofa_dir , use ofa.whl instead. * update BPE * rollback changes used in debugging. * Merge branch 'master' into ofa/image_caption # Conflicts: # docs/README.md # docs/source/conf.py # docs/source/index.rst # docs/source/tutorials/pipeline.md # maas_lib/models/nlp/sequence_classification_model.py # maas_lib/pipelines/builder.py # maas_lib/version.py # setup.py # tests/pipelines/test_text_classification.py * 1. fix a bug in pipelines/builder.py. 2. modify model_path to model in image_captioning.py. * 1. rename test_image_captioning.py. * format all files using pre-commit. * add fairseq in requirements.txt * add fairseq in requirements.txt * change fairseq path to git repo to a whl on oss in ofa.txt. * change module_name to 'ofa' * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/builder.py * optim requirements for ofa / refine image_captioning.py * uncommited change. * feat: Fix confilct, auto commit by WebIDE
3 years ago
[to #42322933]update ofa caption model 将caption pipeline的实现从pipeline下沉到model,并拆解preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/9081211 * [to #41669377] docs and tools refinement and release 1. add build_doc linter script 2. add sphinx-docs support 3. add development doc and api doc 4. change version to 0.1.0 for the first internal release version Link: https://code.aone.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8775307 * [to #41669377] add pipeline tutorial and fix bugs 1. add pipleine tutorial 2. fix bugs when using pipeline with certain model and preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8814301 * refine doc * refine doc * upload ofa for caption(with source code but not whl) * remove data in gitignore * append uncommitted data dir in ofa * remove ofa_dir , use ofa.whl instead. * update BPE * rollback changes used in debugging. * Merge branch 'master' into ofa/image_caption # Conflicts: # docs/README.md # docs/source/conf.py # docs/source/index.rst # docs/source/tutorials/pipeline.md # maas_lib/models/nlp/sequence_classification_model.py # maas_lib/pipelines/builder.py # maas_lib/version.py # setup.py # tests/pipelines/test_text_classification.py * 1. fix a bug in pipelines/builder.py. 2. modify model_path to model in image_captioning.py. * 1. rename test_image_captioning.py. * format all files using pre-commit. * add fairseq in requirements.txt * add fairseq in requirements.txt * change fairseq path to git repo to a whl on oss in ofa.txt. * change module_name to 'ofa' * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/builder.py * optim requirements for ofa / refine image_captioning.py * uncommited change. * feat: Fix confilct, auto commit by WebIDE * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/multi_modal/__init__.py # modelscope/pipelines/multi_modal/image_captioning.py # tests/pipelines/test_image_captioning.py * merge master * merge master * merge master * rename * Merge remote-tracking branch 'origin/master' into ofa/nlu * add caption model * Merge remote-tracking branch 'origin/master' into ofa/nlu * update ofa caption model * fix some typo, update unittest * use local test image * use local test image * refactor, ofa -> multi_model * merge master * 删除 image_caption_pipeline.py
3 years ago
3 years ago
[to #42322933]update ofa caption model 将caption pipeline的实现从pipeline下沉到model,并拆解preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/9081211 * [to #41669377] docs and tools refinement and release 1. add build_doc linter script 2. add sphinx-docs support 3. add development doc and api doc 4. change version to 0.1.0 for the first internal release version Link: https://code.aone.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8775307 * [to #41669377] add pipeline tutorial and fix bugs 1. add pipleine tutorial 2. fix bugs when using pipeline with certain model and preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8814301 * refine doc * refine doc * upload ofa for caption(with source code but not whl) * remove data in gitignore * append uncommitted data dir in ofa * remove ofa_dir , use ofa.whl instead. * update BPE * rollback changes used in debugging. * Merge branch 'master' into ofa/image_caption # Conflicts: # docs/README.md # docs/source/conf.py # docs/source/index.rst # docs/source/tutorials/pipeline.md # maas_lib/models/nlp/sequence_classification_model.py # maas_lib/pipelines/builder.py # maas_lib/version.py # setup.py # tests/pipelines/test_text_classification.py * 1. fix a bug in pipelines/builder.py. 2. modify model_path to model in image_captioning.py. * 1. rename test_image_captioning.py. * format all files using pre-commit. * add fairseq in requirements.txt * add fairseq in requirements.txt * change fairseq path to git repo to a whl on oss in ofa.txt. * change module_name to 'ofa' * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/builder.py * optim requirements for ofa / refine image_captioning.py * uncommited change. * feat: Fix confilct, auto commit by WebIDE * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/multi_modal/__init__.py # modelscope/pipelines/multi_modal/image_captioning.py # tests/pipelines/test_image_captioning.py * merge master * merge master * merge master * rename * Merge remote-tracking branch 'origin/master' into ofa/nlu * add caption model * Merge remote-tracking branch 'origin/master' into ofa/nlu * update ofa caption model * fix some typo, update unittest * use local test image * use local test image * refactor, ofa -> multi_model * merge master * 删除 image_caption_pipeline.py
3 years ago
[to #42322933]update ofa caption model 将caption pipeline的实现从pipeline下沉到model,并拆解preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/9081211 * [to #41669377] docs and tools refinement and release 1. add build_doc linter script 2. add sphinx-docs support 3. add development doc and api doc 4. change version to 0.1.0 for the first internal release version Link: https://code.aone.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8775307 * [to #41669377] add pipeline tutorial and fix bugs 1. add pipleine tutorial 2. fix bugs when using pipeline with certain model and preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8814301 * refine doc * refine doc * upload ofa for caption(with source code but not whl) * remove data in gitignore * append uncommitted data dir in ofa * remove ofa_dir , use ofa.whl instead. * update BPE * rollback changes used in debugging. * Merge branch 'master' into ofa/image_caption # Conflicts: # docs/README.md # docs/source/conf.py # docs/source/index.rst # docs/source/tutorials/pipeline.md # maas_lib/models/nlp/sequence_classification_model.py # maas_lib/pipelines/builder.py # maas_lib/version.py # setup.py # tests/pipelines/test_text_classification.py * 1. fix a bug in pipelines/builder.py. 2. modify model_path to model in image_captioning.py. * 1. rename test_image_captioning.py. * format all files using pre-commit. * add fairseq in requirements.txt * add fairseq in requirements.txt * change fairseq path to git repo to a whl on oss in ofa.txt. * change module_name to 'ofa' * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/builder.py * optim requirements for ofa / refine image_captioning.py * uncommited change. * feat: Fix confilct, auto commit by WebIDE * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/multi_modal/__init__.py # modelscope/pipelines/multi_modal/image_captioning.py # tests/pipelines/test_image_captioning.py * merge master * merge master * merge master * rename * Merge remote-tracking branch 'origin/master' into ofa/nlu * add caption model * Merge remote-tracking branch 'origin/master' into ofa/nlu * update ofa caption model * fix some typo, update unittest * use local test image * use local test image * refactor, ofa -> multi_model * merge master * 删除 image_caption_pipeline.py
3 years ago
[to #42322933]update ofa caption model 将caption pipeline的实现从pipeline下沉到model,并拆解preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/9081211 * [to #41669377] docs and tools refinement and release 1. add build_doc linter script 2. add sphinx-docs support 3. add development doc and api doc 4. change version to 0.1.0 for the first internal release version Link: https://code.aone.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8775307 * [to #41669377] add pipeline tutorial and fix bugs 1. add pipleine tutorial 2. fix bugs when using pipeline with certain model and preprocessor Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8814301 * refine doc * refine doc * upload ofa for caption(with source code but not whl) * remove data in gitignore * append uncommitted data dir in ofa * remove ofa_dir , use ofa.whl instead. * update BPE * rollback changes used in debugging. * Merge branch 'master' into ofa/image_caption # Conflicts: # docs/README.md # docs/source/conf.py # docs/source/index.rst # docs/source/tutorials/pipeline.md # maas_lib/models/nlp/sequence_classification_model.py # maas_lib/pipelines/builder.py # maas_lib/version.py # setup.py # tests/pipelines/test_text_classification.py * 1. fix a bug in pipelines/builder.py. 2. modify model_path to model in image_captioning.py. * 1. rename test_image_captioning.py. * format all files using pre-commit. * add fairseq in requirements.txt * add fairseq in requirements.txt * change fairseq path to git repo to a whl on oss in ofa.txt. * change module_name to 'ofa' * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/builder.py * optim requirements for ofa / refine image_captioning.py * uncommited change. * feat: Fix confilct, auto commit by WebIDE * Merge remote-tracking branch 'origin/master' into ofa/image_caption # Conflicts: # maas_lib/pipelines/multi_modal/__init__.py # modelscope/pipelines/multi_modal/image_captioning.py # tests/pipelines/test_image_captioning.py * merge master * merge master * merge master * rename * Merge remote-tracking branch 'origin/master' into ofa/nlu * add caption model * Merge remote-tracking branch 'origin/master' into ofa/nlu * update ofa caption model * fix some typo, update unittest * use local test image * use local test image * refactor, ofa -> multi_model * merge master * 删除 image_caption_pipeline.py
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import os.path as osp
  3. from io import BytesIO
  4. from typing import Any, Dict, List, Tuple, Union
  5. import json
  6. import torch
  7. from PIL import Image
  8. from timm.data import create_transform
  9. from torchvision.transforms import Compose, Normalize, Resize, ToTensor
  10. from modelscope.hub.snapshot_download import snapshot_download
  11. from modelscope.metainfo import Preprocessors
  12. from modelscope.pipelines.base import Input
  13. from modelscope.preprocessors import load_image
  14. from modelscope.utils.config import Config
  15. from modelscope.utils.constant import Fields, ModeKeys, ModelFile, Tasks
  16. from .base import Preprocessor
  17. from .builder import PREPROCESSORS
  18. from .ofa import * # noqa
  19. from .ofa.utils.collate import collate_fn
  20. from .ofa.utils.constant import OFA_TASK_KEY_MAPPING
  21. __all__ = [
  22. 'OfaPreprocessor',
  23. 'MPlugPreprocessor',
  24. ]
  25. @PREPROCESSORS.register_module(
  26. Fields.multi_modal, module_name=Preprocessors.ofa_tasks_preprocessor)
  27. class OfaPreprocessor(Preprocessor):
  28. def __init__(self,
  29. model_dir: str,
  30. mode=ModeKeys.INFERENCE,
  31. *args,
  32. **kwargs):
  33. """preprocess the data
  34. Args:
  35. model_dir (str): model path
  36. mode: preprocessor mode (model mode)
  37. """
  38. super().__init__(*args, **kwargs)
  39. preprocess_mapping = {
  40. Tasks.ocr_recognition: OfaOcrRecognitionPreprocessor,
  41. Tasks.image_captioning: OfaImageCaptioningPreprocessor,
  42. Tasks.visual_grounding: OfaVisualGroundingPreprocessor,
  43. Tasks.visual_question_answering:
  44. OfaVisualQuestionAnsweringPreprocessor,
  45. Tasks.visual_entailment: OfaVisualEntailmentPreprocessor,
  46. Tasks.image_classification: OfaImageClassificationPreprocessor,
  47. Tasks.text_classification: OfaTextClassificationPreprocessor,
  48. Tasks.text_summarization: OfaSummarizationPreprocessor,
  49. Tasks.text_to_image_synthesis: OfaTextToImageSynthesisPreprocessor
  50. }
  51. model_dir = model_dir if osp.exists(model_dir) else snapshot_download(
  52. model_dir)
  53. self.cfg = Config.from_file(
  54. osp.join(model_dir, ModelFile.CONFIGURATION))
  55. self.preprocess = preprocess_mapping[self.cfg.task](
  56. cfg=self.cfg, model_dir=model_dir, mode=mode)
  57. self.keys = OFA_TASK_KEY_MAPPING[self.cfg.task]
  58. self.tokenizer = self.preprocess.tokenizer
  59. if kwargs.get('no_collate', None):
  60. self.no_collate = True
  61. else:
  62. self.no_collate = False
  63. # just for modelscope demo
  64. def _build_dict(self, input: Union[Input, List[Input]]) -> Dict[str, Any]:
  65. data = dict()
  66. if not isinstance(input, tuple) and not isinstance(input, list):
  67. input = (input, )
  68. for key, item in zip(self.keys, input):
  69. data[key] = item
  70. return data
  71. def _ofa_input_compatibility_conversion(self, data): # fake
  72. if 'image' in data and self.cfg.model.get('type', None) == 'ofa':
  73. if isinstance(data['image'], str):
  74. image = load_image(data['image'])
  75. else:
  76. image = data['image']
  77. if image.mode != 'RGB':
  78. image = image.convert('RGB')
  79. img_buffer = BytesIO()
  80. image.save(img_buffer, format='JPEG')
  81. data['image'] = Image.open(img_buffer)
  82. return data
  83. def __call__(self, input: Union[str, tuple, Dict[str, Any]], *args,
  84. **kwargs) -> Dict[str, Any]:
  85. if isinstance(input, dict):
  86. data = input
  87. else:
  88. data = self._build_dict(input)
  89. sample = self.preprocess(data)
  90. str_data = dict()
  91. for k, v in data.items():
  92. str_data[k] = str(v)
  93. sample['sample'] = str_data
  94. if self.no_collate:
  95. return sample
  96. else:
  97. return collate_fn([sample],
  98. pad_idx=self.tokenizer.pad_token_id,
  99. eos_idx=self.tokenizer.eos_token_id)
  100. def _convert_to_rgb(image):
  101. return image.convert('RGB')
  102. @PREPROCESSORS.register_module(
  103. Fields.multi_modal, module_name=Preprocessors.clip_preprocessor)
  104. class CLIPPreprocessor(Preprocessor):
  105. def __init__(self,
  106. model_dir: str,
  107. mode=ModeKeys.INFERENCE,
  108. *args,
  109. **kwargs):
  110. """preprocess the data
  111. Args:
  112. model_dir (str): model path
  113. mode: preprocessor mode (model mode)
  114. """
  115. super().__init__(*args, **kwargs)
  116. model_dir = model_dir if osp.exists(model_dir) else snapshot_download(
  117. model_dir)
  118. self.mode = mode
  119. # text tokenizer
  120. from modelscope.models.multi_modal.clip.bert_tokenizer import FullTokenizer
  121. if 'tokenizer' in kwargs and isinstance(kwargs['tokenizer'],
  122. FullTokenizer):
  123. self.tokenizer = kwargs['tokenizer']
  124. else:
  125. vocab_file = f'{model_dir}/{ModelFile.VOCAB_FILE}'
  126. self.tokenizer = FullTokenizer(vocab_file=vocab_file)
  127. # image preprocessor
  128. if 'resolution' in kwargs and isinstance(kwargs['resolution'], int):
  129. self.image_resolution = kwargs['resolution']
  130. else:
  131. self.image_resolution = json.load(
  132. open('{}/vision_model_config.json'.format(
  133. model_dir)))['image_resolution']
  134. self.img_preprocess = self._build_image_transform()
  135. # key mapping
  136. # specify the input keys, compatible with training and inference whose key names may be different
  137. self.input_keys = {'img': 'img', 'text': 'text'}
  138. def _build_image_transform(self):
  139. if self.mode == ModeKeys.TRAIN:
  140. transform = create_transform(
  141. input_size=self.image_resolution,
  142. scale=(0.9, 1.0),
  143. is_training=True,
  144. color_jitter=None,
  145. auto_augment='original',
  146. interpolation='bicubic',
  147. mean=(0.48145466, 0.4578275, 0.40821073),
  148. std=(0.26862954, 0.26130258, 0.27577711),
  149. )
  150. transform = Compose(transform.transforms[:-3] + [_convert_to_rgb]
  151. + transform.transforms[-3:])
  152. else:
  153. transform = Compose([
  154. Resize((self.image_resolution, self.image_resolution),
  155. interpolation=Image.BICUBIC),
  156. _convert_to_rgb,
  157. ToTensor(),
  158. Normalize((0.48145466, 0.4578275, 0.40821073),
  159. (0.26862954, 0.26130258, 0.27577711)),
  160. ])
  161. return transform
  162. def tokenize(self,
  163. texts: Union[str, List[str]],
  164. context_length: int = 52) -> torch.LongTensor:
  165. """
  166. Returns the tokenized representation of given input string(s)
  167. Parameters
  168. ----------
  169. texts : Union[str, List[str]]
  170. An input string or a list of input strings to tokenize
  171. context_length : int
  172. The context length to use; all baseline models use 24 as the context length
  173. Returns
  174. -------
  175. A two-dimensional tensor containing the resulting tokens, shape = [number of input strings, context_length]
  176. """
  177. if isinstance(texts, str):
  178. texts = [texts]
  179. all_tokens = []
  180. for text in texts:
  181. all_tokens.append(
  182. [self.tokenizer.vocab['[CLS]']]
  183. + self.tokenizer.convert_tokens_to_ids(
  184. self.tokenizer.tokenize(text))[:context_length - 2]
  185. + [self.tokenizer.vocab['[SEP]']])
  186. result = torch.zeros(len(all_tokens), context_length, dtype=torch.long)
  187. for i, tokens in enumerate(all_tokens):
  188. assert len(tokens) <= context_length
  189. result[i, :len(tokens)] = torch.tensor(tokens)
  190. return result
  191. def set_input_img_key(self, new_key: str):
  192. self.input_keys['img'] = new_key
  193. def set_input_text_key(self, new_key: str):
  194. self.input_keys['text'] = new_key
  195. def __call__(self, input: Union[str, tuple, Dict[str, Any]], *args,
  196. **kwargs) -> Dict[str, Any]:
  197. output = {}
  198. # preprocess the image input
  199. input_img_key = self.input_keys['img']
  200. if input_img_key in input and input[input_img_key] is not None:
  201. image_input = input[input_img_key]
  202. # single image input
  203. if isinstance(image_input, Image.Image):
  204. image_tensor = self.img_preprocess(image_input).unsqueeze(0)
  205. # multi images input
  206. elif isinstance(image_input, list):
  207. if all([isinstance(elem, Image.Image)
  208. for elem in image_input]):
  209. image_tensor = torch.stack(
  210. [self.img_preprocess(elem)
  211. for elem in image_input], # noqa
  212. dim=0) # noqa
  213. else:
  214. unsupported_elem_type = [
  215. type(elem) for elem in image_input
  216. if not isinstance(elem, Image.Image)
  217. ][0]
  218. raise TypeError(
  219. f'img should be PIL.Image or List[PIL.Image], \
  220. but got a List containing one {unsupported_elem_type}'
  221. )
  222. # others
  223. else:
  224. raise TypeError(
  225. f'img should be PIL.Image or List[PIL.Image], but got {type(image_input)}'
  226. )
  227. output['img'] = image_tensor
  228. # preprocess the text input
  229. input_text_key = self.input_keys['text']
  230. if input_text_key in input and input[input_text_key] is not None:
  231. text_input = input[input_text_key]
  232. # single text input
  233. if isinstance(text_input, str):
  234. text_tensor = self.tokenize(text_input)
  235. # multi texts input
  236. elif isinstance(text_input, list):
  237. if all([isinstance(elem, str) for elem in text_input]):
  238. text_tensor = self.tokenize(text_input)
  239. else:
  240. unsupported_elem_type = [
  241. type(elem) for elem in text_input
  242. if not isinstance(elem, str)
  243. ][0]
  244. raise TypeError(
  245. f'text should be str or List[str], but got a List containing one {unsupported_elem_type}'
  246. )
  247. # others
  248. else:
  249. raise TypeError(
  250. f'text should be str or List[str], but got {type(text_input)}'
  251. )
  252. output['text'] = text_tensor
  253. return output
  254. @PREPROCESSORS.register_module(
  255. Fields.multi_modal, module_name=Preprocessors.mplug_tasks_preprocessor)
  256. class MPlugPreprocessor(Preprocessor):
  257. def __init__(self,
  258. model_dir: str,
  259. mode: str = ModeKeys.INFERENCE,
  260. tokenizer_max_length: int = 25,
  261. *args,
  262. **kwargs):
  263. super().__init__(*args, **kwargs)
  264. self.model_dir = model_dir
  265. self.mode = mode
  266. self.tokenizer_max_length = tokenizer_max_length
  267. self._tokenizer = None
  268. self._patch_resize_transform = None
  269. self._image_map = {}
  270. @property
  271. def tokenizer(self):
  272. from transformers import BertTokenizer
  273. if self._tokenizer is None:
  274. self._tokenizer = BertTokenizer.from_pretrained(self.model_dir)
  275. return self._tokenizer
  276. @property
  277. def patch_resize_transform(self):
  278. if self._patch_resize_transform is None:
  279. from torchvision import transforms
  280. from modelscope.models.multi_modal.mplug import CONFIG_NAME, MPlugConfig
  281. config = MPlugConfig.from_yaml_file(
  282. osp.join(self.model_dir, CONFIG_NAME))
  283. mean = (0.48145466, 0.4578275, 0.40821073)
  284. std = (0.26862954, 0.26130258, 0.27577711)
  285. self._patch_resize_transform = transforms.Compose([
  286. transforms.Resize((config.image_res, config.image_res),
  287. interpolation=Image.BICUBIC),
  288. transforms.ToTensor(),
  289. transforms.Normalize(mean=mean, std=std),
  290. ])
  291. return self._patch_resize_transform
  292. def image_open(self, path: str) -> Tuple[Image.Image, int]:
  293. if path not in self._image_map:
  294. index = len(self._image_map)
  295. self._image_map[path] = (load_image(path), index)
  296. return self._image_map[path]
  297. def __call__(
  298. self, data: Union[Image.Image, tuple,
  299. Dict[str, Any]]) -> Dict[str, Any]:
  300. self.cfg = Config.from_file(
  301. osp.join(self.model_dir, ModelFile.CONFIGURATION))
  302. if isinstance(data, (Image.Image, str)):
  303. image = data
  304. elif isinstance(data, tuple):
  305. image = data[0]
  306. else:
  307. image = data['image']
  308. index = 0
  309. if isinstance(image, str):
  310. image, index = self.image_open(image)
  311. image = image.convert('RGB')
  312. image = self.patch_resize_transform(image)
  313. question = '' if self.cfg.task == Tasks.image_captioning \
  314. else data[1 if isinstance(data, tuple)
  315. else ('text' if 'text' in data else 'question')]
  316. question = self.tokenizer(
  317. question.lower(),
  318. padding='max_length',
  319. truncation=True,
  320. max_length=self.tokenizer_max_length,
  321. return_tensors='pt')
  322. if self.mode == ModeKeys.INFERENCE:
  323. image = torch.stack([image], dim=0)
  324. return {'image': image, 'question': question}
  325. else:
  326. answer = data['answer']
  327. answer = self.tokenizer(
  328. answer,
  329. padding='max_length',
  330. truncation=True,
  331. max_length=self.tokenizer_max_length,
  332. return_tensors='pt')
  333. output = {
  334. 'image': image,
  335. 'question_input_ids': question.input_ids.squeeze(),
  336. 'question_attention_mask': question.attention_mask.squeeze(),
  337. 'answer_input_ids': answer.input_ids.squeeze(),
  338. 'answer_attention_mask': answer.attention_mask.squeeze(),
  339. }
  340. if self.cfg.task == Tasks.image_text_retrieval:
  341. output['index'] = index
  342. return output