当前位置: 首页 > news >正文

静态网站模板中英文门户型网站模板

静态网站模板中英文,门户型网站模板,阿里云建设网站步骤,做网站杭州使用diffusers 加载 LoRA,实现文生图功能。摘自 diffusers文档。 模型可以根据名称去modelscope找对应资源下载。使用的时候需要替换成具体路径。虽然modelscope和diffusers都使用了模型id,但是并不能通用。 不同的LoRA对应了不同的“trigger” words&am…

使用diffusers 加载 LoRA,实现文生图功能。摘自 diffusers文档。
模型可以根据名称去modelscope找对应资源下载。使用的时候需要替换成具体路径。虽然modelscope和diffusers都使用了模型id,但是并不能通用。
不同的LoRA对应了不同的“trigger” words,在prompt中加入这个“trigger” words才能生成正确的结果。
比如使用了toy-face的LoRA模型,那么就要在prompt加入“toy face”。

from diffusers import DiffusionPipeline
import torchpipe_id = "stabilityai/stable-diffusion-xl-base-1.0"
pipe = DiffusionPipeline.from_pretrained(pipe_id, torch_dtype=torch.float16).to("cuda")#模型下载
#from modelscope import snapshot_download
#model_dir = snapshot_download('SDXL-LoRA/CiroN2022-toy-face')
#加载lora
pipe.load_lora_weights("CiroN2022/toy-face", weight_name="toy_face_sdxl.safetensors", adapter_name="toy")
# 加入 “toy face”
prompt = "toy_face of a hacker with a hoodie"
lora_scale = 0.9
image = pipe(prompt, num_inference_steps=30, cross_attention_kwargs={"scale": lora_scale}, generator=torch.manual_seed(0)
).images[0]
image

也可以再加载另一个模型,pipe.set_adapters() 函数确定使用哪个模型。不同的模型根据adapter_name来区分。

pipe.load_lora_weights("nerijs/pixel-art-xl", weight_name="pixel-art-xl.safetensors", adapter_name="pixel")
pipe.set_adapters("pixel")prompt = "a hacker with a hoodie, pixel art"
image = pipe(prompt, num_inference_steps=30, cross_attention_kwargs={"scale": lora_scale}, generator=torch.manual_seed(0)
).images[0]
image

也可以同时使用,adapter_weights设置不同的权重,prompt也应该包括全部的“trigger” words。

pipe.set_adapters(["pixel", "toy"], adapter_weights=[0.5, 1.0])
prompt = "toy_face of a hacker with a hoodie, pixel art"
image = pipe(prompt, num_inference_steps=30, cross_attention_kwargs={"scale": 1.0}, generator=torch.manual_seed(0)
).images[0]
image

在这里插入图片描述

更准确的控制LoRA的影响强度。unet一般包括down、mid、up,不同的部分对图片的细节、纹理、风格等影响不同。

pipe.enable_lora()  # enable lora again, after we disabled it above
prompt = "toy_face of a hacker with a hoodie, pixel art"
adapter_weight_scales = { "unet": { "down": 1, "mid": 0, "up": 0} }
pipe.set_adapters("pixel", adapter_weight_scales)
image = pipe(prompt, num_inference_steps=30, generator=torch.manual_seed(0)).images[0]
image

从左到右分别对应{ “down”: 1, “mid”: 0, “up”: 0},{ “down”: 0, “mid”: 1, “up”: 0},{ “down”: 0, “mid”: 0, “up”: 1}
在这里插入图片描述

更细粒度的控制。要根据具体的模型结构,不同的模型结构不同。

adapter_weight_scales_toy = 0.5
adapter_weight_scales_pixel = {"unet": {"down": 0.9,  # all transformers in the down-part will use scale 0.9# "mid"  # because, in this example, "mid" is not given, all transformers in the mid part will use the default scale 1.0"up": {"block_0": 0.6,  # all 3 transformers in the 0th block in the up-part will use scale 0.6"block_1": [0.4, 0.8, 1.0],  # the 3 transformers in the 1st block in the up-part will use scales 0.4, 0.8 and 1.0 respectively}}
}
pipe.set_adapters(["toy", "pixel"], [adapter_weight_scales_toy, adapter_weight_scales_pixel])
image = pipe(prompt, num_inference_steps=30, generator=torch.manual_seed(0)).images[0]
image

在这里插入图片描述

常用函数

#不使用
pipe.disable_lora()
#使用
pipe.enable_lora()
#正在使用的
pipe.get_active_adapters()
#列表
pipe.get_list_adapters()
#删除
pipe.delete_adapters("toy")
http://www.15wanjia.com/news/192294.html

相关文章:

  • 哪个网站查食品建设好wordpress自动发布网站
  • 网站策划的基本过程西安市商标局
  • 网站备案注意事项网站开发者工具解读
  • 给传销做网站重庆3号线
  • 吉安知名网站建设wordpress怎么定义不同的侧边栏
  • 购买域名之后怎么做网站站群系统程序
  • 无锡软件网站开发公司江苏微信网站建设
  • seo教育培训机构黑帽seo软件
  • 如何让百度搜索到自己的网站潍坊市做网站
  • h5技术建设网站网站制作技巧017
  • 深圳市招聘信息网站昌宁县住房和城乡建设网站
  • 个人购物网站建设好的兼职做调查网站
  • 周到的网站建设开发小程序的费用明细
  • 中国建设监理官方网站网站加载效果怎么做的
  • dkp网站开发做黏土的网站
  • 如何免费建站网页制作软件案例
  • 长沙购物网站建设王通seo教程
  • 网站品质购物网站介绍
  • 广州易网外贸网站建设视觉设计包括什么
  • 哈尔滨模板建站系统本地做网站图片怎么存
  • 做一个页面网站需要多少钱网站备案号格式说明书
  • 阿里云备案网站备案域名中明建投建设集团 网站
  • 商城网站建设怎么收费做网站数据需要的软件
  • 免费金融发布网站模板下载长安东莞网站设计
  • 凉山彝族自治州网站建站如何查注册商标是别人注册过的
  • 企业网站建设联系电话织梦教育培训网站源码
  • 张家口建设部网站福建建设工程交易中心网站
  • 做网站的要多钱wordpress 图灵机器人
  • 手机传奇手游发布网站鄂州网站建设网络公司
  • 特色专业建设展示网站打开陕西建设厅网站