1 Star 0 Fork 48

michael1589 / omni-perception-pretrainer

forked from MindSpore / zidongtaichu 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

OPT

项目介绍

OPT(Omni-Perception Pre-Trainer)是全场景感知预训练模型的简称,是中科院自动化和华为在探索通用人工智能道路上的重要成果,并在2021年9月发布了全球首个图文音三模态千亿大模型,中文名字叫紫东.太初,本仓是紫东.太初十亿参数级别代码,软硬件采用全国产华为昇腾全栈,包含预训练模型及多个下游任务模型。多模态模型可从不同模态(语音、图片、文字等)的数据中训练学习,从而完成许多应用广泛的AI任务,紫东.太初的发布将改变当前单一模型对应单一任务的人工智能研发范式,实现三模态图文音的统一语义表达,在多模态内容的理解、搜索、推荐和问答,语音识别和合成,人机交互和无人驾驶等商业应用中具有潜力巨大的市场价值。

模型架构

紫东太初的模型架构由特征提取模型、三个单模态编码器、一个跨模态编码器和两个跨模态解码器组成,并提出了三个级别的预训练任务:(1)Token级建模;(2) 模态级建模;(3) 样本级建模,详细内容可阅读论文了解,模型主体架构图如下:

输入图片说明

环境安装

  1. 安装CANN 5.0.4
    前往昇腾社区下载安装包:
    https://www.hiascend.com/software/cann/commercial
    以arm + 欧拉的系统配置为例( x86的系统请选择x86的包 )
    安装驱动:
    ./A800-9000-npu-driver_21.0.4_linux-aarch64.run --full
    安装固件:
    ./A800-9000-npu-firmware_1.80.22.2.220.run --full
    安装cann-toolkit包:
    ./Ascend-cann-toolkit_5.0.4_linux-aarch64.run --full

  2. 安装MindSpore 1.6.1版本
    前往MindSpore官网,按照教程安装对应版本即可,当前为1.6.1,链接如下:
    https://www.mindspore.cn/install

  3. 安装requirements依赖
    pip install -r requirements.txt

代码结构

├── config #配置文件
│  ├── caption #caption任务的配置文件
│  │  ├── cross_modal_encoder_base.json
│  │  └── ft_cap_base.json
│  └── ... #同上
├── image #代码仓图片
│  ├── frameworkimage.png
│  └── image_caption.png
├── scripts #预训练模型及下游任务训练/测试启动脚本
│  ├── pretrain.sh
│  ├── test_caption.sh
│  ├── test_retrieval.sh
│  ├── train_caption.sh
│  └── train_retrieval.sh
├── src #核心代码
│  ├── config #配置文件
│  ├── data #数据加载
│  ├── fastspeech2_mindspore #语音生成
│  ├── mae_mindspore #MAE代码
│  ├── model_mindspore #模型核心代码
│  ├── vqvae_mindspore #vqvae代码
│  ├── scripts #下游任务启动入口脚本
│  └── tools #工具
├── requirements.txt
├── LICENSE
├── OWNERS
└── README.md

