新的生图模型DeepFloyd IF来了,可以拳打Stable Diffusion,脚踢Dall-E?

简介:

Stability AI与它的多模式AI研究实验室DeepFloyd共同宣布研究版本DeepFloyd IF的发布,这是一款强大的文text-to-image级联像素扩散模型(cascaded pixel diffusion model),复现了Google的Imagen(Text-to-Image Diffusion Models)。

对比Stable Diffusion(可以看我以前的文章:北方的郎:深入浅出讲解Stable Diffusion原理,新手也能看明白),Imagen也依赖于一个冻结的文本编码器:先将文本提示转换为嵌入,然后由扩散模型解码成图像。但不同的是,Imagen并没有使用多模态训练的CLIP,而是使用了大型T5-XXL语言模型。而StabilityAI推出的DeepFloyd IF复刻的正是这一架构。同时DeepFloyd IF在像素空间工作,与Stable Diffusion不同,扩散是在像素级实现的。

这些特点使它可以更精确的生成图像,例如生成带有特定文本的图片。在测试中,DeepFloyd IF直接超越了谷歌的Imagen,以及一众竞品(包括兄弟产品Stable Diffusion)。

照例还是先列出所有资源链接:

GitHub:GitHub - deep-floyd/IF

博客:

Stability AI releases DeepFloyd IF, a powerful text-to-image model that can smartly integrate text into images — Stability AI

Running IF with diffusers on a Free Tier Google Colab

Imagen:Text-to-Image Diffusion Models

论文灵感:https://arxiv.org/pdf/2205.11487.pdf

官网: https://deepfloyd.ai/deepfloyd-if

模型下载: https://github.com/deep-floyd/IF

HuggingFace Space: https://huggingface.co/DeepFloyd

Demo试验: https://huggingface.co/spaces/DeepFloyd/IF

参与讨论: https://linktr.ee/deepfloyd

整体介绍:

DeepFloyd IF是StablilityAI在非商业研究许可证下发布的最先进的文本到图像模型。与StablilityAI的其他模型一样,StablilityAI打算在未来发布完全开源的DeepFloyd IF模型。

DeepFloyd IF,具有高度的照片级真实感和语言理解。DeepFloyd IF 是一个由冻结的文本编码器和三个级联像素扩散模块组成的模块:

一个基于文本提示(Text Prompt)生成 64x64 像素图像的基本模型和两个超分辨率模型,每个模型都旨在生成分辨率不断提高的图像:256x256 像素和 1024x1024 像素。该模型的所有阶段都利用基于 T5 转换器的冻结文本编码器来提取文本嵌入,然后将其馈送到通过交叉注意力和注意力池增强的 UNet 架构中。

结果是一个高效的模型,优于当前最先进的模型,在COCO数据集上实现了6.66的 zero-shot FID分数。研究者的工作体现了更大的UNet架构在级联扩散模型第一阶段的潜力,并描绘了文本到图像合成的光明未来。

描述和特征

深度文本提示(text prompt)理解:

利用大型语言模型T5-XXL-1.1作为文本编码器。大量的文本-图像交叉注意力层(text-image cross-attention layers)也提供了更好的提示和图像联盟。

将文本描述应用于图像:

结合T5模型的智能性,DeepFloyd IF生成连贯清晰的文本以及出现在各种空间关系中的不同属性的对象。到目前为止,这些用例对大多数文本到图像模型来说都是具有挑战性的。

高度写真性:

这一特点反映在令人印象深刻的 zero-shot FID得分6.66上,该得分是在COCO dataset上获得的(FID是评估文本到图像模型性能的主要指标;分数越低,性能越好)。

宽高比转换:

生成非标准宽高比的图像的能力,垂直或水平的,以及标准的方形宽高比。

zero-shot图像到图像转换:

图像修改是通过(1)将原始图像调整到64个像素,(2)通过正向扩散添加噪音,以及(3)使用带有新提示的反向扩散去除图像的噪音(在填补模式下,该过程发生在图像的局部区域内)实现的。样式可以通过超分辨率模块进一步改变提示文本描述。这种方法提供了在保持源图像的基本形式的同时修改输出的风格、模式和细节的机会 - 而所有这些都无需微调。

模型定义

DeepFloyd IF是一个模块化的、级联的、像素扩散模型。这里详细说明每个描述符的定义:

模块化:

DeepFloyd IF由几个神经模块组成(可以独立解决任务的神经网络,如从文本提示生成图像和超分辨率),这些模块在一个体系结构中相互作用,产生协同效应。

级联:

DeepFloyd IF以级联方式对高分辨率数据进行建模,使用不同分辨率下单独训练的一系列模型。该过程从生成唯一低分辨率样本的基本模型(“player”)开始,然后由连续的超分辨率模型(“amplifiers”)上采样以产生高分辨率图像。

扩散:

DeepFloyd IF的基本模型和超分辨率模型是扩散模型,其中使用一系列步骤的马尔科夫链向数据中注入随机噪声,然后反转该过程以从噪声中生成新数据样本。

