Qwen2VL + Flux:基于VLM的可控图片理解生成

238 阅读2分钟

Qwen2VL + Flux:基于VLM的可控图片理解生成

image.png

Qwen2vl-Flux 是一种先进的多模态图像生成模型,它将 Qwen2VL 的视觉语言理解能力融入到 FLUX 中。该模型擅长基于文本提示和视觉参考生成高质量图像,提供卓越的多模态理解和控制能力。模型架构将 Qwen2VL 的视觉语言能力集成到 FLUX 框架中,实现更精确和上下文感知的图像生成。关键组件包括:视觉语言理解模块(Qwen2VL)、增强的 FLUX 骨干、多模式生成管道、结构控制集成。特点包括增强的视觉语言理解:利用 Qwen2VL 实现卓越的多模态理解。

此实现使用 Qwen2VL 作为视觉语言模型,以增强多模态理解能力,它与 Flux 架构相集成。同时,它还支持 ControlNet 的功能,包括深度估计和线条检测,以便更精确地控制图像生成。

模型架构

Qwen2VL + Flux整体模型结构:

image.png

关键架构特性:

  • 视觉语言理解:利用Qwen2VL实现卓越的图像和文本理解
  • 增强控制:集成 ControlNet 以实现精确的结构引导
  • 灵活的工作流程:支持各种生成模式,包括变分、图像到图像以及图像修复

效果

image.png

image.png

可以看到,基于Qwen2VL的图像Embedding空间,可以实现对图像的编辑。

image.png

image.png

同时也能实现对图片的融合,使用两张图片,对风格进行融合。

image.png

支持基于GridStyle的风格转换。

上手

安装 克隆存储库并安装依赖项: git clone github.com/erwold/qwen… qwen2vl-fluxpip install -r requirements.txt 从 Hugging Face 下载模型检查点:

from huggingface_hub 

import snapshot_download


snapshot_download("Djrango/Qwen2vl-Flux") 


from model import FluxModel

# Initialize model
model = FluxModel(device="cuda")

# Image Variation
outputs = model.generate(
    input_image_a=input_image,
    prompt="Your text prompt",
    mode="variation"
)

# Image Blending
outputs = model.generate(
    input_image_a=source_image,
    input_image_b=reference_image,
    mode="img2img",
    denoise_strength=0.8
)

# Text-Guided Blending
outputs = model.generate(
    input_image_a=input_image,
    prompt="Transform into an oil painting style",
    mode="variation",
    guidance_scale=7.5
)

# Grid-Based Style Transfer
outputs = model.generate(
    input_image_a=content_image,
    input_image_b=style_image,
    mode="controlnet",
    line_mode=True,
    depth_mode=True
)


Technical Specifications

  • Framework: PyTorch 2.4.1+

  • Base Models:

    • FLUX.1-dev
    • Qwen2-VL-7B-Instruct
  • Memory Requirements: 48GB+ VRAM

  • Supported Image Sizes:

    • 1024x1024 (1:1)
    • 1344x768 (16:9)
    • 768x1344 (9:16)
    • 1536x640 (2.4:1)
    • 896x1152 (3:4)
    • 1152x896 (4:3)