Stable Diffusion原理以及CAC的应用


前言

添加本文记录


一、How does Stable Diffusion work?

Stable Diffusion基于latent diffusion model(训练模型以生成图像的latent representations(压缩))

latent diffusion三个主要组件:
在这里插入图片描述

  • An autoencoder (VAE).
      VAE模型有编码器,解码器两部分。编码器用于将图像转换为低维潜在表示,作为U-Net模型的输入。解码器反过来,将潜在的表示转换回图像。扩散训练中,使用编码器获取图像的潜表征(latent representations, latents),用于正向扩散过程,每一步都应用越来越多的噪声。在映射过程中,使用VAE解码器将反向扩散过程产生的去噪latent representations转换回图像。

  • A U-Net.
      U-Net的编码器部分和解码器部分都由ResNet块组成。编码器将图像表示压缩为较低分辨率的图像表示,而解码器将较低分辨率的图像表示解码回原始的高分辨率图像表示。更具体地说,U-Net输出预测噪声残差(difference between the slightly less noisy image and the input image)用于计算预测的去噪图像表示。
      为了防止U-Net在下采样时丢失重要信息,通常在编码器的下采样resnet和解码器的上采样resnet之间添加捷径连接。此外,稳定的扩散U-Net能够通过交叉注意层在文本嵌入上调整输出。交叉注意层被添加到U-Net的编码器和解码器部分ResNet块之间。
    在这里插入图片描述

  • A text-encoder
    文本编码器负责转换输入提示符,例如。“宇航员骑马”编码到U-Net可以理解的嵌入空间。它通常是一个简单的基于Transformer的编码器,将输入tokens序列映射为潜在的文本嵌入序列。

二、使用步骤

  • pipeline : CycleDiffusionPipeline

  • scheduler : DDIMScheduler

scheduler.config

FrozenDict([(‘num_train_timesteps’, 1000),
(‘beta_start’, 0.00085),
(‘beta_end’, 0.012),
(‘beta_schedule’, ‘scaled_linear’),
(‘trained_betas’, None),
(‘clip_sample’, False),
(‘set_alpha_to_one’, False),
(‘steps_offset’, 1),
(‘prediction_type’, ‘epsilon’),
(‘_class_name’, ‘PNDMScheduler’),
(‘_diffusers_version’, ‘0.7.0.dev0’),
(‘skip_prk_steps’, True)])

  • model : UNet2DConditionModel

model.config

FrozenDict([(‘sample_size’, 64),
(‘in_channels’, 4),
(‘out_channels’, 4),
(‘center_input_sample’, False),
(‘flip_sin_to_cos’, True),
(‘freq_shift’, 0),
(‘down_block_types’,
[‘CrossAttnDownBlock2D’,
‘CrossAttnDownBlock2D’,
‘CrossAttnDownBlock2D’,
‘DownBlock2D’]),
(‘mid_block_type’, ‘UNetMidBlock2DCrossAttn’),
(‘up_block_types’,
[‘UpBlock2D’,
‘CrossAttnUpBlock2D’,
‘CrossAttnUpBlock2D’,
‘CrossAttnUpBlock2D’]),
(‘only_cross_attention’, False),
(‘block_out_channels’, [320, 640, 1280, 1280]),
(‘layers_per_block’, 2),
(‘downsample_padding’, 1),
(‘mid_block_scale_factor’, 1),
(‘act_fn’, ‘silu’),
(‘norm_num_groups’, 32),
(‘norm_eps’, 1e-05),
(‘cross_attention_dim’, 768),
(‘attention_head_dim’, 8),
(‘dual_cross_attention’, False),
(‘use_linear_projection’, False),
(‘class_embed_type’, None),
(‘num_class_embeds’, None),
(‘upcast_attention’, False),
(‘resnet_time_scale_shift’, ‘default’),
(‘_class_name’, ‘UNet2DConditionModel’),
(‘_diffusers_version’, ‘0.2.2’),
(‘_name_or_path’, ‘CompVis/stable-diffusion-v1-4’)])

总结

学习使用huggingface上得diffuser仓库提供的各种扩散模型相关论文的模型接口,处理的各种生成任务,如何加载和配置pipeline, schedulers,models。想要看text-guided img2img任务的中间结果,需要客制化采样器
时候还没有调通text-encoder传来的encoder_hidden_states。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值