下游任务

  • 1. 文本生成(Image Caption)

    任务简介:
    Image Caption 顾名思义,即让算法根据输入的一幅图自动生成对应的描述性的文字,是图像理解中非常重要的基础任务。 输入图片说明

    数据集介绍:该数据集是COCO Caption的数据集,自动化所将标签从英文翻译为中文,该数据集的训练集包括11.3万张图像,每张图像有5条描述的中文标签,测试集有5千张图像,每张图像1条描述的中文标签。

    数据集下载:
    百度云盘链接:https://pan.baidu.com/s/1ECN5JXlRPQsBS8O763Y8pA
    提取码:84me
    解压至dataset/caption/路径下

    coco图片下载
    http://images.cocodataset.org/zips/train2014.zip
    http://images.cocodataset.org/zips/val2014.zip
    解压至dataset/caption/img/mscoco/路径下

    预训练模型下载:
    https://opt-release.obs.cn-central-221.ovaijisuan.com:443/model/OPT_1-38_136.ckpt
    下载至model/caption/路径下

    启动训练:
    单卡:
    bash scripts/train_caption.sh
    多卡:
    bash scripts/train_caption_parallel.sh [DEVICE_NUM] [VISIABLE_DEVICES(0,1,2,3,4,5,6,7)] [RANK_TABLE_FILE] (各项参数说明参考Mindspore官方文档)

    启动测试(需安装java1.8.0):
    bash scripts/test_caption.sh

    启动推理:
    bash scripts/inference_caption.sh
    支持对单目录或列表的推理,需要修改脚本中的inference_dir和inference_list参数。
    若存在inference_list则会读取list中的每项文件进行推理(文件目录为inference_dir拼接list中的文件名);
    若inference_list为空则遍历inference_dir中的每个文件执行推理。

    模型导出:
    python src/scripts/export_caption.py --ckpt_file="***.ckpt"
    默认导出格式为MindIR,可通过file_format进行修改(目前由于框架限制,紫东太初模型仅支持导出MindIR)。

    效果展示:

  • 2. 视觉问答(Visual Question Answer, VQA)

    任务简介:
    视觉问答是给定一幅图片和一个相关的问题,算法输出相应的答案,是多模态理解中的基础任务之一。

    数据集介绍:
    该数据集是百度发布的中文VQA数据集Are You Talking to a Machine? Dataset and Methods for Multilingual Image Question Answering,图片来自于COCO,每张图片对应一到两个问题。

    数据集下载:

    VQA数据集
    http://research.baidu.com/Public/uploads/5ac9e10bdd572.gz
    下载后将文件解压并重命名为FM-IQA.json,移动至dataset/vqa/txt/路径下

    coco图片
    http://images.cocodataset.org/zips/train2014.zip
    http://images.cocodataset.org/zips/val2014.zip
    解压至dataset/vqa/img/mscoco/路径下

    词表
    链接:https://pan.baidu.com/s/14FrOW7LMAwwDK5gfDS1BeA 提取码:j50u
    下载后运行python src/tools/vqa/prepare_vqa_tokens.py 提取vqa问题和答案的token,将得到的文件放到dataset/vqa/路径下

    预训练模型下载:
    https://opt-release.obs.cn-central-221.ovaijisuan.com:443/model/OPT_1-38_136.ckpt
    下载至model/vqa/路径下

    启动训练:
    单卡:
    bash scripts/train_vqa.sh
    多卡:
    bash scripts/train_vqa_parallel.sh [DEVICE_NUM] [VISIABLE_DEVICES(0,1,2,3,4,5,6,7)] [RANK_TABLE_FILE] (各项参数说明参考Mindspore官方文档)

    启动测试(需安装java1.8.0):
    bash scripts/test_vqa.sh

    效果展示:

  • 3. 跨模态检索(Cross-modal Retrieval) 任务简介:
    跨模态检索是在不同模态之间进行数据的检索。
    例如输入图片,在文本库中挑选出与图片内容最匹配的描述;输入描述,在图片库中挑出与这句描述内容最符合的图片。 输入图片说明

    数据集介绍:该数据集是COCO Caption的数据集,自动化所将标签从英文翻译为中文,该数据集的训练集包括12万张图像,每张图像有5条描述的中文标签, 选取了150图文对进行检索性能的测试。

    数据集下载:
    链接:https://pan.baidu.com/s/1lArnJlPfkahcn5IZlgwJvQ 提取码:fdc8
    解压至dataset/retrieval/路径下

    预训练模型下载:
    https://opt-release.obs.cn-central-221.ovaijisuan.com:443/model/OPT_1-38_136.ckpt
    下载至model/retrieval/路径下

    启动训练:
    bash scripts/train_retrieval_parallel.sh [DEVICE_NUM] [VISIABLE_DEVICES(0,1,2,3,4,5,6,7)] [RANK_TABLE_FILE] (各项参数说明参考Mindspore官方文档)

    启动测试(将test_retrieval.sh中的ckpt模型路径更换成自己训练的):
    bash scripts/test_retrieval.sh

    评估结果:

     |  输入尺寸 | IR @1  | IR @5  | IR @10 | TR @1  | TR @5  | TR @10 |
     |----------|--------|--------|--------|--------|--------|--------|
     |   448    |    70  |   96   |  98.7  |  64.67 | 93.33  |  98    |
  • 4. 以文生图(Text-To-Image)

    任务简介:
    以文生图任务是条件图像生成任务中重要的任务之一,要求模型理解输入文本的语义信息并生成与输入文本描述内容一致的逼真图像。

    启动两阶段训练,在第一阶段训练VQVAE,采用训练好的VQVAE提取图像token;在第二阶段训练Transformer解码器,建模文本token和图像token的跨模态关联关系:
    bash scripts/train_txt2img_stageone.sh
    bash scripts/train_txt2img_stagetwo.sh

    启动推理(将test_txt2img.sh中ckpt的路径替换为实际权重文件路径):
    bash scripts/test_txt2img.sh

  • 5. 语音合成(Text To Speech)

    任务简介:
    语音合成是输入文本输出语音。

    数据集介绍:该数据集是AISHELL3的数据集。AISHELL-3的语音时长为85小时88035句,可做为多说话人合成系统。录制过程在安静室内环境中,使用高保真麦克风(44.1kHz,16bit)。218名来自中国不同口音区域的发言人参与录制。专业语音校对人员进行拼音和韵律标注,并通过严格质量检验,此数据库音字确率在98%以上。

    数据集下载:
    链接:https://pan.baidu.com/s/1dt04CmP5v_EL_dUq8S8SVA 提取码:o8ja
    解压至dataset/speech/路径下

    启动训练:
    bash scripts/train_speech.sh

    启动测试(test_speech.sh中的ckpt模型路径更换成自己训练的):
    bash scripts/test_speech.sh

