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

文档下载页面模板梁水才seo优化专家

文档下载页面模板,梁水才seo优化专家,用java做视频网站,wordpress集成文库1 关于Diffusers Pipeline 1.1 简介 大部分扩散模型包含多个独立训练的子模型和组件模块组合而成,例如StableDiffusion 有: 3个独立训练的子模型:Autoencoder、 Conditional Unet、CLIP text encoder调度器组件scheduler,CLIPImageProcesso…

1 关于Diffusers Pipeline

1.1 简介

大部分扩散模型包含多个独立训练的子模型和组件模块组合而成,例如StableDiffusion 有:

  • 3个独立训练的子模型:Autoencoder、 Conditional Unet、CLIP text encoder
  • 调度器组件scheduler,
  • CLIPImageProcessor,
  • safety checker.

为了让开发者以最简单的方式使用最新最先进的扩散模型,diffusers开发了pipeline管理和使用这些类,使得开发者可以以端对端方式使用扩散模型。

注意:pipeline本身没有提供任何训练相关功能,如果想要实现训练,可以参考官方的训练样例

1.2 官方Pipeline

以下表格是diffusers官方实现的Pipeline,每个Pipeline有对应的论文。

PipelineSourceTasks
dance diffusionDance DiffusionUnconditional Audio Generation
ddpmDenoising Diffusion Probabilistic ModelsUnconditional Image Generation
ddimDenoising Diffusion Implicit ModelsUnconditional Image Generation
latent_diffusionHigh-Resolution Image Synthesis with Latent Diffusion ModelsText-to-Image Generation
latent_diffusion_uncondHigh-Resolution Image Synthesis with Latent Diffusion ModelsUnconditional Image Generation
pndmPseudo Numerical Methods for Diffusion Models on ManifoldsUnconditional Image Generation
score_sde_veScore-Based Generative Modeling through Stochastic Differential EquationsUnconditional Image Generation
score_sde_vpScore-Based Generative Modeling through Stochastic Differential EquationsUnconditional Image Generation
stable_diffusionStable DiffusionText-to-Image Generation
stable_diffusionStable DiffusionImage-to-Image Text-Guided Generation
stable_diffusionStable DiffusionText-Guided Image Inpainting
stochastic_karras_veElucidating the Design Space of Diffusion-Based Generative ModelsUnconditional Image Generation

2 Pipeline API接口

扩散模型包含多个独立的模型和组件,不同任务中模型独立训练,并且可以用其他模型替换。不同的Pipeline可能包含专有的函数接口,但所有Pipeline都有的共同函数如下:

  • from_pretrained(cls, pretrained_model_name_or_path, **kwargs): 参数pretrained_model_name_or_path可以是 Hugging Face Hub repository的 id, 例如: runwayml/stable-diffusion-v1-5 或本地路径:"./stable-diffusion". 为了确保所有模型和组件能被正确加载,需要提供一个 model_index.json 文件, 例如: runwayml/stable-diffusion-v1-5/model_index.json, 这个文件定义了所有要被加载的组件。其格式如下: <name>: ["<library>", "<class name>"],其中<name> 是类<class name>实例的名称。此类可以在库"<library>"中加载到。
  • save_pretrained(self, save_directory) : 参数save_directory为本地目录路径,例如: ./stable-diffusion ,所有的模型和组件会被保存。每个模型和组件创建一个对应的子目录,子目录名称为模型或组件的属性名称如./stable_diffusion/unet. 此外,还会再根目录创建 model_index.json 文件如:./stable_diffusion/model_index.json
  • to(self, torch_device: Optional[Union[str, torch.device]] = None) 参数torch_device为 stringtorch.device 类型,将所有torch.nn.Module 类型的对象转移到指定的device上,此函数与pytorch的to函数功能一致。
  • __call__函数执行推理,此函数定义了pipeline的推理逻辑,不同的Pipeline对应的推理输入差别很大,例如文生图Pipeline StableDiffusionPipeline 的输入应该是文本prompt,输出是生成的图。 而DDPMPipeline 则无需提供任何输入。因此读者需要根据实际的Pipeline功能以及查看相应的官方文档使用。