像素:

DeepFloyd IF在像素空间工作。与使用潜在表示的潜在扩散模型(如Stable Diffusion)不同,扩散是在像素级实现的。

总之,DeepFloyd IF是一个模块化的、级联的、基于像素的扩散模型,它由多个神经模块组成,可以独立地生成和提高图像分辨率。它使用一系列单独训练的模型在不同分辨率下以级联方式对高分辨率数据进行建模。该模型是一种扩散模型,可以在像素级注入和删除随机噪声。这使得DeepFloyd IF在保留源内容的同时生成新样式和细节方面表现出色。

这幅生成流程图代表三个阶段的工作:文本提示通过冻结的T5-XXL语言模型传递,将其转换为定性文本表示。

第一阶段:基本扩散模型将定性文本转换为64x64图像。DeepFloyd团队已训练三个版本的基本模型,每个模型的参数都不同:IF-I 400M、IF-I 900M和IF-I 4.3B。

第二阶段:为了“放大”图像,应用两个文本条件超分辨率模型(Efficient U-Net)对基本模型的输出。第一个模型将64x64图像放大到256x256图像。同样,该模型也有几个版本可用:IF-II 400M和IF-II 1.2B。

第三阶段:应用第二个超分辨率扩散模型产生生动的1024x1024图像。最终的第三阶段模型IF-III有700M个参数。注意:研究者还没有发布这个第三阶段模型;然而,IF模型的模块化特性允许他们在第三阶段使用其他放大模型 - 如Stable Diffusion x4 Upscaler

数据集训练

DeepFloyd IF在定制的LAION-A数据集上训练,该数据集由10亿对高质量图像和文本组成。LAION-A是LAION-5B数据集英语部分的优化后的子集,包括基于相似性哈希进行去重、额外清理以及对原始数据集的其他修改。DeepFloyd的定制过滤器用于删除带水印的、不适合工作环境的和其他不恰当的内容。

Model 列表

Name Cascade Params FID Batch size Steps
IF-I-M I 400M 8.86 3072 2.5M
IF-I-L I 900M 8.06 3200 3.0M
IF-I-XL* I 4.3B 6.66 3072 2.42M
IF-II-M II 450M - 1536 2.5M
IF-II-L* II 1.2B - 1536 2.5M
IF-III-L* (soon) III 700M - 3072 1.25M

*best modules

模型评估

下面是不同大小的DeepFloyd IF模型在COCO数据集上的评测效果,可以看到模型参数越大,FID越低,最大的模型IF-4.3B的FID为6.6。

模型应用

使用所有IF模型的最低要求:

  • 16GB vRAM,用于 IF-I-XL(4.3B 文本到 64x64 基本模块)和 IF-II-L(1.2B 到 256x256 升频模块)
  • 24GB vRAM,用于IF-I-XL(4.3B文本到64x64基本模块)和IF-II-L(1.2B到256x256升频模块)和稳定的x4(到1024x1024升频器)
  • xformers并设置环境变量FORCE_MEM_EFFICIENT_ATTN=1

运行

目前DeepFloyd IF模型也已经集成到了diffusers库 FaceDiffusers library.

diffusers默认试用model cpu offloading运行IF pipeline,这样只需要14 GB VRAM就可以了。

from diffusers import DiffusionPipeline
from diffusers.utils import pt_to_pil
import torch

# stage 1
stage_1 = DiffusionPipeline.from_pretrained("DeepFloyd/IF-I-XL-v1.0", variant="fp16", torch_dtype=torch.float16)
stage_1.enable_xformers_memory_efficient_attention()  # remove line if torch.__version__ >= 2.0.0
stage_1.enable_model_cpu_offload()

# stage 2
stage_2 = DiffusionPipeline.from_pretrained(
    "DeepFloyd/IF-II-L-v1.0", text_encoder=None, variant="fp16", torch_dtype=torch.float16
)
stage_2.enable_xformers_memory_efficient_attention()  # remove line if torch.__version__ >= 2.0.0
stage_2.enable_model_cpu_offload()

# stage 3
safety_modules = {"feature_extractor": stage_1.feature_extractor, "safety_checker": stage_1.safety_checker, "watermarker": stage_1.watermarker}
stage_3 = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-x4-upscaler", **safety_modules, torch_dtype=torch.float16)
stage_3.enable_xformers_memory_efficient_attention()  # remove line if torch.__version__ >= 2.0.0
stage_3.enable_model_cpu_offload()

prompt = 'a photo of a kangaroo wearing an orange hoodie and blue sunglasses standing in front of the eiffel tower holding a sign that says "very deep learning"'

# text embeds
prompt_embeds, negative_embeds = stage_1.encode_prompt(prompt)

generator = torch.manual_seed(0)

# stage 1
image = stage_1(prompt_embeds=prompt_embeds, negative_prompt_embeds=negative_embeds, generator=generator, output_type="pt").images
pt_to_pil(image)[0].save("./if_stage_I.png")

