From 59568bbb6301a6a3a573129dc6bc78381fc8c984 Mon Sep 17 00:00:00 2001 From: DanielYang Date: Mon, 28 Nov 2022 01:35:02 +0800 Subject: [PATCH] test=update_yaml_onlinedemo, test=release/2.3 (#5676) --- modelcenter/DeepCFD/info.yaml | 2 +- ...troduction.ipynb => introduction_cn.ipynb} | 0 modelcenter/ERNIE-3.0 Zeus/info.yaml | 2 +- .../ERNIE-3.0 Zeus/introduction_cn.ipynb | 35 +- modelcenter/ERNIE-3.0/info.yaml | 4 +- modelcenter/ERNIE-Layout/info.yaml | 2 +- modelcenter/ERNIE-M/info.yaml | 2 +- modelcenter/ERNIE-UIE/info.yaml | 2 +- modelcenter/ERNIE-ViLG/info.yaml | 2 +- modelcenter/ERNIE-ViLG/introduction_cn.ipynb | 9 +- modelcenter/PINN-CFD/info.yaml | 2 +- modelcenter/PP-HumanV2/info.yaml | 2 +- modelcenter/PP-MSVSR/info.yaml | 2 +- modelcenter/PP-OCRv2/info.yaml | 2 +- modelcenter/PP-OCRv3/info.yaml | 2 +- modelcenter/PP-ShiTu/info.yaml | 2 +- modelcenter/PP-StructureV2/info.yaml | 2 +- modelcenter/PP-TinyPose/info.yaml | 2 +- modelcenter/PP-Vehicle/info.yaml | 2 +- modelcenter/{VSQL => PQ-VSQL}/.gitkeep | 0 modelcenter/PQ-VSQL/download_cn.md | 5 + modelcenter/PQ-VSQL/download_en.md | 5 + modelcenter/PQ-VSQL/info.yaml | 20 + modelcenter/PQ-VSQL/introduction_cn.ipynb | 505 ++++++++++++++++++ modelcenter/PQ-VSQL/introduction_en.ipynb | 414 ++++++++++++++ modelcenter/VIMER-CAE/info.yaml | 2 +- modelcenter/VIMER-StrucTexT/info.yaml | 2 +- modelcenter/VIMER-UFO/info.yaml | 2 +- 28 files changed, 1001 insertions(+), 32 deletions(-) rename modelcenter/DeepCFD/{introduction.ipynb => introduction_cn.ipynb} (100%) rename modelcenter/{VSQL => PQ-VSQL}/.gitkeep (100%) create mode 100644 modelcenter/PQ-VSQL/download_cn.md create mode 100644 modelcenter/PQ-VSQL/download_en.md create mode 100644 modelcenter/PQ-VSQL/info.yaml create mode 100644 modelcenter/PQ-VSQL/introduction_cn.ipynb create mode 100644 modelcenter/PQ-VSQL/introduction_en.ipynb diff --git a/modelcenter/DeepCFD/info.yaml b/modelcenter/DeepCFD/info.yaml index a634944e..ca40942e 100644 --- a/modelcenter/DeepCFD/info.yaml +++ b/modelcenter/DeepCFD/info.yaml @@ -14,4 +14,4 @@ Datasets: "deepcfd-data" Publisher: "Baidu" License: "apache.2.0" IfTraining: 1 -IfOnlineDemo: 1 +IfOnlineDemo: 0 diff --git a/modelcenter/DeepCFD/introduction.ipynb b/modelcenter/DeepCFD/introduction_cn.ipynb similarity index 100% rename from modelcenter/DeepCFD/introduction.ipynb rename to modelcenter/DeepCFD/introduction_cn.ipynb diff --git a/modelcenter/ERNIE-3.0 Zeus/info.yaml b/modelcenter/ERNIE-3.0 Zeus/info.yaml index c9c5bfbd..fd021938 100644 --- a/modelcenter/ERNIE-3.0 Zeus/info.yaml +++ b/modelcenter/ERNIE-3.0 Zeus/info.yaml @@ -14,4 +14,4 @@ Datasets: "" Publisher: "Baidu" License: "apache.2.0" IfTraining: 0 -IfOnlineDemo: 1 +IfOnlineDemo: 0 diff --git a/modelcenter/ERNIE-3.0 Zeus/introduction_cn.ipynb b/modelcenter/ERNIE-3.0 Zeus/introduction_cn.ipynb index cd4e2162..6a2b4dc6 100644 --- a/modelcenter/ERNIE-3.0 Zeus/introduction_cn.ipynb +++ b/modelcenter/ERNIE-3.0 Zeus/introduction_cn.ipynb @@ -8,7 +8,7 @@ "source": [ "## 1. ERNIE 3.0 Zeus 模型简介\n", "\n", - "ERNIE 3.0 Zeus 是 ERNIE 3.0 系列模型的最新升级。其除了对无标注数据和知识图谱的学习之外,还通过持续学习对百余种不同形式的任务数据学习。实现了任务知识增强,显著提升了模型的零样本/小样本学习能力。\n", + "ERNIE 3.0 Zeus 是 ERNIE 3.0 系列模型的最新升级。其除了对无标注数据和知识图谱的学习之外,还通过持续学习对百余种不同形式的任务数据学习。实现了任务知识增强,显著提升了模型的零样本/小样本学习能力。[点击此处进入体验页面](https://wenxin.baidu.com/ernie3)\n", "\n", "## 2. 模型原理介绍\n", "\n", @@ -20,7 +20,7 @@ " \n", "#### 温馨提示\n", "\n", - "每个账户每日免费请求ERNIE 3.0系列服务的上限为200条输入,免费请求额度共2000条输入。如果您有更多请求需求,请跟我们联系:[体验申请](https://wenxin.baidu.com/wenxin/apply3)\n", + "* 每个账户每日免费请求ERNIE 3.0系列服务的上限为200条输入,免费请求额度共2000条输入。如果您有更多请求额度需求和商务合作需求,请跟我们联系:[体验申请](https://wenxin.baidu.com/wenxin/apply3)\n", "\n", "\n", "#### 获取API Key\n", @@ -34,11 +34,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "collapsed": false }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple\n", + "Collecting wenxin-api\n", + " Downloading https://pypi.tuna.tsinghua.edu.cn/packages/0e/32/fb1e931cc0436205fb53193a4c1f9fd8aae75ba71dbd999fd55b9899428b/wenxin_api-0.1.0-py3-none-any.whl (24 kB)\n", + "Requirement already satisfied: tqdm in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from wenxin-api) (4.64.1)\n", + "Requirement already satisfied: requests>=2.20 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from wenxin-api) (2.24.0)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20->wenxin-api) (2019.9.11)\n", + "Requirement already satisfied: chardet<4,>=3.0.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20->wenxin-api) (3.0.4)\n", + "Requirement already satisfied: idna<3,>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20->wenxin-api) (2.8)\n", + "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20->wenxin-api) (1.25.6)\n", + "Installing collected packages: wenxin-api\n", + "Successfully installed wenxin-api-0.1.0\n", + "\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip available: \u001b[0m\u001b[31;49m22.1.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m22.3.1\u001b[0m\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n" + ] + } + ], "source": [ "!pip install --upgrade wenxin-api" ] @@ -107,7 +128,7 @@ "\n", "## 5. 应用场景\n", "\n", - "智能创作、摘要生成、问答、语义检索、情感分析、信息抽取、文本匹配、文本纠错等各类自然语言理解和生成任务\n", + "智能创作、摘要生成、问答、语义检索、情感分析、信息抽取、文本匹配、文本纠错等各类自然语言理解和生成任务。\n", "\n", "## 6. 使用方案\n", "\n", @@ -115,11 +136,11 @@ "\n", "#### 通过飞桨旸谷社区在线体验\n", "\n", - "通过飞桨旸谷社区在线体验 ERNIE 3.0 Zeus 的文本理解和文本创作能力,您可以通过 ERNIE 3.0 Zeus Prompt 接口体验预置 prompt 技能,预置技能包括作文创作、文案创作、摘要生成、问题生成、古诗创作、对联续写、小说续写、自由问答、情感分析、信息抽取、同义改写、文本匹配、文本纠错、完型填空、Text2SQL 等十余种预置技能,也可以自定义 prompt 体验 ERNIE 3.0 Zeus 强大的零样本、小样本自然语言处理能力。同样的,通过 ERNIE3.0 Zeus 接口您可以随意输入内容,体验模型强大的续写能力。\n", + "通过飞桨旸谷社区[在线体验](https://wenxin.baidu.com/ernie3) ERNIE 3.0 Zeus 的文本理解和文本创作能力,您可以通过 ERNIE 3.0 Zeus Prompt 接口体验预置 prompt 技能,预置技能包括作文创作、文案创作、摘要生成、问题生成、古诗创作、对联续写、小说续写、自由问答、情感分析、信息抽取、同义改写、文本匹配、文本纠错、完型填空、Text2SQL 等十余种预置技能,也可以自定义 prompt 体验 ERNIE 3.0 Zeus 强大的零样本、小样本自然语言处理能力。同样的,通过 ERNIE3.0 Zeus 接口您可以随意输入内容,体验模型强大的续写能力。\n", "\n", "#### 通过 API 调用体验\n", "\n", - "ERNIE 3.0 Zeus 提供[ API 体验调用的入口](https://wenxin.baidu.com/ernie3),您也可以在飞桨旸谷社区 API 体验专区申请 AK、SK 进行接口调用体验。\n" + "ERNIE 3.0 Zeus 提供API体验调用的入口,您也可以在飞桨旸谷社区 API 体验专区申请 AK、SK 进行接口调用体验(上述已给出API接口调用体验流程)。" ] } ], diff --git a/modelcenter/ERNIE-3.0/info.yaml b/modelcenter/ERNIE-3.0/info.yaml index 85dae6f8..ce0343ba 100644 --- a/modelcenter/ERNIE-3.0/info.yaml +++ b/modelcenter/ERNIE-3.0/info.yaml @@ -33,5 +33,5 @@ License: "apache.2.0" Paper: - title: "ERNIE-Tiny: A Progressive Distillation Framework for Pretrained Transformer Compression" url: "https://arxiv.org/abs/2106.02241" -IfTraining: 0 -IfOnlineDemo: 1 \ No newline at end of file +IfTraining: 1 +IfOnlineDemo: 0 \ No newline at end of file diff --git a/modelcenter/ERNIE-Layout/info.yaml b/modelcenter/ERNIE-Layout/info.yaml index 6c8ebc64..522f65d2 100644 --- a/modelcenter/ERNIE-Layout/info.yaml +++ b/modelcenter/ERNIE-Layout/info.yaml @@ -31,4 +31,4 @@ Paper: - title: "ERNIE-Layout: Layout-Knowledge Enhanced Multi-modal Pre-training for Document Understanding" url: https://arxiv.org/pdf/2210.06155.pdf IfTraining: 1 -IfOnlineDemo: 1 \ No newline at end of file +IfOnlineDemo: 0 \ No newline at end of file diff --git a/modelcenter/ERNIE-M/info.yaml b/modelcenter/ERNIE-M/info.yaml index 5461f315..3d7ab7e7 100644 --- a/modelcenter/ERNIE-M/info.yaml +++ b/modelcenter/ERNIE-M/info.yaml @@ -22,5 +22,5 @@ Paper: - title: "ERNIE-M: Enhanced Multilingual Representation by Aligning Cross-lingual\ \ Semantics with Monolingual Corpora" url: "https://arxiv.org/pdf/2012.15674.pdf" -IfTraining: 0 +IfTraining: 1 IfOnlineDemo: 0 \ No newline at end of file diff --git a/modelcenter/ERNIE-UIE/info.yaml b/modelcenter/ERNIE-UIE/info.yaml index 48ba133c..243adc0b 100644 --- a/modelcenter/ERNIE-UIE/info.yaml +++ b/modelcenter/ERNIE-UIE/info.yaml @@ -65,5 +65,5 @@ License: "apache.2.0" Paper: - title: "Unified Structure Generation for Universal Information Extraction" url: "https://arxiv.org/pdf/2203.12277.pdf" -IfTraining: 0 +IfTraining: 1 IfOnlineDemo: 1 \ No newline at end of file diff --git a/modelcenter/ERNIE-ViLG/info.yaml b/modelcenter/ERNIE-ViLG/info.yaml index d71f0670..25794194 100644 --- a/modelcenter/ERNIE-ViLG/info.yaml +++ b/modelcenter/ERNIE-ViLG/info.yaml @@ -14,4 +14,4 @@ Datasets: "" Publisher: "Baidu" License: "apache.2.0" IfTraining: 0 -IfOnlineDemo: 1 +IfOnlineDemo: 0 diff --git a/modelcenter/ERNIE-ViLG/introduction_cn.ipynb b/modelcenter/ERNIE-ViLG/introduction_cn.ipynb index d6c1d65d..88f8d173 100644 --- a/modelcenter/ERNIE-ViLG/introduction_cn.ipynb +++ b/modelcenter/ERNIE-ViLG/introduction_cn.ipynb @@ -8,7 +8,7 @@ "source": [ "## 1. ERNIE-ViLG模型简介\n", "\n", - "ERNIE-ViLG是一个知识增强跨模态图文生成大模型,将文生成图和图生成文任务融合到同一个模型进行端到端的学习,从而实现文本和图像的跨模态语义对齐。可以支持用户进行内容创作,让每个用户都能够体验到一个低门槛的创作平台。[点击此处进去体验页面](https://wenxin.baidu.com/moduleApi/ernieVilg)\n", + "ERNIE-ViLG是一个知识增强跨模态图文生成大模型,将文生成图和图生成文任务融合到同一个模型进行端到端的学习,从而实现文本和图像的跨模态语义对齐。可以支持用户进行内容创作,让每个用户都能够体验到一个低门槛的创作平台。[点击此处进入体验页面](https://wenxin.baidu.com/moduleApi/ernieVilg)\n", "\n", "## 2. 模型原理介绍\n", "百度文心ERNIE-ViLG 模型提出统一的跨模态双向生成模型,通过自回归生成模式对图像生成和文本生成任务进行统一建模,更好地捕捉模态间的语义对齐关系,从而同时提升图文双向生成任务的效果。文心 ERNIE-ViLG 在文本生成图像的权威公开数据集 MS-COCO 上,图片质量评估指标 FID(Fréchet Inception Distance)远超 OpenAI 的DALL-E等同类模型,并刷新了图像描述多项任务的最好效果。此外,文心ERNIE-ViLG还凭借强大的跨模态理解能力,在生成式视觉问答任务上也取得了领先成绩。\n", @@ -20,7 +20,7 @@ "\n", "* 温馨提示:\n", "\n", - "每个账户每日免费请求ERNIE-ViLG API服务的上限为100条输入,免费请求额度共500条输入。如需提额,请在[合作咨询](https://wenxin.baidu.com/wenxin/apply)的需求描述里填写您的购买需求。\n", + "每个账户每日免费请求ERNIE-ViLG API服务的上限为100条输入,免费请求额度共500条输入。如需提额或者商务合作请在[合作咨询](https://wenxin.baidu.com/wenxin/apply)的需求描述里填写您的购买需求或者合作需求。\n", "\n", "### 获取API Key\n", "\n", @@ -131,14 +131,13 @@ "\n", "## 5. 使用方案\n", "\n", - "\n", "#### 通过飞桨旸谷社区在线体验\n", "\n", - "通过飞桨旸谷社区在线体验 ERNIE-ViLG的文生图能力。\n", + "通过飞桨旸谷社区[在线体验](https://wenxin.baidu.com/moduleApi/ernieVilg) ERNIE-ViLG的文生图能力。\n", "\n", "#### 通过 API 调用体验\n", "\n", - "ERNIE-ViLG 提供API体验调用的入口,您也可以在飞桨旸谷社区 API 体验专区申请 AK、SK 进行接口调用体验。" + "ERNIE-ViLG 提供API体验调用的入口,您也可以在飞桨旸谷社区 API 体验专区申请 AK、SK 进行接口调用体验(上述已给出API接口调用体验流程)。" ] } ], diff --git a/modelcenter/PINN-CFD/info.yaml b/modelcenter/PINN-CFD/info.yaml index 7dd5258c..6782938b 100644 --- a/modelcenter/PINN-CFD/info.yaml +++ b/modelcenter/PINN-CFD/info.yaml @@ -22,4 +22,4 @@ Datasets: "cylinder2D_continuous" Publisher: "Baidu" License: "apache.2.0" IfTraining: 1 -IfOnlineDemo: 1 +IfOnlineDemo: 0 diff --git a/modelcenter/PP-HumanV2/info.yaml b/modelcenter/PP-HumanV2/info.yaml index 31585430..4227118d 100644 --- a/modelcenter/PP-HumanV2/info.yaml +++ b/modelcenter/PP-HumanV2/info.yaml @@ -40,5 +40,5 @@ Example: Datasets: "" Publisher: "Baidu" License: "apache.2.0" -IfTraining: 0 +IfTraining: 1 IfOnlineDemo: 1 diff --git a/modelcenter/PP-MSVSR/info.yaml b/modelcenter/PP-MSVSR/info.yaml index 2536be9f..95c456d3 100644 --- a/modelcenter/PP-MSVSR/info.yaml +++ b/modelcenter/PP-MSVSR/info.yaml @@ -26,4 +26,4 @@ Paper: - title: "PP-MSVSR: Multi-Stage Video Super-Resolution" url: "https://arxiv.org/pdf/2112.02828.pdf" IfTraining: 1 -IfOnlineDemo: 1 +IfOnlineDemo: 0 diff --git a/modelcenter/PP-OCRv2/info.yaml b/modelcenter/PP-OCRv2/info.yaml index ec5d411c..224103de 100644 --- a/modelcenter/PP-OCRv2/info.yaml +++ b/modelcenter/PP-OCRv2/info.yaml @@ -21,5 +21,5 @@ License: "apache.2.0" Paper: - title: "PP-OCRv2: Bag of Tricks for Ultra Lightweight OCR System" url: "https://arxiv.org/abs/2109.03144" -IfTraining: 0 +IfTraining: 1 IfOnlineDemo: 1 diff --git a/modelcenter/PP-OCRv3/info.yaml b/modelcenter/PP-OCRv3/info.yaml index e177ac9e..08a150d3 100644 --- a/modelcenter/PP-OCRv3/info.yaml +++ b/modelcenter/PP-OCRv3/info.yaml @@ -42,5 +42,5 @@ License: "apache.2.0" Paper: - title: "PP-OCRv3: More Attempts for the Improvement of Ultra Lightweight OCR System" url: "https://arxiv.org/abs/2206.03001" -IfTraining: 0 +IfTraining: 1 IfOnlineDemo: 1 diff --git a/modelcenter/PP-ShiTu/info.yaml b/modelcenter/PP-ShiTu/info.yaml index 5a757c81..283c31d6 100644 --- a/modelcenter/PP-ShiTu/info.yaml +++ b/modelcenter/PP-ShiTu/info.yaml @@ -22,4 +22,4 @@ Publisher: "Baidu" License: "apache.2.0" Paper: "" IfTraining: 1 -IfOnlineDemo: 1 +IfOnlineDemo: 0 diff --git a/modelcenter/PP-StructureV2/info.yaml b/modelcenter/PP-StructureV2/info.yaml index df7c1e30..244d466d 100644 --- a/modelcenter/PP-StructureV2/info.yaml +++ b/modelcenter/PP-StructureV2/info.yaml @@ -45,5 +45,5 @@ License: "apache.2.0" Paper: - title: "PP-StructureV2: A Stronger Document Analysis System" url: "https://arxiv.org/abs/2210.05391v2" -IfTraining: 0 +IfTraining: 1 IfOnlineDemo: 1 diff --git a/modelcenter/PP-TinyPose/info.yaml b/modelcenter/PP-TinyPose/info.yaml index 65e65c20..d55efab3 100644 --- a/modelcenter/PP-TinyPose/info.yaml +++ b/modelcenter/PP-TinyPose/info.yaml @@ -24,5 +24,5 @@ Example: Datasets: "COCO train2017,AI Challenger trainset,COCO person keypoints val2017,COCO instances val2017" Publisher: "Baidu" License: "apache.2.0" -IfTraining: 0 +IfTraining: 1 IfOnlineDemo: 1 diff --git a/modelcenter/PP-Vehicle/info.yaml b/modelcenter/PP-Vehicle/info.yaml index 39977410..43dad246 100644 --- a/modelcenter/PP-Vehicle/info.yaml +++ b/modelcenter/PP-Vehicle/info.yaml @@ -24,5 +24,5 @@ Example: Datasets: "BDD-100k" Publisher: "Baidu" License: "apache.2.0" -IfTraining: 0 +IfTraining: 1 IfOnlineDemo: 1 diff --git a/modelcenter/VSQL/.gitkeep b/modelcenter/PQ-VSQL/.gitkeep similarity index 100% rename from modelcenter/VSQL/.gitkeep rename to modelcenter/PQ-VSQL/.gitkeep diff --git a/modelcenter/PQ-VSQL/download_cn.md b/modelcenter/PQ-VSQL/download_cn.md new file mode 100644 index 00000000..a3b50c4f --- /dev/null +++ b/modelcenter/PQ-VSQL/download_cn.md @@ -0,0 +1,5 @@ +# 模型列表 + +| 模型名称 | 模型简介 | 数据集 | 下载地址 | +|---|---|---|---| +| VSQL | 图片分类 | MNIST(0,1) | [预训练模型](https://release-data.cdn.bcebos.com/PaddleQuantum/vsql.pdparams) | diff --git a/modelcenter/PQ-VSQL/download_en.md b/modelcenter/PQ-VSQL/download_en.md new file mode 100644 index 00000000..843ee262 --- /dev/null +++ b/modelcenter/PQ-VSQL/download_en.md @@ -0,0 +1,5 @@ +# Model list + +| Model | Introduction | Dataset | Download | +|---|---|---|---| +| VSQL | Image classification | MNIST(0, 1) | [pretrained model](https://release-data.cdn.bcebos.com/PaddleQuantum/vsql.pdparams) | diff --git a/modelcenter/PQ-VSQL/info.yaml b/modelcenter/PQ-VSQL/info.yaml new file mode 100644 index 00000000..fd046510 --- /dev/null +++ b/modelcenter/PQ-VSQL/info.yaml @@ -0,0 +1,20 @@ +--- +Model_Info: + name: "PQ-VSQL" + description: "基于影子特征的量子-经典混合模型" + description_en: "Hybrid quantum-classical model based on the shadow features" + update_time: + icon: "https://user-images.githubusercontent.com/23690325/203944010-3f7e9373-d6d3-4bf5-989a-d5817b15e20f.png" +Task: +- tag: "量子计算" + tag_en: "Quantum Computing" + sub_tag: "变分影子量子学习" + sub_tag_en: "VSQL" +Datasets: MNIST +Pulisher: Baidu +License: Apache 2.0 +Paper: +- title: "VSQL: Variational Shadow Quantum Learning for Classification" + url: https://ojs.aaai.org/index.php/AAAI/article/view/17016 +IfTraining: 0 +IfOnlineDemo: 0 \ No newline at end of file diff --git a/modelcenter/PQ-VSQL/introduction_cn.ipynb b/modelcenter/PQ-VSQL/introduction_cn.ipynb new file mode 100644 index 00000000..9c8d2a56 --- /dev/null +++ b/modelcenter/PQ-VSQL/introduction_cn.ipynb @@ -0,0 +1,505 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "chronic-tunisia", + "metadata": {}, + "source": [ + "## 1. VSQL 模型简介\n", + "\n", + "变分影子量子学习(variational shadow quantum learning, VSQL)是一个在监督学习框架下的量子–经典混合算法。它使用了参数化量子电路(parameterized quantum circuit, PQC)和经典影子(classical shadow),和通常使用的变分量子算法(variational quantum alogorithm, VQA)不同的是,VSQL 只从子空间获取局部特征,而不是从整个希尔伯特空间获取特征。" + ] + }, + { + "cell_type": "markdown", + "id": "8429d648", + "metadata": {}, + "source": [ + "## 2. 模型原理简介\n", + "\n", + "VSQL 的流程图如下:\n", + "\n", + "![pipeline](https://ai-studio-static-online.cdn.bcebos.com/36c5194bc48a4af88560172fdd7ec15b8fd3225c27b644acad1981046a48d1ec \"VSQL 流程图\")\n", + "
VSQL 流程图
\n", + "\n", + "其训练步骤为:\n", + "\n", + "1. 将经典数据 $\\mathbf{x}^i$ 编码到量子态 $\\left|\\mathbf{x}^i\\right>$。\n", + "2. 准备一个参数化局部量子电路 $U(\\mathbf{\\theta})$ 并且初始化它的参数 $\\mathbf{\\theta}$。\n", + "3. 在前几个量子比特上作用 $U(\\mathbf{\\theta})$,然后通过测量局部可观测量(比如说泡利 $X\\otimes X\\cdots \\otimes X$ 算符)来获取一个局部影子特征。\n", + "4. 每次将 $U(\\mathbf{\\theta})$ 向下移动一个量子比特,重复步骤3直到 $U(\\mathbf{\\theta})$ 作用到最后一个量子比特上。\n", + "5. 将步骤3–4中得到的所有局部影子特征传入经典 FCNN 并通过激活函数得到预测的标签 $\\tilde{\\mathbf{y}}^i$。对于多分类问题来说,我们使用归一化指数函数 (softmax) 作为激活函数。\n", + "6. 重复步骤3–5直到数据集内所有的数据点都经过了处理。然后计算损失函数 $\\mathcal{L}(\\mathbf{\\theta}, \\mathbf{W}, \\mathbf{b})$。\n", + "7. 通过梯度下降等优化方法调整参数 $\\mathbf{\\theta}$、$\\mathbf{W}$ 和 $\\mathbf{b}$ 的值,从而最小化损失函数。这样我们就得到了优化后的模型 $\\mathcal{F}$。\n", + "\n", + "由于 VSQL 只获取局部影子特征,所以它可以比较容易地在有拓扑连接限制的量子设备上实现。除此之外,因为我们用同一个 $U(\\mathbf{\\theta})$ 来获取整个电路上的局部影子特征,所以需要训练的参数数量相对于通常使用的变分量子分类器来说大大减少。\n", + "\n", + "### 2.1 局部影子电路介绍\n", + "\n", + "在讲电路的细节之前,我们需要说明几个参数:\n", + "- $n$:编码后量子态的量子比特数目。\n", + "- $n_{qsc}$:量子影子电路的宽度。我们每次只在连续 $n_{qsc}$ 个量子比特上作用 $U(\\mathbf{\\theta})$。\n", + "- $D$:电路的深度,表示 $U(\\mathbf{\\theta})$ 门中某一层电路重复的次数。\n", + "\n", + "这里我们给出 $n=4$、$n_{qsc}=2$ 时的一个例子:\n", + "\n", + "我们首先在前两个量子比特上作用 $U(\\mathbf{\\theta})$,并且获取第一个影子特征 $O_1$。\n", + "\n", + "![qubit0](https://ai-studio-static-online.cdn.bcebos.com/a544360d2b864cd2882c6965bf30e1a0f5fbf089173043cd95a5821b1cdbd799 \"获取第一个影子特征\")\n", + "
获取第一个影子特征
\n", + "\n", + "然后我们准备一样的输入态 $\\left|\\mathbf{x}^i\\right>$,在中间两个量子比特上作用 $U(\\mathbf{\\theta})$,得到第二个影子特征 $O_2$。\n", + "\n", + "![qubit1](https://ai-studio-static-online.cdn.bcebos.com/9cdb70da3e5f47c2bd089f020975a987e1348d71d724418d890591f298786d4c \"获取第二个影子特征\")\n", + "
获取第二个影子特征
\n", + "\n", + "最后,我们再准备一个一样的输入态,在最后两个量子比特上作用 $U(\\mathbf{\\theta})$,得到影子特征 $O_3$。这样我们就处理完了这个数据点!\n", + "\n", + "![qubit2](https://ai-studio-static-online.cdn.bcebos.com/6a404995be1141bc9fd6ca36b5e394e00fbe302621c4413bbf86554de6bfc964 \"获取第三个影子特征\")\n", + "
获取第三个影子特征
\n", + "\n", + "通常来说,处理一个数据点需要重复以上步骤 $n - n_{qsc} + 1$ 次。有一点需要指出的是,在上面这个例子中我们只使用了一个影子电路,在获取这三个影子特征时我们使用同样的参数 $\\mathbf{\\theta}$。你可以选择增加影子电路的数量来解决更复杂的问题,这里需要注意的是不同影子电路中的参数 $\\mathbf{\\theta}$ 不同。 \n", + " \n", + "在后面的 MNIST 二分类任务中,我们将使用2–局部影子电路,即 $n_{qsc}=2$。下图展示了这个影子电路的结构。\n", + "\n", + "![2-local](https://ai-studio-static-online.cdn.bcebos.com/0c1035262cb64f61bd3cc87dbf53253aa6a7ecc170634c4db8dd71d576a9409c \"local数为2时的影子电路结构\")\n", + "
local数为2时的影子电路结构
\n", + "\n", + "为了增强量子电路的表达能力,我们将重复 $D$ 次虚线框中的结构。$U(\\mathbf{\\theta})$ 的设计并不是唯一的,这里展示的仅仅是一个例子,也可以设计别的电路结构。" + ] + }, + { + "cell_type": "markdown", + "id": "2f0070ae", + "metadata": {}, + "source": [ + "## 3. 模型效果\n", + "\n", + "VSQL 在 MNIST 数据集上的二分类效果如下:\n", + "\n", + "![binary-classification](https://ai-studio-static-online.cdn.bcebos.com/03c38b174d0e47ae9dbeea6dfda1333d6d3aa74209594324b78c9159b72e7e8a \"二分类效果图\")\n", + "
二分类效果图
\n", + "\n", + "VSQL 在 MNIST 数据集上的十分类效果如下:\n", + "\n", + "![10-classification](https://ai-studio-static-online.cdn.bcebos.com/54a0273672ad4ec5ba6b7d73b3b225f8d97380c43ceb495a82d16a258117182b \"十分类效果图\")\n", + "
十分类效果图
\n", + "\n", + "由表可见,相比于其它的量子神经网络,VSQL 可以使用很少的参数实现更高的分类准确率。而与经典神经网络相比,在十分类任务上,VSQL 也可以使用较少的参数达到相近的效果。当数据量较小时,VSQL 比经典神经网络的效果会更好。" + ] + }, + { + "cell_type": "markdown", + "id": "17661d06", + "metadata": {}, + "source": [ + "## 4. 模型如何使用\n", + "\n", + "按照如下代码来配置环境:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "eb7a2be4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Looking in indexes: https://mirrors.bfsu.edu.cn/pypi/web/simple\n", + "Requirement already satisfied: paddle-quantum in /Users/wangzihe/temp/baidu/QPlatform/PaddleQu (2.2.1)\n", + "Requirement already satisfied: paddlepaddle<=2.3.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (2.3.0)\n", + "Requirement already satisfied: scipy in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (1.7.1)\n", + "Collecting protobuf<=3.20.1\n", + " Using cached https://mirrors.bfsu.edu.cn/pypi/web/packages/92/0e/b8a60441178c8725fb3afa648e80c312a77feab31e7831d69c672b3c18cc/protobuf-3.20.1-cp37-cp37m-macosx_10_9_x86_64.whl (961 kB)\n", + "Requirement already satisfied: networkx>=2.5 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (2.6.3)\n", + "Requirement already satisfied: qcompute in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (3.0.0)\n", + "Requirement already satisfied: matplotlib>=3.3.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (3.5.2)\n", + "Requirement already satisfied: tqdm in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (4.64.0)\n", + "Requirement already satisfied: openfermion in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (1.5.1)\n", + "Requirement already satisfied: opencv-python in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (4.6.0.66)\n", + "Requirement already satisfied: scikit-learn in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (1.0.2)\n", + "Requirement already satisfied: fastdtw in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (0.3.4)\n", + "Requirement already satisfied: cvxpy in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (1.2.2)\n", + "Requirement already satisfied: rich in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (12.0.1)\n", + "Requirement already satisfied: pyscf in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (2.1.1)\n", + "Requirement already satisfied: pillow>=6.2.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from matplotlib>=3.3.0->paddle-quantum) (9.3.0)\n", + "Requirement already satisfied: pyparsing>=2.2.1 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from matplotlib>=3.3.0->paddle-quantum) (3.0.9)\n", + "Requirement already satisfied: python-dateutil>=2.7 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from matplotlib>=3.3.0->paddle-quantum) (2.8.2)\n", + "Requirement already satisfied: packaging>=20.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from matplotlib>=3.3.0->paddle-quantum) (21.3)\n", + "Requirement already satisfied: cycler>=0.10 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from matplotlib>=3.3.0->paddle-quantum) (0.11.0)\n", + "Requirement already satisfied: numpy>=1.17 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from matplotlib>=3.3.0->paddle-quantum) (1.21.3)\n", + "Requirement already satisfied: fonttools>=4.22.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from matplotlib>=3.3.0->paddle-quantum) (4.38.0)\n", + "Requirement already satisfied: kiwisolver>=1.0.1 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from matplotlib>=3.3.0->paddle-quantum) (1.4.4)\n", + "Requirement already satisfied: paddle-bfloat==0.1.2 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddlepaddle<=2.3.0->paddle-quantum) (0.1.2)\n", + "Requirement already satisfied: astor in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddlepaddle<=2.3.0->paddle-quantum) (0.8.1)\n", + "Requirement already satisfied: requests>=2.20.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddlepaddle<=2.3.0->paddle-quantum) (2.28.0)\n", + "Requirement already satisfied: six in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddlepaddle<=2.3.0->paddle-quantum) (1.16.0)\n", + "Requirement already satisfied: decorator in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddlepaddle<=2.3.0->paddle-quantum) (5.1.1)\n", + "Requirement already satisfied: opt-einsum==3.3.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddlepaddle<=2.3.0->paddle-quantum) (3.3.0)\n", + "Requirement already satisfied: scs>=1.1.6 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from cvxpy->paddle-quantum) (3.2.2)\n", + "Requirement already satisfied: osqp>=0.4.1 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from cvxpy->paddle-quantum) (0.6.2.post5)\n", + "Requirement already satisfied: ecos>=2 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from cvxpy->paddle-quantum) (2.0.10)\n", + "Requirement already satisfied: cirq-google>=0.15.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from openfermion->paddle-quantum) (1.0.0)\n", + "Requirement already satisfied: sympy in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from openfermion->paddle-quantum) (1.10.1)\n", + "Requirement already satisfied: deprecation in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from openfermion->paddle-quantum) (2.1.0)\n", + "Requirement already satisfied: cirq-core>=0.15.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from openfermion->paddle-quantum) (1.0.0)\n", + "Requirement already satisfied: pubchempy in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from openfermion->paddle-quantum) (1.0.4)\n", + "Requirement already satisfied: h5py>=2.8 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from openfermion->paddle-quantum) (3.7.0)\n", + "Collecting scipy\n", + " Using cached https://mirrors.bfsu.edu.cn/pypi/web/packages/4c/4a/440cc9703938bbc86636ff6b9e17810f3d0f06e9b41891c5433dc4cd9091/scipy-1.1.0-cp37-cp37m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (16.7 MB)\n", + "Collecting qcompute\n", + " Using cached https://mirrors.bfsu.edu.cn/pypi/web/packages/f6/57/823a3f3e3fd6e327453c4d028751fee7292784e1f2447ae6b7c0f3cc6565/qcompute-2.0.6-py3-none-any.whl (172 kB)\n", + " Using cached https://mirrors.bfsu.edu.cn/pypi/web/packages/8e/03/0a64ec2b7e6395fa53688ad3e489163218c45f36f0c96b448e0279391538/qcompute-2.0.4-py3-none-any.whl (96 kB)\n", + "Requirement already satisfied: bidict in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from qcompute->paddle-quantum) (0.22.0)\n", + "Requirement already satisfied: pyprimes in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from qcompute->paddle-quantum) (0.1)\n", + "Requirement already satisfied: bce-python-sdk in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from qcompute->paddle-quantum) (0.8.73)\n", + "Requirement already satisfied: commonmark<0.10.0,>=0.9.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from rich->paddle-quantum) (0.9.1)\n", + "Requirement already satisfied: pygments<3.0.0,>=2.6.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from rich->paddle-quantum) (2.13.0)\n", + "Requirement already satisfied: typing-extensions<5.0,>=3.7.4 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from rich->paddle-quantum) (4.3.0)\n", + "Requirement already satisfied: joblib>=0.11 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from scikit-learn->paddle-quantum) (1.2.0)\n", + "Requirement already satisfied: threadpoolctl>=2.0.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from scikit-learn->paddle-quantum) (3.1.0)\n", + "Requirement already satisfied: backports.cached-property~=1.0.1 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from cirq-core>=0.15.0->openfermion->paddle-quantum) (1.0.2)\n", + "Requirement already satisfied: duet~=0.2.7 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from cirq-core>=0.15.0->openfermion->paddle-quantum) (0.2.7)\n", + "Requirement already satisfied: pandas in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from cirq-core>=0.15.0->openfermion->paddle-quantum) (1.3.5)\n", + "Requirement already satisfied: sortedcontainers~=2.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from cirq-core>=0.15.0->openfermion->paddle-quantum) (2.4.0)\n", + "Requirement already satisfied: google-api-core[grpc]<2.0.0dev,>=1.14.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from cirq-google>=0.15.0->openfermion->paddle-quantum) (1.33.2)\n", + "Requirement already satisfied: proto-plus>=1.20.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from cirq-google>=0.15.0->openfermion->paddle-quantum) (1.22.1)\n", + "Requirement already satisfied: qdldl in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from osqp>=0.4.1->cvxpy->paddle-quantum) (0.1.5.post2)\n", + "Requirement already satisfied: charset-normalizer~=2.0.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle<=2.3.0->paddle-quantum) (2.0.12)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle<=2.3.0->paddle-quantum) (2022.9.24)\n", + "Requirement already satisfied: idna<4,>=2.5 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle<=2.3.0->paddle-quantum) (3.4)\n", + "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle<=2.3.0->paddle-quantum) (1.26.12)\n", + "Requirement already satisfied: future>=0.6.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from bce-python-sdk->qcompute->paddle-quantum) (0.18.2)\n", + "Requirement already satisfied: pycryptodome>=3.8.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from bce-python-sdk->qcompute->paddle-quantum) (3.15.0)\n", + "Requirement already satisfied: mpmath>=0.19 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from sympy->openfermion->paddle-quantum) (1.2.1)\n", + "Collecting typing-extensions<5.0,>=3.7.4\n", + " Using cached https://mirrors.bfsu.edu.cn/pypi/web/packages/2e/35/6c4fff5ab443b57116cb1aad46421fb719bed2825664e8fe77d66d99bcbc/typing_extensions-3.10.0.0-py3-none-any.whl (26 kB)\n", + "Collecting protobuf<=3.20.1\n", + " Using cached https://mirrors.bfsu.edu.cn/pypi/web/packages/ea/fe/82cf68917308b208731487f986db209e56903c30e324499b6bf0cc6a6203/protobuf-3.19.6-cp37-cp37m-macosx_10_9_x86_64.whl (979 kB)\n", + "Requirement already satisfied: google-auth<3.0dev,>=1.25.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google>=0.15.0->openfermion->paddle-quantum) (2.14.1)\n", + "Requirement already satisfied: googleapis-common-protos<2.0dev,>=1.56.2 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google>=0.15.0->openfermion->paddle-quantum) (1.57.0)\n", + "Requirement already satisfied: grpcio<2.0dev,>=1.33.2 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google>=0.15.0->openfermion->paddle-quantum) (1.50.0)\n", + "Requirement already satisfied: grpcio-status<2.0dev,>=1.33.2 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google>=0.15.0->openfermion->paddle-quantum) (1.48.2)\n", + "Requirement already satisfied: pytz>=2017.3 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from pandas->cirq-core>=0.15.0->openfermion->paddle-quantum) (2022.6)\n", + "Requirement already satisfied: pyasn1-modules>=0.2.1 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from google-auth<3.0dev,>=1.25.0->google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google>=0.15.0->openfermion->paddle-quantum) (0.2.8)\n", + "Requirement already satisfied: cachetools<6.0,>=2.0.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from google-auth<3.0dev,>=1.25.0->google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google>=0.15.0->openfermion->paddle-quantum) (5.2.0)\n", + "Requirement already satisfied: rsa<5,>=3.1.4 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from google-auth<3.0dev,>=1.25.0->google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google>=0.15.0->openfermion->paddle-quantum) (4.9)\n", + "Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from pyasn1-modules>=0.2.1->google-auth<3.0dev,>=1.25.0->google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google>=0.15.0->openfermion->paddle-quantum) (0.4.8)\n", + "Installing collected packages: typing-extensions, scipy, protobuf, qcompute\n", + " Attempting uninstall: typing-extensions\n", + " Found existing installation: typing_extensions 4.3.0\n", + " Uninstalling typing_extensions-4.3.0:\n", + " Successfully uninstalled typing_extensions-4.3.0\n", + " Attempting uninstall: scipy\n", + " Found existing installation: scipy 1.7.1\n", + " Uninstalling scipy-1.7.1:\n", + " Successfully uninstalled scipy-1.7.1\n", + " Attempting uninstall: protobuf\n", + " Found existing installation: protobuf 4.21.1\n", + " Uninstalling protobuf-4.21.1:\n", + " Successfully uninstalled protobuf-4.21.1\n", + " Attempting uninstall: qcompute\n", + " Found existing installation: qcompute 3.0.0\n", + " Uninstalling qcompute-3.0.0:\n", + " Successfully uninstalled qcompute-3.0.0\n", + "Successfully installed protobuf-3.19.6 qcompute-2.0.4 scipy-1.1.0 typing-extensions-3.10.0.0\n", + "Note: you may need to restart the kernel to use updated packages.\n", + "--2022-11-24 13:44:45-- https://release-data.cdn.bcebos.com/PaddleQuantum/vsql.pdparams\n", + "Resolving release-data.cdn.bcebos.com (release-data.cdn.bcebos.com)... 222.35.73.1\n", + "Connecting to release-data.cdn.bcebos.com (release-data.cdn.bcebos.com)|222.35.73.1|:443... connected.\n", + "HTTP request sent, awaiting response... 200 OK\n", + "Length: 857 [application/octet-stream]\n", + "Saving to: ‘vsql.pdparams.1’\n", + "\n", + "vsql.pdparams.1 100%[===================>] 857 --.-KB/s in 0s \n", + "\n", + "2022-11-24 13:44:46 (204 MB/s) - ‘vsql.pdparams.1’ saved [857/857]\n", + "\n" + ] + } + ], + "source": [ + "# 安装量桨\n", + "%pip install paddle-quantum\n", + "# 下载预训练模型\n", + "!wget https://release-data.cdn.bcebos.com/PaddleQuantum/vsql.pdparams" + ] + }, + { + "cell_type": "markdown", + "id": "f8a3ebf3", + "metadata": {}, + "source": [ + "接下来,可以加载模型并进行测试:" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "53a5f59a", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/scipy/linalg/__init__.py:212: DeprecationWarning: The module numpy.dual is deprecated. Instead of using dual, use the functions directly from numpy or scipy.\n", + " from numpy.dual import register_func\n", + "/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/scipy/sparse/sputils.py:16: DeprecationWarning: `np.typeDict` is a deprecated alias for `np.sctypeDict`.\n", + " supported_dtypes = [np.typeDict[x] for x in supported_dtypes]\n", + "/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/scipy/special/orthogonal.py:81: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.\n", + "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n", + " from numpy import (exp, inf, pi, sqrt, floor, sin, cos, around, int,\n", + "/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/scipy/io/matlab/mio5.py:98: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.\n", + "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n", + " from .mio5_utils import VarReader5\n" + ] + } + ], + "source": [ + "# 导入所需要的包\n", + "import os\n", + "import warnings\n", + "\n", + "warnings.filterwarnings('ignore')\n", + "os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'python'\n", + "\n", + "import numpy as np\n", + "import paddle\n", + "import paddle_quantum as pq\n", + "import matplotlib.pyplot as plt\n", + "from paddle_quantum.qml.vsql import VSQL\n", + "\n", + "# 设置模型参数\n", + "num_qubits = 10\n", + "num_shadow = 2\n", + "classes = [0, 1]\n", + "num_classes = len(classes)\n", + "depth = 1\n", + "\n", + "# 加载已训练的模型\n", + "model = VSQL(\n", + " num_qubits=num_qubits,\n", + " num_shadow=num_shadow,\n", + " num_classes=num_classes,\n", + " depth=depth,\n", + ")\n", + "state_dict = paddle.load('./vsql.pdparams')\n", + "model.set_state_dict(state_dict)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "8f54b4de", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "--2022-11-24 13:45:04-- https://ai-studio-static-online.cdn.bcebos.com/088dc9dbabf349c88d029dfd2e07827aa6e41ba958c5434bbd96bc167fc65347\n", + "Resolving ai-studio-static-online.cdn.bcebos.com (ai-studio-static-online.cdn.bcebos.com)... 222.35.73.1\n", + "Connecting to ai-studio-static-online.cdn.bcebos.com (ai-studio-static-online.cdn.bcebos.com)|222.35.73.1|:443... connected.\n", + "HTTP request sent, awaiting response... 200 OK\n", + "Length: 290 [image/png]\n", + "Saving to: ‘data-0.png’\n", + "\n", + "data-0.png 100%[===================>] 290 --.-KB/s in 0s \n", + "\n", + "2022-11-24 13:45:05 (277 MB/s) - ‘data-0.png’ saved [290/290]\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaAAAAGdCAYAAABU0qcqAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAb/0lEQVR4nO3df3DV9b3n8dcBksMPk0NDyK8SaECFChK3VNIMSrFkSNJ7uYBsF9R2wXFgoQlbpFY3HQVte29anFFHh8LevS3RqYDSFaiMpcVgwloTHBDKsq25JE0lDklQZjknBAkx+ewfrKc9kojfwzl5J+H5mPnOkHO+n3zffjnjky/n8I3POecEAEAfG2I9AADg+kSAAAAmCBAAwAQBAgCYIEAAABMECABgggABAEwQIACAiWHWA3xad3e3Tp8+raSkJPl8PutxAAAeOefU1tamrKwsDRnS+3VOvwvQ6dOnlZ2dbT0GAOAaNTU1ady4cb0+3+8ClJSUJEm6Q9/UMCUYTwMA8OpjdepNvRb+/3lv4hagTZs26cknn1RLS4tyc3P13HPPaebMmVdd98lfuw1Tgob5CBAADDj//w6jV3sbJS4fQnjppZe0bt06bdiwQe+8845yc3NVWFioM2fOxONwAIABKC4Beuqpp7RixQrdf//9uuWWW7RlyxaNHDlSv/zlL+NxOADAABTzAF26dElHjhxRQUHB3w4yZIgKCgpUU1Nzxf4dHR0KhUIRGwBg8It5gD788EN1dXUpPT094vH09HS1tLRcsX95ebkCgUB44xNwAHB9MP+HqGVlZQoGg+GtqanJeiQAQB+I+afgUlNTNXToULW2tkY83traqoyMjCv29/v98vv9sR4DANDPxfwKKDExUTNmzFBlZWX4se7ublVWVio/Pz/WhwMADFBx+XdA69at07Jly/TVr35VM2fO1DPPPKP29nbdf//98TgcAGAAikuAlixZog8++EDr169XS0uLbrvtNu3bt++KDyYAAK5fPuecsx7i74VCIQUCAc3RAu6EAAAD0MeuU1Xao2AwqOTk5F73M/8UHADg+kSAAAAmCBAAwAQBAgCYIEAAABMECABgggABAEwQIACACQIEADBBgAAAJggQAMAEAQIAmCBAAAATBAgAYIIAAQBMECAAgAkCBAAwQYAAACYIEADABAECAJggQAAAEwQIAGCCAAEATBAgAIAJAgQAMEGAAAAmCBAAwAQBAgCYIEAAABMECABgggABAEwQIACACQIEADBBgAAA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06dGlSvh6udh54cO3ZMkvrX68H6UxCfx44dO5zf73cVFRXuT3/6k1u5cqUbPXq0a2lpsR6tT33/+993VVVVrrGx0f3hD39wBQUFLjU11Z05c8Z6tLhqa2tzR48edUePHnWS3FNPPeWOHj3q3nvvPeeccz/96U/d6NGj3Z49e9zx48fdggULXE5Ojvvoo4+MJ4+tzzoPbW1t7qGHHnI1NTWusbHRvf766+4rX/mKu+mmm9zFixetR4+Z1atXu0Ag4Kqqqlxzc3N4u3DhQnifVatWufHjx7sDBw64w4cPu/z8fJefn284dexd7TzU19e7H/3oR+7w4cOusbHR7dmzx02cONHNnj3bePJIAyJAzjn33HPPufHjx7vExEQ3c+ZMV1tbaz1Sn1uyZInLzMx0iYmJ7otf/KJbsmSJq6+vtx4r7t544w0n6Ypt2bJlzrnLH8V+7LHHXHp6uvP7/W7u3Lmurq7Odug4+KzzcOHCBTdv3jw3duxYl5CQ4CZMmOBWrFgx6P6Q1tN/vyS3devW8D4fffSR++53v+u+8IUvuJEjR7pFixa55uZmu6Hj4Grn4dSpU2727NkuJSXF+f1+d+ONN7of/OAHLhgM2g7+Kfw4BgCAiX7/HhAAYHAiQAAAEwQIAGCCAAEATBAgAIAJAgQAMEGAAAAmCBAAwAQBAgCYIEAAABMECABgggABAEz8P6zGwHOCsnIFAAAAAElFTkSuQmCC", + "text/plain": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "# 加载手写数字0\n", + "!wget https://ai-studio-static-online.cdn.bcebos.com/088dc9dbabf349c88d029dfd2e07827aa6e41ba958c5434bbd96bc167fc65347 -O data-0.png\n", + "image0 = plt.imread('data-0.png')\n", + "plt.imshow(image0)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "40ebcb55", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "--2022-11-24 13:45:06-- https://ai-studio-static-online.cdn.bcebos.com/c755f723af3d4a1c8f113f8ac3bd365406decd1be70944b7b7b9d41413e8bc7a\n", + "Resolving ai-studio-static-online.cdn.bcebos.com (ai-studio-static-online.cdn.bcebos.com)... 222.35.73.1\n", + "Connecting to ai-studio-static-online.cdn.bcebos.com (ai-studio-static-online.cdn.bcebos.com)|222.35.73.1|:443... connected.\n", + "HTTP request sent, awaiting response... 200 OK\n", + "Length: 173 [image/png]\n", + "Saving to: ‘data-1.png’\n", + "\n", + "data-1.png 100%[===================>] 173 --.-KB/s in 0s \n", + "\n", + "2022-11-24 13:45:06 (165 MB/s) - ‘data-1.png’ saved [173/173]\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaAAAAGdCAYAAABU0qcqAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAaCElEQVR4nO3df2xU95nv8c8YzACJPa4x9njAUEMSaAO4WwquRUJI8QVcLcsvXUGSShAhENSkBZomcpVAaCu5JRKNErmgq5tCcxUgRQqwQVsqYrBRWpsIB0RRUwtbboGLbRp28RgTjMN89w820w7YocfM8HjM+yUdCc+cr+fJ6SlvDnM8+JxzTgAA3GMp1gMAAO5PBAgAYIIAAQBMECAAgAkCBAAwQYAAACYIEADABAECAJgYaD3ArSKRiC5cuKC0tDT5fD7rcQAAHjnn1N7erlAopJSUnq9z+lyALly4oLy8POsxAAB36dy5cxo5cmSPz/e5AKWlpUmSHtO3NVCpxtMAALz6TF36QP8R/f28JwkLUEVFhV599VW1tLSooKBAb7zxhqZOnXrHdZ//tdtApWqgjwABQNL5n08YvdPbKAm5CeGdd97R+vXrtXHjRn300UcqKCjQ7NmzdfHixUS8HAAgCSUkQFu2bNGKFSv07LPP6qtf/aq2bdumoUOH6le/+lUiXg4AkITiHqDr16+rrq5OxcXF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uNhlZWW5ixcvWo+WUO3t7e7EiRPuxIkTTpLbsmWLO3HihPvrX//qnHPuZz/7mcvIyHD79+93p06dcvPmzXP5+fnu008/NZ48vr7oOLS3t7vnn3/e1dTUuKamJvf++++7r3/96+7hhx92165dsx49blavXu0CgYCrqqpyzc3N0e3q1avRfVatWuVGjRrlDh8+7I4fP+6KiopcUVGR4dTxd6fj0NDQ4H784x+748ePu6amJrd//343ZswYN336dOPJYyVFgJxz7o033nCjRo1ygwYNclOnTnW1tbXWI91zixcvdrm5uW7QoEFuxIgRbvHixa6hocF6rIQ7cuSIk3TbtnTpUufczVuxX375ZZeTk+P8fr+bOXOmq6+vtx06Ab7oOFy9etXNmjXLDR8+3KWmprrRo0e7FStW9Ls/pHX33y/Jbd++PbrPp59+6r773e+6L33pS27o0KFuwYIFrrm52W7oBLjTcTh79qybPn26y8zMdH6/3z300EPuhz/8oWtra7Md/Bb8cwwAABN9/j0gAED/RIAAACYIEADABAECAJggQAAAEwQIAGCCAAEATBAgAIAJAgQAMEGAAAAmCBAAwAQBAgCY+G/lgUw3G3htogAAAABJRU5ErkJggg==", + "text/plain": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "# 加载手写数字1\n", + "!wget https://ai-studio-static-online.cdn.bcebos.com/c755f723af3d4a1c8f113f8ac3bd365406decd1be70944b7b7b9d41413e8bc7a -O data-1.png\n", + "image1 = plt.imread('data-1.png')\n", + "plt.imshow(image1)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "c4830c1a", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/paddle/tensor/creation.py:125: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. \n", + "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n", + " if data.dtype == np.object:\n", + "/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/paddle/fluid/framework.py:1104: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.\n", + "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n", + " elif dtype == np.bool:\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "对于手写数字 0,模型有 89.22% 的信心认为它是 0,有10.78%的信心认为它是 1。\n", + "对于手写数字 1,模型有 18.29% 的信心认为它是 0,有81.71%的信心认为它是 1。\n" + ] + } + ], + "source": [ + "# 将图片编码为量子态\n", + "test_data = [np.array(image0).flatten(), np.array(image1).flatten()]\n", + "test_data = [np.pad(datum, pad_width=(0, 2 ** num_qubits - datum.size)) for datum in test_data]\n", + "test_data = [paddle.to_tensor(datum / np.linalg.norm(datum), dtype=pq.get_dtype()) for datum in test_data]\n", + "# 使用模型进行预测并得到对应的概率值\n", + "test_output = model(test_data)\n", + "test_prob = paddle.nn.functional.softmax(test_output)\n", + "print(f\"对于手写数字 0,模型有 {test_prob[0][0].item():3.2%} 的信心认为它是 0,有{test_prob[0][1].item():3.2%}的信心认为它是 1。\")\n", + "print(f\"对于手写数字 1,模型有 {test_prob[1][0].item():3.2%} 的信心认为它是 0,有{test_prob[1][1].item():3.2%}的信心认为它是 1。\")" + ] + }, + { + "cell_type": "markdown", + "id": "8f6f3b91", + "metadata": {}, + "source": [ + "## 5. 注意事项\n", + "\n", + "我们提供的模型为二分类模型,仅可以用来分辨手写数字0和1。对于其它分类任务,需要重新进行训练。" + ] + }, + { + "cell_type": "markdown", + "id": "4857182b", + "metadata": {}, + "source": [ + "## 6. 相关论文以及引用信息\n", + "\n", + "```\n", + "@inproceedings{li2021vsql,\n", + " title={VSQL: Variational shadow quantum learning for classification},\n", + " author={Li, Guangxi and Song, Zhixin and Wang, Xin},\n", + " booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},\n", + " volume={35},\n", + " number={9},\n", + " pages={8357--8365},\n", + " year={2021}\n", + "}\n", + "```" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3.7.15 ('py37')", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.15" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false + }, + "vscode": { + "interpreter": { + "hash": "49b49097121cb1ab3a8a640b71467d7eda4aacc01fc9ff84d52fcb3bd4007bf1" + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/modelcenter/PQ-VSQL/introduction_en.ipynb b/modelcenter/PQ-VSQL/introduction_en.ipynb new file mode 100644 index 00000000..0953407c --- /dev/null +++ b/modelcenter/PQ-VSQL/introduction_en.ipynb @@ -0,0 +1,414 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "6f0a162f", + "metadata": {}, + "source": [ + "## 1. VSQL Introduction\n", + "\n", + "Variational Shadow Quantum Learning (VSQL) is a hybird quantum-classical framework for supervised quantum learning, which utilizes parameterized quantum circuits and classical shadows. Unlike commonly used variational quantum algorithms, the VSQL method extracts \"local\" features from the subspace instead of the whole Hilbert space." + ] + }, + { + "cell_type": "markdown", + "id": "99c07da5", + "metadata": {}, + "source": [ + "## 2. Introduction to the Model Principle\n", + "\n", + "The flow chart of VSQL is as follows.\n", + "\n", + "![pipeline](https://ai-studio-static-online.cdn.bcebos.com/2b806cc0405e425995df1786a5c5976196c5ca83697647d9ae70ac7cc0bf83c9 \"Flow chart of VSQL\")\n", + "
Flow chart of VSQL
\n", + "\n", + "The training steps are as below.\n", + "\n", + "1. Encode a classical data point $\\mathbf{x}^i$ into a quantum state $\\left|\\mathbf{x}^i\\right>$.\n", + "2. Prepare a parameterized local quantum circuit $U(\\mathbf{\\theta})$ and initialize its parameters $\\mathbf{\\theta}$.\n", + "3. Apply $U(\\mathbf{\\theta})$ on the first few qubits. Then, obtain a shadow feature via measuring a local observable, for instance, $X\\otimes X\\cdots \\otimes X$, on these qubits.\n", + "4. Sliding down $U(\\mathbf{\\theta})$ one qubit each time, repeat step 3 until the last qubit has been covered.\n", + "5. Feed all shadow features obtained from steps 3-4 to an FCNN and get the predicted label $\\tilde{\\mathbf{y}}^i$ through an activation function. For multi-label classification problems, we use the softmax activation function.\n", + "5. Repeat steps 3-5 until all data points in the data set have been processed. Then calculate the loss function $\\mathcal{L}(\\mathbf{\\theta}, \\mathbf{W}, \\mathbf{b})$.\n", + "6. Adjust the parameters $\\mathbf{\\theta}$, $\\mathbf{W}$, and $\\mathbf{b}$ through optimization methods such as gradient descent to minimize the loss function. Then we get the optimized model $\\mathcal{F}$.\n", + "\n", + "Since VSQL only extracts local shadow features, it can be easily implemented on quantum devices with topological connectivity limits. Besides, since the $U(\\mathbf{\\theta})$ used in circuits are identical, the number of parameters involved is significantly smaller than other commonly used variational quantum classifiers.\n", + "\n", + "### 2.1 Introduction to local shadow circuits\n", + "\n", + "Now, we are ready for the next step. Before diving into details of the circuit, we need to clarify several parameters:\n", + "- $n$: the number of qubits encoding each data point.\n", + "- $n_{qsc}$: the width of the quantum shadow circuit . We only apply $U(\\mathbf{\\theta})$ on consecutive $n_{qsc}$ qubits each time.\n", + "- $D$: the depth of the circuit, indicating the repeating times of a layer in $U(\\mathbf{\\theta})$.\n", + "\n", + "Here, we give an example where $n = 4$ and $n_{qsc} = 2$.\n", + "\n", + "We first apply $U(\\mathbf{\\theta})$ to the first two qubits and obtain the shadow feature $O_1$.\n", + "\n", + "![qubit0](https://ai-studio-static-online.cdn.bcebos.com/818b3c2bac5d4ef0b73e223c357b49d688649f036d7b4d798fb54838a555c6e6 \"The first circuit\")\n", + "
The first circuit
\n", + "\n", + "Then, we prepare a copy of the same input state $\\left|\\mathbf{x}^i\\right>$, apply $U(\\mathbf{\\theta})$ to the two qubits in the middle, and obtain the shadow feature $O_2$.\n", + "\n", + "![qubit1](https://ai-studio-static-online.cdn.bcebos.com/b58591c4adfc4d18a657cf1b811f4fc0c6dced8fd6b54724a78fbe1c86bb32dc \"The second circuit\")\n", + "
The second circuit
\n", + "\n", + "Finally, we prepare another copy of the same input state, apply $U(\\mathbf{\\theta})$ to the last two qubits, and obtain the shadow feature $O_3$. Now we are done with this data point!\n", + "\n", + "![qubit2](https://ai-studio-static-online.cdn.bcebos.com/57089cc1c0dd412ba984a0b12e20f5d88585aaa4d293455aa9f6bb7869d7f771 \"The last circuit\")\n", + "
The last circuit
\n", + "\n", + "In general, we will need to repeat this process for $n - n_{qsc} + 1$ times for each data point. One thing to point out is that we only use one shadow circuit in the above example. When sliding the shadow circuit $U(\\mathbf{\\theta})$ through the $n$-qubit Hilbert space, the same parameters $\\mathbf{\\theta}$ are used. You can use more shadow circuits for complicated tasks, and different shadow circuits should have different parameters $\\mathbf{\\theta}$.\n", + "\n", + "Below, we will use a 2-local shadow circuit, i.e., $n_{qsc}=2$ for the MNIST classification task, and the circuit's structure is shown in the follow figure.\n", + "\n", + "![2-local](https://ai-studio-static-online.cdn.bcebos.com/0c1035262cb64f61bd3cc87dbf53253aa6a7ecc170634c4db8dd71d576a9409c \"The 2-local shadow circuit design\")\n", + "
The 2-local shadow circuit design
\n", + "\n", + "The circuit layer in the dashed box is repeated for $D$ times to increase the expressive power of the quantum circuit. The structure of the circuit is not unique. You can try to design your own circuit." + ] + }, + { + "cell_type": "markdown", + "id": "bbec4432", + "metadata": {}, + "source": [ + "## 3. Model Performance\n", + "\n", + "The binary classification effect of VSQL on MNIST dataset is as follows.\n", + "\n", + "![binary-classification](https://ai-studio-static-online.cdn.bcebos.com/03c38b174d0e47ae9dbeea6dfda1333d6d3aa74209594324b78c9159b72e7e8a \"Binary classification performance\")\n", + "
Binary classification performance
\n", + "\n", + "The ten-class classification effect of VSQL on the MNIST dataset is as follows.\n", + "\n", + "![10-classification](https://ai-studio-static-online.cdn.bcebos.com/54a0273672ad4ec5ba6b7d73b3b225f8d97380c43ceb495a82d16a258117182b \"Ten-class classification performance\")\n", + "
Ten-class classification performance
\n", + "\n", + "As shown in the tables, VSQL can achieve higher classification accuracy with fewer parameters than other quantum neural networks. Compared with classical neural networks, VSQL can also achieve similar results in ten-class classification tasks with fewer parameters. And when the amount of data is small, VSQL can achieve better results than classical neural networks." + ] + }, + { + "cell_type": "markdown", + "id": "0af2eccc", + "metadata": {}, + "source": [ + "## 4. How to Use the Model\n", + "\n", + "Configure the environment according to the following code." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "77177110", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "--2022-11-24 13:45:54-- https://release-data.cdn.bcebos.com/PaddleQuantum/vsql.pdparams\n", + "Resolving release-data.cdn.bcebos.com (release-data.cdn.bcebos.com)... 222.35.73.1\n", + "Connecting to release-data.cdn.bcebos.com (release-data.cdn.bcebos.com)|222.35.73.1|:443... connected.\n", + "HTTP request sent, awaiting response... 200 OK\n", + "Length: 857 [application/octet-stream]\n", + "Saving to: ‘vsql.pdparams.2’\n", + "\n", + "vsql.pdparams.2 100%[===================>] 857 --.-KB/s in 0s \n", + "\n", + "2022-11-24 13:45:54 (817 MB/s) - ‘vsql.pdparams.2’ saved [857/857]\n", + "\n" + ] + } + ], + "source": [ + "# Install the paddle quantum\n", + "%pip install paddle-quantum\n", + "# Download the pretrained model\n", + "!wget https://release-data.cdn.bcebos.com/PaddleQuantum/vsql.pdparams" + ] + }, + { + "cell_type": "markdown", + "id": "4843c62f", + "metadata": {}, + "source": [ + "Next, the model can be loaded and tested." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "86d4405c", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/scipy/linalg/__init__.py:212: DeprecationWarning: The module numpy.dual is deprecated. Instead of using dual, use the functions directly from numpy or scipy.\n", + " from numpy.dual import register_func\n", + "/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/scipy/sparse/sputils.py:16: DeprecationWarning: `np.typeDict` is a deprecated alias for `np.sctypeDict`.\n", + " supported_dtypes = [np.typeDict[x] for x in supported_dtypes]\n", + "/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/scipy/special/orthogonal.py:81: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.\n", + "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n", + " from numpy import (exp, inf, pi, sqrt, floor, sin, cos, around, int,\n", + "/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/scipy/io/matlab/mio5.py:98: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.\n", + "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n", + " from .mio5_utils import VarReader5\n" + ] + } + ], + "source": [ + "# Import the required packages\n", + "import os\n", + "import warnings\n", + "\n", + "warnings.filterwarnings('ignore')\n", + "os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'python'\n", + "\n", + "import numpy as np\n", + "import paddle\n", + "import paddle_quantum as pq\n", + "import matplotlib.pyplot as plt\n", + "from paddle_quantum.qml.vsql import VSQL\n", + "\n", + "# Set model parameters\n", + "num_qubits = 10\n", + "num_shadow = 2\n", + "classes = [0, 1]\n", + "num_classes = len(classes)\n", + "depth = 1\n", + "\n", + "# Load the trained model\n", + "model = VSQL(\n", + " num_qubits=num_qubits,\n", + " num_shadow=num_shadow,\n", + " num_classes=num_classes,\n", + " depth=depth,\n", + ")\n", + "state_dict = paddle.load('./vsql.pdparams')\n", + "model.set_state_dict(state_dict)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "6676b204", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "--2022-11-24 13:46:01-- https://ai-studio-static-online.cdn.bcebos.com/088dc9dbabf349c88d029dfd2e07827aa6e41ba958c5434bbd96bc167fc65347\n", + "Resolving ai-studio-static-online.cdn.bcebos.com (ai-studio-static-online.cdn.bcebos.com)... 222.35.73.1\n", + "Connecting to ai-studio-static-online.cdn.bcebos.com (ai-studio-static-online.cdn.bcebos.com)|222.35.73.1|:443... connected.\n", + "HTTP request sent, awaiting response... 200 OK\n", + "Length: 290 [image/png]\n", + "Saving to: ‘data-0.png’\n", + "\n", + "data-0.png 100%[===================>] 290 --.-KB/s in 0s \n", + "\n", + "2022-11-24 13:46:02 (138 MB/s) - ‘data-0.png’ saved [290/290]\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaAAAAGdCAYAAABU0qcqAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAb/0lEQVR4nO3df3DV9b3n8dcBksMPk0NDyK8SaECFChK3VNIMSrFkSNJ7uYBsF9R2wXFgoQlbpFY3HQVte29anFFHh8LevS3RqYDSFaiMpcVgwloTHBDKsq25JE0lDklQZjknBAkx+ewfrKc9kojfwzl5J+H5mPnOkHO+n3zffjnjky/n8I3POecEAEAfG2I9AADg+kSAAAAmCBAAwAQBAgCYIEAAABMECABgggABAEwQIACAiWHWA3xad3e3Tp8+raSkJPl8PutxAAAeOefU1tamrKwsDRnS+3VOvwvQ6dOnlZ2dbT0GAOAaNTU1ady4cb0+3+8ClJSUJEm6Q9/UMCUYTwMA8OpjdepNvRb+/3lv4hagTZs26cknn1RLS4tyc3P13HPPaebMmVdd98lfuw1Tgob5CBAADDj//w6jV3sbJS4fQnjppZe0bt06bdiwQe+8845yc3NVWFioM2fOxONwAIABKC4Beuqpp7RixQrdf//9uuWWW7RlyxaNHDlSv/zlL+NxOADAABTzAF26dElHjhxRQUHB3w4yZIgKCgpUU1Nzxf4dHR0KhUIRGwBg8It5gD788EN1dXUpPT094vH09HS1tLRcsX95ebkCgUB44xNwAHB9MP+HqGVlZQoGg+GtqanJeiQAQB+I+afgUlNTNXToULW2tkY83traqoyMjCv29/v98vv9sR4DANDPxfwKKDExUTNmzFBlZWX4se7ublVWVio/Pz/WhwMADFBx+XdA69at07Jly/TVr35VM2fO1DPPPKP29nbdf//98TgcAGAAikuAlixZog8++EDr169XS0uLbrvtNu3bt++KDyYAAK5fPuecsx7i74VCIQUCAc3RAu6EAAAD0MeuU1Xao2AwqOTk5F73M/8UHADg+kSAAAAmCBAAwAQBAgCYIEAAABMECABgggABAEwQIACACQIEADBBgAAAJggQAMAEAQIAmCBAAAATBAgAYIIAAQBMECAAgAkCBAAwQYAAACYIEADABAECAJggQAAAEwQIAGCCAAEATBAgAIAJAgQAMEGAAAAmCBAAwAQBAgCYIEAAABMECABgggABAEwQIACACQIEADBBgAAAJggQAMAEAQIAmCBAAAATBAgAYIIAAQBMECAAgAkCBAAwQYAAACYIEADABAECAJggQAAAEwQIAGCCAAEATBAgAIAJAgQAMEGAAAAmCBAAwAQBAgCYGGY9AK4vQ6dO9rzmtf0veV7T5bo9r5GkoT7vfyaL9lh9YeoflkW17lLzKM9rRr/r87xm7JZaz2vknP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4+tzzoPbW1t7qGHHnI1NTWusbHRvf766+4rX/mKu+mmm9zFixetR4+Z1atXu0Ag4Kqqqlxzc3N4u3DhQnifVatWufHjx7sDBw64w4cPu/z8fJefn284dexd7TzU19e7H/3oR+7w4cOusbHR7dmzx02cONHNnj3bePJIAyJAzjn33HPPufHjx7vExEQ3c+ZMV1tbaz1Sn1uyZInLzMx0iYmJ7otf/KJbsmSJq6+vtx4r7t544w0n6Ypt2bJlzrnLH8V+7LHHXHp6uvP7/W7u3Lmurq7Odug4+KzzcOHCBTdv3jw3duxYl5CQ4CZMmOBWrFgx6P6Q1tN/vyS3devW8D4fffSR++53v+u+8IUvuJEjR7pFixa55uZmu6Hj4Grn4dSpU2727NkuJSXF+f1+d+ONN7of/OAHLhgM2g7+Kfw4BgCAiX7/HhAAYHAiQAAAEwQIAGCCAAEATBAgAIAJAgQAMEGAAAAmCBAAwAQBAgCYIEAAABMECABgggABAEz8P6zGwHOCsnIFAAAAAElFTkSuQmCC", + "text/plain": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "# Load handwritten digit 0\n", + "!wget https://ai-studio-static-online.cdn.bcebos.com/088dc9dbabf349c88d029dfd2e07827aa6e41ba958c5434bbd96bc167fc65347 -O data-0.png\n", + "image0 = plt.imread('data-0.png')\n", + "plt.imshow(image0)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "f637d0ca", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "--2022-11-24 13:46:03-- https://ai-studio-static-online.cdn.bcebos.com/c755f723af3d4a1c8f113f8ac3bd365406decd1be70944b7b7b9d41413e8bc7a\n", + "Resolving ai-studio-static-online.cdn.bcebos.com (ai-studio-static-online.cdn.bcebos.com)... 222.35.73.1\n", + "Connecting to ai-studio-static-online.cdn.bcebos.com (ai-studio-static-online.cdn.bcebos.com)|222.35.73.1|:443... connected.\n", + "HTTP request sent, awaiting response... 200 OK\n", + "Length: 173 [image/png]\n", + "Saving to: ‘data-1.png’\n", + "\n", + "data-1.png 100%[===================>] 173 --.-KB/s in 0s \n", + "\n", + "2022-11-24 13:46:03 (165 MB/s) - ‘data-1.png’ saved [173/173]\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaAAAAGdCAYAAABU0qcqAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAaCElEQVR4nO3df2xU95nv8c8YzACJPa4x9njAUEMSaAO4WwquRUJI8QVcLcsvXUGSShAhENSkBZomcpVAaCu5JRKNErmgq5tCcxUgRQqwQVsqYrBRWpsIB0RRUwtbboGLbRp28RgTjMN89w820w7YocfM8HjM+yUdCc+cr+fJ6SlvDnM8+JxzTgAA3GMp1gMAAO5PBAgAYIIAAQBMECAAgAkCBAAwQYAAACYIEADABAECAJgYaD3ArSKRiC5cuKC0tDT5fD7rcQAAHjnn1N7erlAopJSUnq9z+lyALly4oLy8POsxAAB36dy5cxo5cmSPz/e5AKWlpUmSHtO3NVCpxtMAALz6TF36QP8R/f28JwkLUEVFhV599VW1tLSooKBAb7zxhqZOnXrHdZ//tdtApWqgjwABQNL5n08YvdPbKAm5CeGdd97R+vXrtXHjRn300UcqKCjQ7NmzdfHixUS8HAAgCSUkQFu2bNGKFSv07LPP6qtf/aq2bdumoUOH6le/+lUiXg4AkITiHqDr16+rrq5OxcXFf3+RlBQVFxerpqbmtv07OzsVDodjNgBA/xf3AH3yySe6ceOGcnJyYh7PyclRS0vLbfuXl5crEAhEN+6AA4D7g/kPopaVlamtrS26nTt3znokAMA9EPe74LKysjRgwAC1trbGPN7a2qpgMHjb/n6/X36/P95jAAD6uLhfAQ0aNEiTJ09WZWVl9LFIJKLKyko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4fP+6KiopcUVGR4dTxd6fj0NDQ4H784x+748ePu6amJrd//343ZswYN336dOPJYyVFgJxz7o033nCjRo1ygwYNclOnTnW1tbXWI91zixcvdrm5uW7QoEFuxIgRbvHixa6hocF6rIQ7cuSIk3TbtnTpUufczVuxX375ZZeTk+P8fr+bOXOmq6+vtx06Ab7oOFy9etXNmjXLDR8+3KWmprrRo0e7FStW9Ls/pHX33y/Jbd++PbrPp59+6r773e+6L33pS27o0KFuwYIFrrm52W7oBLjTcTh79qybPn26y8zMdH6/3z300EPuhz/8oWtra7Md/Bb8cwwAABN9/j0gAED/RIAAACYIEADABAECAJggQAAAEwQIAGCCAAEATBAgAIAJAgQAMEGAAAAmCBAAwAQBAgCY+G/lgUw3G3htogAAAABJRU5ErkJggg==", + "text/plain": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "# Load handwritten digit 1\n", + "!wget https://ai-studio-static-online.cdn.bcebos.com/c755f723af3d4a1c8f113f8ac3bd365406decd1be70944b7b7b9d41413e8bc7a -O data-1.png\n", + "image1 = plt.imread('data-1.png')\n", + "plt.imshow(image1)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "e40d847a", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/paddle/tensor/creation.py:125: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. \n", + "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n", + " if data.dtype == np.object:\n", + "/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/paddle/fluid/framework.py:1104: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.\n", + "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n", + " elif dtype == np.bool:\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "For handwritten digits 0, the model has 89.22% confidence that it is 0 and 10.78% confidence that it is 1.\n", + "For handwritten digits 1, the model has 18.29% confidence that it is 0 and 81.71% confidence that it is 1.\n" + ] + } + ], + "source": [ + "# Encoding images into quantum states\n", + "test_data = [np.array(image0).flatten(), np.array(image1).flatten()]\n", + "test_data = [np.pad(datum, pad_width=(0, 2 ** num_qubits - datum.size)) for datum in test_data]\n", + "test_data = [paddle.to_tensor(datum / np.linalg.norm(datum), dtype=pq.get_dtype()) for datum in test_data]\n", + "# Use the model to make predictions and get the corresponding probability\n", + "test_output = model(test_data)\n", + "test_prob = paddle.nn.functional.softmax(test_output)\n", + "print(\n", + " f\"For handwritten digits 0, \"\n", + " f\"the model has {test_prob[0][0].item():3.2%} confidence that it is 0 \"\n", + " f\"and {test_prob[0][1].item():3.2%} confidence that it is 1.\"\n", + ")\n", + "print(\n", + " f\"For handwritten digits 1, \"\n", + " f\"the model has {test_prob[1][0].item():3.2%} confidence that it is 0 \"\n", + " f\"and {test_prob[1][1].item():3.2%} confidence that it is 1.\"\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "3990efae", + "metadata": {}, + "source": [ + "## 5. Note\n", + "\n", + "The model we provide is a binary classification model that can only be used to distinguish handwritten digits 0 and 1. For other classification tasks, it needs to be retrained." + ] + }, + { + "cell_type": "markdown", + "id": "4fe699ea", + "metadata": {}, + "source": [ + "## 6. Related papers and citations\n", + "\n", + "```\n", + "@inproceedings{li2021vsql,\n", + " title={VSQL: Variational shadow quantum learning for classification},\n", + " author={Li, Guangxi and Song, Zhixin and Wang, Xin},\n", + " booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},\n", + " volume={35},\n", + " number={9},\n", + " pages={8357--8365},\n", + " year={2021}\n", + "}\n", + "```" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3.7.15 ('py37')", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.15" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false + }, + "vscode": { + "interpreter": { + "hash": "49b49097121cb1ab3a8a640b71467d7eda4aacc01fc9ff84d52fcb3bd4007bf1" + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/modelcenter/VIMER-CAE/info.yaml b/modelcenter/VIMER-CAE/info.yaml index 3d41c19e..8985df3a 100644 --- a/modelcenter/VIMER-CAE/info.yaml +++ b/modelcenter/VIMER-CAE/info.yaml @@ -17,4 +17,4 @@ Paper: - title: "Context Autoencoder for Self-Supervised Representation Learning" url: "https://arxiv.org/abs/2202.03026" IfTraining: 0 -IfOnlineDemo: 1 \ No newline at end of file +IfOnlineDemo: 0 \ No newline at end of file diff --git a/modelcenter/VIMER-StrucTexT/info.yaml b/modelcenter/VIMER-StrucTexT/info.yaml index a0a24da2..b4d4de65 100644 --- a/modelcenter/VIMER-StrucTexT/info.yaml +++ b/modelcenter/VIMER-StrucTexT/info.yaml @@ -17,4 +17,4 @@ Paper: - title: "Structured Text Understanding with Multi-Modal Transformers" url: "https://arxiv.org/pdf/2108.02923.pdf" IfTraining: 0 -IfOnlineDemo: 1 \ No newline at end of file +IfOnlineDemo: 0 \ No newline at end of file diff --git a/modelcenter/VIMER-UFO/info.yaml b/modelcenter/VIMER-UFO/info.yaml index da5ef612..c863f318 100644 --- a/modelcenter/VIMER-UFO/info.yaml +++ b/modelcenter/VIMER-UFO/info.yaml @@ -17,4 +17,4 @@ Paper: - title: "UFO:Unified Feature Optimization" url: "https://arxiv.org/pdf/2207.10341v1.pdf" IfTraining: 0 -IfOnlineDemo: 1 +IfOnlineDemo: 0 -- GitLab