{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "## 1. ERNIE-ViLG模型简介\n", "\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", "\n", "## 3. 模型快速使用\n", "### 接口说明\n", "\n", "ERNIE-ViLG跨模态文生图:基于文心ERNIE-ViLG大模型,根据用户输入的文本,自动创作图像。\n", "\n", "* 温馨提示:\n", "\n", "每个账户每日免费请求ERNIE-ViLG API服务的上限为100条输入,免费请求额度共500条输入。如需提额,请在[合作咨询](https://wenxin.baidu.com/wenxin/apply)的需求描述里填写您的购买需求。\n", "\n", "### 获取API Key\n", "\n", "您可以登录大模型开放API获取您的专属获取您的专属 API Key(AK)和Secret Key(SK),点击[链接](https://wenxin.baidu.com/moduleApi/key)查看您的AK和SK。请注意保护您的密钥信息,避免泄露。您可以通过删除已泄露的密钥来保护您的账户安全。\n", "\n", "![image.png](https://bce.bdstatic.com/doc/AIDP/wenxin/image_9f4929b.png)\n", "\n", "### 调用方式\n", "\n", "#### 在本地Python环境调用接口 " ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# 安装wenxin-api工具包\n", "# 注意:建议python版本在python 3.7及以上版本\n", "!pip install --upgrade wenxin-api" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "* 如何调用" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# -*- coding: utf-8 -*\n", "import wenxin_api # 可以通过\"pip install wenxin-api\"命令安装\n", "from wenxin_api.tasks.text_to_image import TextToImage\n", "wenxin_api.ak = \"your_ak\"\n", "wenxin_api.sk = \"your_sk\"\n", "input_dict = {\n", " \"text\": \"睡莲\",\n", " \"style\": \"油画\"\n", "}\n", "rst = TextToImage.create(**input_dict)\n", "print(rst)" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "* 等待过程返回信息\n", "```python\n", "2022-08-12 02:23:15,488 - model is painting now!, taskId: 1023101, waiting: 2m\n", "2022-08-12 02:23:35,641 - model is painting now!, taskId: 1023101, waiting: 1m\n", "2022-08-12 02:23:55,982 - model is painting now!, taskId: 1023101, waiting: 1m\n", "```\n", "\n", "* 返回结果示例\n", "\n", "```python\n", "{\n", " \"imgUrls\":[\n", " \"https://wenxin.baidu.com/younger/file/ERNIE-ViLG/61157afdaef4f0dfef0d5e51459160fbex\",\n", " \"https://wenxin.baidu.com/younger/file/ERNIE-ViLG/61157afdaef4f0dfef0d5e51459160fbi4\",\n", " \"https://wenxin.baidu.com/younger/file/ERNIE-ViLG/61157afdaef4f0dfef0d5e51459160fb5q\",\n", " \"https://wenxin.baidu.com/younger/file/ERNIE-ViLG/61157afdaef4f0dfef0d5e51459160fb30\",\n", " \"https://wenxin.baidu.com/younger/file/ERNIE-ViLG/61157afdaef4f0dfef0d5e51459160fbv9\",\n", " \"https://wenxin.baidu.com/younger/file/ERNIE-ViLG/61157afdaef4f0dfef0d5e51459160fba2\",\n", " \"https://wenxin.baidu.com/younger/file/ERNIE-ViLG/61157afdaef4f0dfef0d5e51459160fbbf\",\n", " \"https://wenxin.baidu.com/younger/file/ERNIE-ViLG/61157afdaef4f0dfef0d5e51459160fbms\",\n", " \"https://wenxin.baidu.com/younger/file/ERNIE-ViLG/61157afdaef4f0dfef0d5e51459160fbu7\",\n", " \"https://wenxin.baidu.com/younger/file/ERNIE-ViLG/61157afdaef4f0dfef0d5e51459160fbct\"\n", " ]\n", "}\n", "```" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "\n", "\n", "## 4. 模型效果\n", "以下是ERNIE ViLG生成图片效果\n", "\n", "prompt:震撼的科幻插图,神秘宇宙背景,一只巨大的星球, 大场景,超高清,未来主义\n", "![](https://ai-studio-static-online.cdn.bcebos.com/aafe6e178a0e471c87a66bbe12ad86df24c5a7df607e4dc79b9a579ef7b2f61e)\n", "\n", "prompt:二次元 少女 梦幻 长袍 冰霜 帅气 画师krenz,二次元\n", "![](https://ai-studio-static-online.cdn.bcebos.com/c5a289eb93084d709b7fcf5f88202d5e4dc6f64b17c245d9a6232824ee44f2de)\n", "\n", "prompt:浮世绘日本科幻幻想哑光绘画,动漫风格神道寺禅园英雄动作序列,包豪斯,概念艺术\n", "![](https://ai-studio-static-online.cdn.bcebos.com/7da123c7c1d24cefab9304f35cebb5d4bf22b63e85b5427cb3f8f08df74acd94)\n", "\n", "## 5. 使用方案\n", "\n", "\n", "#### 通过飞桨旸谷社区在线体验\n", "\n", "通过飞桨旸谷社区在线体验 ERNIE-ViLG的文生图能力。\n", "\n", "#### 通过 API 调用体验\n", "\n", "ERNIE-ViLG 提供API体验调用的入口,您也可以在飞桨旸谷社区 API 体验专区申请 AK、SK 进行接口调用体验。" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "py35-paddle1.2.0" }, "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.4" } }, "nbformat": 4, "nbformat_minor": 1 }