# stage 2
image = stage_2(
    image=image, prompt_embeds=prompt_embeds, negative_prompt_embeds=negative_embeds, generator=generator, output_type="pt"
).images
pt_to_pil(image)[0].save("./if_stage_II.png")

# stage 3
image = stage_3(prompt=prompt, image=image, generator=generator, noise_level=100).images
image[0].save("./if_stage_III.png")

I. Dream

Dream is the text-to-image mode of the IF model

from deepfloyd_if.pipelines import dream

prompt = 'ultra close-up color photo portrait of rainbow owl with deer horns in the woods'
count = 4

result = dream(
    t5=t5, if_I=if_I, if_II=if_II, if_III=if_III,
    prompt=[prompt]*count,
    seed=42,
    if_I_kwargs={
        "guidance_scale": 7.0,
        "sample_timestep_respacing": "smart100",
    },
    if_II_kwargs={
        "guidance_scale": 4.0,
        "sample_timestep_respacing": "smart50",
    },
    if_III_kwargs={
        "guidance_scale": 9.0,
        "noise_level": 20,
        "sample_timestep_respacing": "75",
    },
)

if_III.show(result['III'], size=14)

II. Zero-shot Image-to-Image Translation

In Style Transfer mode, the output of your prompt comes out at the style of the support_pil_img

from deepfloyd_if.pipelines import style_transfer

result = style_transfer(
    t5=t5, if_I=if_I, if_II=if_II,
    support_pil_img=raw_pil_image,
    style_prompt=[
        'in style of professional origami',
        'in style of oil art, Tate modern',
        'in style of plastic building bricks',
        'in style of classic anime from 1990',
    ],
    seed=42,
    if_I_kwargs={
        "guidance_scale": 10.0,
        "sample_timestep_respacing": "10,10,10,10,10,10,10,10,0,0",
        'support_noise_less_qsample_steps': 5,
    },
    if_II_kwargs={
        "guidance_scale": 4.0,
        "sample_timestep_respacing": 'smart50',
        "support_noise_less_qsample_steps": 5,
    },
)
if_I.show(result['II'], 1, 20)

III. Super Resolution

For super-resolution, users can run IF-II and IF-III or 'Stable x4' on an image that was not necessarely generated by IF (two cascades):

from deepfloyd_if.pipelines import super_resolution

middle_res = super_resolution(
    t5,
    if_III=if_II,
    prompt=['woman with a blue headscarf and a blue sweaterp, detailed picture, 4k dslr, best quality'],
    support_pil_img=raw_pil_image,
    img_scale=4.,
    img_size=64,
    if_III_kwargs={
        'sample_timestep_respacing': 'smart100',
        'aug_level': 0.5,
        'guidance_scale': 6.0,
    },
)
high_res = super_resolution(
    t5,
    if_III=if_III,
    prompt=[''],
    support_pil_img=middle_res['III'][0],
    img_scale=4.,
    img_size=256,
    if_III_kwargs={
        "guidance_scale": 9.0,
        "noise_level": 20,
        "sample_timestep_respacing": "75",
    },
)
show_superres(raw_pil_image, high_res['III'][0])

IV. Zero-shot Inpainting

from deepfloyd_if.pipelines import inpainting

result = inpainting(
    t5=t5, if_I=if_I,
    if_II=if_II,
    if_III=if_III,
    support_pil_img=raw_pil_image,
    inpainting_mask=inpainting_mask,
    prompt=[
        'oil art, a man in a hat',
    ],
    seed=42,
    if_I_kwargs={
        "guidance_scale": 7.0,
        "sample_timestep_respacing": "10,10,10,10,10,0,0,0,0,0",
        'support_noise_less_qsample_steps': 0,
    },
    if_II_kwargs={
        "guidance_scale": 4.0,
        'aug_level': 0.0,
        "sample_timestep_respacing": '100',
    },
    if_III_kwargs={
        "guidance_scale": 9.0,
        "noise_level": 20,
        "sample_timestep_respacing": "75",
    },
)
if_I.show(result['I'], 2, 3)
if_I.show(result['II'], 2, 6)
if_I.show(result['III'], 2, 14)

效果测试:

prompt:landscape of newyork with words "hello"

Midjourney

Stable Diffusion

这个实验只有DeepFloyd IF正确显示了文字。

Prompt:a man holding a cardboard with words "let's dance"

DeepFloyd IF

MidJourney

Stable Diffusion

这个实验只有DeepFloyd IF比较正确显示了文字(4张图就1张图多了一个t)。

Prompt: a neon sign says "It's Saturday"

Midjourney:

StableDiffusion:

这个实验只有DeepFloyd IF正确显示了文字,看起来DeepFloyd IF在正确显示文字方面的确是有着巨大的优势。

Prompt: an old lady looking at a mirror and seeing a beautiful young girl

这个效果其实是试了好几次的结果。

Stable Diffusion

感觉有帮助的朋友,欢迎赞同、关注、分享三连。^-^

猜你喜欢

转载自blog.csdn.net/hawkman/article/details/130641680