Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
755425ce
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
1 年多 前同步成功
通知
283
Star
12117
Fork
2091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
200
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleHub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
200
Issue
200
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
755425ce
编写于
11月 04, 2022
作者:
jm_12138
提交者:
GitHub
11月 04, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update ernie_vilg (#2098)
* remove resolution parameter * update README
上级
fbd18e99
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
35 addition
and
22 deletion
+35
-22
modules/image/text_to_image/ernie_vilg/README.md
modules/image/text_to_image/ernie_vilg/README.md
+6
-3
modules/image/text_to_image/ernie_vilg/module.py
modules/image/text_to_image/ernie_vilg/module.py
+3
-19
modules/image/text_to_image/ernie_vilg/test.py
modules/image/text_to_image/ernie_vilg/test.py
+26
-0
未找到文件。
modules/image/text_to_image/ernie_vilg/README.md
浏览文件 @
755425ce
...
...
@@ -79,7 +79,6 @@
def generate_image(
text_prompts:str,
style: Optional[str] = "探索无限",
resolution: Optional[str] = "1024*1024",
topk: Optional[int] = 6,
output_dir: Optional[str] = 'ernievilg_output')
```
...
...
@@ -91,7 +90,6 @@
- text_prompts(str): 输入的语句,描述想要生成的图像的内容。
- style(Optional[str]): 生成图像的风格,当前支持 古风、油画、水彩、卡通、二次元、浮世绘、蒸汽波艺术、
low poly、像素风格、概念艺术、未来主义、赛博朋克、写实风格、洛丽塔风格、巴洛克风格、超现实主义、探索无限。
- resolution(Optional[str]): 生成图像的分辨率,当前支持 '1024\*1024', '1024\*1536', '1536\*1024',默认为'1024\*1024'。
- topk(Optional[int]): 保存前多少张图,最多保存6张。
- output_dir(Optional[str]): 保存输出图像的目录,默认为"ernievilg_output"。
...
...
@@ -389,6 +387,11 @@ DiscoDiffusion Prompt 技巧资料:https://docs.google.com/document/d/1l8s7uS2
* 1.1.0
增加分辨率参数以及所支持的风格
* 1.2.0
移除分辨率参数
```
shell
$ hub install ernie_vilg == 1.
1
.0
$ hub install ernie_vilg == 1.
2
.0
```
modules/image/text_to_image/ernie_vilg/module.py
浏览文件 @
755425ce
import
argparse
import
ast
import
base64
import
os
import
re
import
sys
import
time
from
functools
import
partial
from
io
import
BytesIO
from
typing
import
List
from
typing
import
Optional
import
requests
from
PIL
import
Image
from
tqdm.auto
import
tqdm
import
paddlehub
as
hub
from
paddlehub.module.module
import
moduleinfo
from
paddlehub.module.module
import
runnable
from
paddlehub.module.module
import
serving
@
moduleinfo
(
name
=
"ernie_vilg"
,
version
=
"1.
1
.0"
,
version
=
"1.
2
.0"
,
type
=
"image/text_to_image"
,
summary
=
""
,
author
=
"baidu-nlp"
,
...
...
@@ -65,7 +59,6 @@ class ErnieVilG:
def
generate_image
(
self
,
text_prompts
,
style
:
Optional
[
str
]
=
"探索无限"
,
resolution
:
Optional
[
str
]
=
"1024*1024"
,
topk
:
Optional
[
int
]
=
6
,
visualization
:
Optional
[
bool
]
=
True
,
output_dir
:
Optional
[
str
]
=
'ernievilg_output'
):
...
...
@@ -75,7 +68,6 @@ class ErnieVilG:
:param text_prompts: Phrase, sentence, or string of words and phrases describing what the image should look like.
:param style: Image stype, currently supported 古风、油画、水彩、卡通、二次元、浮世绘、蒸汽波艺术、
low poly、像素风格、概念艺术、未来主义、赛博朋克、写实风格、洛丽塔风格、巴洛克风格、超现实主义、探索无限。
:param resolution: Resolution of images, currently supported "1024*1024", "1024*1536", "1536*1024".
:param topk: Top k images to save.
:param visualization: Whether to save images or not.
:output_dir: Output directory
...
...
@@ -94,8 +86,7 @@ class ErnieVilG:
data
=
{
'access_token'
:
token
,
"text"
:
text_prompt
,
"style"
:
style
,
"resolution"
:
resolution
"style"
:
style
})
res
=
res
.
json
()
if
res
[
'code'
]
==
4001
:
...
...
@@ -117,8 +108,7 @@ class ErnieVilG:
data
=
{
'access_token'
:
token
,
"text"
:
text_prompt
,
"style"
:
style
,
"resolution"
:
resolution
"style"
:
style
})
res
=
res
.
json
()
if
res
[
'code'
]
!=
0
:
...
...
@@ -242,7 +232,6 @@ class ErnieVilG:
self
.
token
=
self
.
_apply_token
(
self
.
ak
,
self
.
sk
)
results
=
self
.
generate_image
(
text_prompts
=
args
.
text_prompts
,
style
=
args
.
style
,
resolution
=
args
.
resolution
,
topk
=
args
.
topk
,
visualization
=
args
.
visualization
,
output_dir
=
args
.
output_dir
)
...
...
@@ -275,11 +264,6 @@ class ErnieVilG:
'未来主义'
,
'赛博朋克'
,
'写实风格'
,
'洛丽塔风格'
,
'巴洛克风格'
,
'超现实主义'
,
'探索无限'
],
help
=
"绘画风格"
)
self
.
arg_input_group
.
add_argument
(
'--resolution'
,
type
=
str
,
default
=
'1024*1024'
,
choices
=
[
'1024*1024'
,
'1024*1536'
,
'1536*1024'
],
help
=
"图像分辨率"
)
self
.
arg_input_group
.
add_argument
(
'--topk'
,
type
=
int
,
default
=
6
,
help
=
"选取保存前多少张图,最多10张"
)
self
.
arg_input_group
.
add_argument
(
'--ak'
,
type
=
str
,
default
=
None
,
help
=
"申请文心api使用token的ak"
)
self
.
arg_input_group
.
add_argument
(
'--sk'
,
type
=
str
,
default
=
None
,
help
=
"申请文心api使用token的sk"
)
...
...
modules/image/text_to_image/ernie_vilg/test.py
0 → 100644
浏览文件 @
755425ce
import
shutil
import
unittest
import
paddlehub
as
hub
class
TestHubModule
(
unittest
.
TestCase
):
@
classmethod
def
setUpClass
(
cls
)
->
None
:
cls
.
module
=
hub
.
Module
(
name
=
"ernie_vilg"
)
@
classmethod
def
tearDownClass
(
cls
)
->
None
:
shutil
.
rmtree
(
'ernievilg_output'
)
def
test_generate_image
(
self
):
self
.
module
.
generate_image
(
text_prompts
=
[
'戴眼镜的猫'
],
style
=
"探索无限"
,
topk
=
6
,
visualization
=
True
,
output_dir
=
'ernievilg_output'
)
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录