注意: 所有的Pipeline的__call__函数会自动调用torch.no_grad函数禁用梯度,因为Pipeline不是用于训练。如果你在前向推理后有保存梯度的需求,可以自定义Pipeline,参考官方示例

3 使用示例

1 扩散模型:文生图

# make sure you're logged in with `huggingface-cli login`
from diffusers import StableDiffusionPipeline, LMSDiscreteSchedulerpipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
pipe = pipe.to("cuda")prompt = "a photo of an astronaut riding a horse on mars"
image = pipe(prompt).images[0]  image.save("astronaut_rides_horse.png")

2 扩散模型:图生图

StableDiffusionImg2ImgPipeline 接受一个文本prompt和初始图片作为条件,指导生成新图。

import requests
from PIL import Image
from io import BytesIOfrom diffusers import StableDiffusionImg2ImgPipeline# load the pipeline
device = "cuda"
pipe = StableDiffusionImg2ImgPipeline.from_pretrained("runwayml/stable-diffusion-v1-5",torch_dtype=torch.float16,
).to(device)# let's download an initial image
url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"response = requests.get(url)
init_image = Image.open(BytesIO(response.content)).convert("RGB")
init_image = init_image.resize((768, 512))prompt = "A fantasy landscape, trending on artstation"images = pipe(prompt=prompt, image=init_image, strength=0.75, guidance_scale=7.5).imagesimages[0].save("fantasy_landscape.png")

可以在colab中直接运行colab

3 扩充模型:In-painting

StableDiffusionInpaintPipeline 接受文本prompt和mask,用于编辑图像指定区域。

import PIL
import requests
import torch
from io import BytesIOfrom diffusers import StableDiffusionInpaintPipelinedef download_image(url):response = requests.get(url)return PIL.Image.open(BytesIO(response.content)).convert("RGB")img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"init_image = download_image(img_url).resize((512, 512))
mask_image = download_image(mask_url).resize((512, 512))pipe = StableDiffusionInpaintPipeline.from_pretrained("runwayml/stable-diffusion-inpainting",torch_dtype=torch.float16,
)
pipe = pipe.to("cuda")prompt = "Face of a yellow cat, high resolution, sitting on a park bench"
image = pipe(prompt=prompt, image=init_image, mask_image=mask_image).images[0]

可以在colab中直接运行 colab

http://www.tj-hxxt.cn/news/62122.html

相关文章:

  • 做dota2菠菜网站seo自动推广工具
  • 新手怎样做网站推广厂房网络推广平台
  • 成都最正规的装修公司站长工具seo综合查询是什么
  • 用dw制作个介绍家乡网站百度指数查询排行榜
  • 常熟做网站优化网站seo入门基础教程书籍
  • 网络营销用什么软件昆明seo博客
  • 360免费wifi怎么安装宁波网络推广优化方案
  • 合适做服装的国际网站发外链平台
  • 两学一做的做题网站是多少游戏推广员是违法的吗
  • 网页视频下载器免费提供seo服务
  • 之江汇学校网站建设百度搜索关键词排名优化
  • 抖音小姐姐做我女朋友网站世界羽联最新排名
  • 域名空间做网站石家庄新闻网头条新闻
  • 推销什么企业做网站和app6百度站长平台论坛
  • 如何让网站收录百度官网登录入口
  • 上海高端网站制作站霸科技成都关键词优化排名
  • 深圳顶级做网站公司排名专业seo网站优化推广排名教程
  • 洛阳网站建设招聘信息查询网站相关网址
  • 做go分析的网站如何进行市场推广
  • 网站开发有关书籍网站宣传的方法有哪些
  • 天津百度分公司奉化网站关键词优化费用
  • 郑州网站制作咨询上海网络推广需要多少
  • 网站建设维修服务流程西部数码域名注册
  • 网站一次性链接怎么做的可以访问违规网站的浏览器
  • 成都网站设计培训跨境电商平台注册开店流程
  • 百度站长查询工具网店代运营诈骗
  • 联想北京有限公司北京网站优化策略
  • 专门做简历的网站国家免费培训学校
  • 黄色为主的网站企业官网推广
  • 上海整形网站建设关键词查网站