模型创新

  • 全球首个多模态图文音预训练大模型

  • 多层次多任务自监督学习

  • 弱关联多模态数据语义统一表达

  • 兼顾任务感知和推理增强的中文预训练模型

  • 多粒度学习与注意力指导的视觉预训练模型

  • 基于自监督预训练的多任务语音建模技术

应用价值

输入图片说明

引用说明

如果你使用了该项目,请引用该论文,论文链接:https://arxiv.org/abs/2107.00249

免责声明

MindSpore(“我们”)不拥有数据集的任何所有权或知识产权,并且经过训练的模型是在“原样”和“可用”的基础上提供的。我们不对任何类型的数据集和经过训练的模型(统称为“材料”)作出任何陈述或保证,并且不对材料引起的任何损失、损害、费用或成本负责。请确保您有权根据数据集的相应许可和相关许可协议的条款使用数据集。提供的训练模型仅用于研究和教育目的。

致数据集所有者:如果您不希望 MindSpore 中包含数据集,或希望以任何方式对其进行更新,我们将根据您的要求删除或更新内容。请通过 GitHub 或 Gitee 联系我们。非常感谢您对社区的理解和贡献。

MindSpore 在 Apache 2.0 许可下可用,请参阅 LICENSE 文件

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] 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.

简介

OPT(Omni-Perception Pre-Trainer)是全场景感知预训练模型的简称,中文名字叫紫东太初,是中科院自动化和华为联合研发的多模态预训练模型,本仓是紫东太初十亿参数级别模型的MindSpore版本代码,包含预训练模型及多个下游任务模型。 展开 收起
Python
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/binghan1589/omni-perception-pretrainer.git
git@gitee.com:binghan1589/omni-perception-pretrainer.git
binghan1589
omni-perception-pretrainer
omni-perception-pretrainer
master

搜索帮助