dalle部署可以使用中文 (原为dalle俄语版)

2023-10-29 00:30

本文主要是介绍dalle部署可以使用中文 (原为dalle俄语版),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

原项目地址https://github.com/ai-forever/ru-dalle

pip install rudalle==1.1.0rc0
pip install  ruclip
pip install translators   -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn

1 项目运行俄语版

import ruclip
from rudalle.pipelines import generate_images, show, super_resolution, cherry_pick_by_ruclip
from rudalle import get_rudalle_model, get_tokenizer, get_vae, get_realesrgan
from rudalle.utils import seed_everything# prepare models:
device = 'cuda'
dalle = get_rudalle_model('Malevich', pretrained=True, fp16=True, device=device)
tokenizer = get_tokenizer()
vae = get_vae(dwt=True).to(device)# pipeline utils:
realesrgan = get_realesrgan('x2', device=device)
clip, processor = ruclip.load('ruclip-vit-base-patch32-384', device=device)
clip_predictor = ruclip.Predictor(clip, processor, device, bs=8)
text = 'радуга на фоне ночного города'seed_everything(42)
pil_images = []
scores = []
for top_k, top_p, images_num in [(2048, 0.995, 24),
]:_pil_images, _scores = generate_images(text, tokenizer, dalle, vae, top_k=top_k, images_num=images_num, bs=8, top_p=top_p)pil_images += _pil_imagesscores += _scoresshow(pil_images, 6)

2软件翻译

# 载入翻译器
import translators as tsdef translate(txt, backend):return getattr(ts, backend)(txt, from_language='auto', to_language='ru')
# 对图像的文字描述backend = 'google' # google/bing/alibaba/tencent/sogou
source_text = '鳄梨形椅子' # 自动模式,你可以输入任何语言作为文字描述 # auto mode, you can type any languageprint('源文本 target text:', source_text)
try:target_text = translate(source_text, backend)
except:raise Exception('调用翻译器失败,请尝试更换backend。''Failed to call the translator, please try to replace the backend.')
print('目标文本 target text:', target_text)

在这里插入图片描述

3完整代码

import ruclip
from rudalle.pipelines import generate_images, show, super_resolution, cherry_pick_by_ruclip
from rudalle import get_rudalle_model, get_tokenizer, get_vae, get_realesrgan
from rudalle.utils import seed_everything
import translators as tsdef translate(txt, backend):return getattr(ts, backend)(txt, from_language='auto', to_language='ru')# prepare models:
device = 'cuda'
dalle = get_rudalle_model('Malevich', pretrained=True, fp16=True, device=device)
tokenizer = get_tokenizer()
vae = get_vae(dwt=True).to(device)# pipeline utils:
realesrgan = get_realesrgan('x2', device=device)
clip, processor = ruclip.load('ruclip-vit-base-patch32-384', device=device)
clip_predictor = ruclip.Predictor(clip, processor, device, bs=8)
backend = 'google' # google/bing/alibaba/tencent/sogou
source_text = '鳄梨形椅子' # 自动模式,你可以输入任何语言作为文字描述 # auto mode, you can type any languagetry:target_text = translate(source_text, backend)
except:raise Exception('调用翻译器失败,请尝试更换backend。''Failed to call the translator, please try to replace the backend.')
print('目标文本 target text:', target_text)seed_everything(42)
pil_images = []
scores = []
for top_k, top_p, images_num in [(2048, 0.995, 24),
]:_pil_images, _scores = generate_images(target_text, tokenizer, dalle, vae, top_k=top_k, images_num=images_num, bs=8, top_p=top_p)pil_images += _pil_imagesscores += _scoresshow(pil_images, 6)

2080ti 显存不足在这里插入图片描述
修改超参数,会使效果变差

import ruclip
from rudalle.pipelines import generate_images, show, super_resolution, cherry_pick_by_ruclip
from rudalle import get_rudalle_model, get_tokenizer, get_vae, get_realesrgan
from rudalle.utils import seed_everything
import translators as tsdef translate(txt, backend):return getattr(ts, backend)(txt, from_language='auto', to_language='ru')# prepare models:
device = 'cuda'
dalle = get_rudalle_model('Malevich', pretrained=True, fp16=True, device=device)
tokenizer = get_tokenizer()
vae = get_vae(dwt=True).to(device)# pipeline utils:
realesrgan = get_realesrgan('x2', device=device)
clip, processor = ruclip.load('ruclip-vit-base-patch32-384', device=device)
clip_predictor = ruclip.Predictor(clip, processor, device, bs=8)
backend = 'google' # google/bing/alibaba/tencent/sogou
source_text = '鳄梨形椅子' # 自动模式,你可以输入任何语言作为文字描述 # auto mode, you can type any languagetry:target_text = translate(source_text, backend)
except:raise Exception('调用翻译器失败,请尝试更换backend。''Failed to call the translator, please try to replace the backend.')
print('目标文本 target text:', target_text)seed_everything(42)
pil_images = []
scores = []
for top_k, top_p, images_num in [# (2048, 0.995, 24),(2048, 0.995,6),
]:_pil_images, _scores = generate_images(target_text, tokenizer, dalle, vae, top_k=top_k, images_num=images_num, bs=2, top_p=top_p)pil_images += _pil_imagesscores += _scores# show(pil_images, 6)
show(pil_images, 2)

好吃的小面包
在这里插入图片描述
难吃的小面包
在这里插入图片描述
电脑游戏
在这里插入图片描述

这篇关于dalle部署可以使用中文 (原为dalle俄语版)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/297007

相关文章

Git可视化管理工具(SourceTree)使用操作大全经典

《Git可视化管理工具(SourceTree)使用操作大全经典》本文详细介绍了SourceTree作为Git可视化管理工具的常用操作,包括连接远程仓库、添加SSH密钥、克隆仓库、设置默认项目目录、代码... 目录前言:连接Gitee or github,获取代码:在SourceTree中添加SSH密钥:Cl

Python中模块graphviz使用入门

《Python中模块graphviz使用入门》graphviz是一个用于创建和操作图形的Python库,本文主要介绍了Python中模块graphviz使用入门,具有一定的参考价值,感兴趣的可以了解一... 目录1.安装2. 基本用法2.1 输出图像格式2.2 图像style设置2.3 属性2.4 子图和聚

windows和Linux使用命令行计算文件的MD5值

《windows和Linux使用命令行计算文件的MD5值》在Windows和Linux系统中,您可以使用命令行(终端或命令提示符)来计算文件的MD5值,文章介绍了在Windows和Linux/macO... 目录在Windows上:在linux或MACOS上:总结在Windows上:可以使用certuti

CentOS和Ubuntu系统使用shell脚本创建用户和设置密码

《CentOS和Ubuntu系统使用shell脚本创建用户和设置密码》在Linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设置密码,本文写了一个shell... 在linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设

Python使用Matplotlib绘制3D曲面图详解

《Python使用Matplotlib绘制3D曲面图详解》:本文主要介绍Python使用Matplotlib绘制3D曲面图,在Python中,使用Matplotlib库绘制3D曲面图可以通过mpl... 目录准备工作绘制简单的 3D 曲面图绘制 3D 曲面图添加线框和透明度控制图形视角Matplotlib

Pandas中统计汇总可视化函数plot()的使用

《Pandas中统计汇总可视化函数plot()的使用》Pandas提供了许多强大的数据处理和分析功能,其中plot()函数就是其可视化功能的一个重要组成部分,本文主要介绍了Pandas中统计汇总可视化... 目录一、plot()函数简介二、plot()函数的基本用法三、plot()函数的参数详解四、使用pl

使用Python实现IP地址和端口状态检测与监控

《使用Python实现IP地址和端口状态检测与监控》在网络运维和服务器管理中,IP地址和端口的可用性监控是保障业务连续性的基础需求,本文将带你用Python从零打造一个高可用IP监控系统,感兴趣的小伙... 目录概述:为什么需要IP监控系统使用步骤说明1. 环境准备2. 系统部署3. 核心功能配置系统效果展

使用Java将各种数据写入Excel表格的操作示例

《使用Java将各种数据写入Excel表格的操作示例》在数据处理与管理领域,Excel凭借其强大的功能和广泛的应用,成为了数据存储与展示的重要工具,在Java开发过程中,常常需要将不同类型的数据,本文... 目录前言安装免费Java库1. 写入文本、或数值到 Excel单元格2. 写入数组到 Excel表格

redis中使用lua脚本的原理与基本使用详解

《redis中使用lua脚本的原理与基本使用详解》在Redis中使用Lua脚本可以实现原子性操作、减少网络开销以及提高执行效率,下面小编就来和大家详细介绍一下在redis中使用lua脚本的原理... 目录Redis 执行 Lua 脚本的原理基本使用方法使用EVAL命令执行 Lua 脚本使用EVALSHA命令

Java 中的 @SneakyThrows 注解使用方法(简化异常处理的利与弊)

《Java中的@SneakyThrows注解使用方法(简化异常处理的利与弊)》为了简化异常处理,Lombok提供了一个强大的注解@SneakyThrows,本文将详细介绍@SneakyThro... 目录1. @SneakyThrows 简介 1.1 什么是 Lombok?2. @SneakyThrows