CSGO是一个用于文本生成图像的PyTorch实现,支持图像驱动的风格迁移、文本驱动的风格化合成和文本编辑驱动的风格化合成。
下载量 500
发布时间 : 8/30/2024
模型介绍
内容详情
替代品
模型简介
CSGO是一个先进的文本生成图像模型,能够实现内容与风格的灵活组合,支持多种风格迁移和合成任务。
模型特点
内容-风格组合
支持灵活的内容和风格标记组合,实现多样化的图像生成效果。
多模式生成
支持图像驱动的风格迁移、文本驱动的风格化合成和文本编辑驱动的风格化合成。
兼容性
与SDXL、VAE、ControlNet和图像编码器完全兼容。
模型能力
文本生成图像
图像风格迁移
文本驱动的风格合成
文本编辑驱动的风格合成
使用案例
创意设计
图像风格迁移
将一张图像的风格迁移到另一张图像上,保留内容特征。
生成具有目标风格的内容图像
文本驱动的风格合成
根据文本描述生成具有特定风格的图像。
生成符合文本描述的风格化图像
图像编辑
文本编辑驱动的风格合成
通过编辑文本描述来调整生成图像的风格。
生成根据文本编辑调整后的风格化图像
许可证:Apache-2.0
语言:
- 英文
库名称:diffusers
管道标签:文本生成图像
简介 📖
本仓库名为 CSGO,包含了我们论文《CSGO: 文本生成图像中的内容-风格组合》的官方 PyTorch 实现。我们正在积极更新和改进此仓库。如果您发现任何问题或有建议,欢迎提出问题或提交拉取请求(PR)💖。
详情 ✨
我们目前发布了两组模型权重。
模式 | 内容标记数 | 风格标记数 | 其他 |
---|---|---|---|
csgo.bin | 4 | 16 | - |
csgo_4_32.bin | 4 | 32 | Deepspeed zero2 |
csgo_4_32_v2.bin | 4 | 32 | Deepspeed zero2+更多(即将推出) |
流程 💻
功能 🚅
🔥 我们的 CSGO 实现了 图像驱动的风格迁移、文本驱动的风格化合成和文本编辑驱动的风格化合成。
🔥 更多结果请访问我们的 主页 🔥
快速开始 🏁
1. 克隆代码并准备环境
git clone https://github.com/instantX-research/CSGO
cd CSGO
# 使用 conda 创建环境
conda create -n CSGO python=3.9
conda activate CSGO
# 使用 pip 安装依赖
# 适用于 Linux 和 Windows 用户
pip install -r requirements.txt
2. 下载预训练权重(即将推出)
从 HuggingFace 下载预训练权重最简单的方式:
# 首先确保已安装 git-lfs,参见:https://docs.github.com/en/repositories/working-with-files/managing-large-files/installing-git-large-file-storage
git lfs install
# 克隆并移动权重
git clone https://huggingface.co/InstantX/CSGO
我们的方法完全兼容 SDXL、VAE、ControlNet 和 图像编码器。
请下载它们并放置在 ./base_models 文件夹中。
提示:如果您希望像 CSGO 中那样直接使用 ControlNetPipeline 加载 Controlnet,请执行以下操作:
git clone https://huggingface.co/TTPlanet/TTPLanet_SDXL_Controlnet_Tile_Realistic
mv TTPLanet_SDXL_Controlnet_Tile_Realistic/TTPLANET_Controlnet_Tile_realistic_v2_fp16.safetensors TTPLanet_SDXL_Controlnet_Tile_Realistic/diffusion_pytorch_model.safetensors
3. 推理 🚀
import torch
from ip_adapter.utils import resize_content
import numpy as np
from ip_adapter.utils import BLOCKS as BLOCKS
from ip_adapter.utils import controlnet_BLOCKS as controlnet_BLOCKS
from PIL import Image
from diffusers import (
AutoencoderKL,
ControlNetModel,
StableDiffusionXLControlNetPipeline,
)
from ip_adapter import CSGO
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
base_model_path = "./base_models/stable-diffusion-xl-base-1.0"
image_encoder_path = "./base_models/IP-Adapter/sdxl_models/image_encoder"
csgo_ckpt = "./CSGO/csgo.bin"
pretrained_vae_name_or_path = './base_models/sdxl-vae-fp16-fix'
controlnet_path = "./base_models/TTPLanet_SDXL_Controlnet_Tile_Realistic"
weight_dtype = torch.float16
vae = AutoencoderKL.from_pretrained(pretrained_vae_name_or_path, torch_dtype=torch.float16)
controlnet = ControlNetModel.from_pretrained(controlnet_path, torch_dtype=torch.float16, use_safetensors=True)
pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
base_model_path,
controlnet=controlnet,
torch_dtype=torch.float16,
add_watermarker=False,
vae=vae
)
pipe.enable_vae_tiling()
target_content_blocks = BLOCKS['content']
target_style_blocks = BLOCKS['style']
controlnet_target_content_blocks = controlnet_BLOCKS['content']
controlnet_target_style_blocks = controlnet_BLOCKS['style']
csgo = CSGO(pipe, image_encoder_path, csgo_ckpt, device, num_content_tokens=4, num_style_tokens=32,
target_content_blocks=target_content_blocks, target_style_blocks=target_style_blocks, controlnet_adapter=True,
controlnet_target_content_blocks=controlnet_target_content_blocks,
controlnet_target_style_blocks=controlnet_target_style_blocks,
content_model_resampler=True,
style_model_resampler=True,
)
style_name = 'img_1.png'
content_name = 'img_0.png'
style_image = Image.open("../assets/{}".format(style_name)).convert('RGB')
content_image = Image.open('../assets/{}'.format(content_name)).convert('RGB')
caption = 'a small house with a sheep statue on top of it'
num_sample = 4
# 图像驱动的风格迁移
images = csgo.generate(pil_content_image=content_image, pil_style_image=style_image,
prompt=caption,
negative_prompt="text, watermark, lowres, low quality, worst quality, deformed, glitch, low contrast, noisy, saturation, blurry",
content_scale=1.0,
style_scale=1.0,
guidance_scale=10,
num_images_per_prompt=num_sample,
num_samples=1,
num_inference_steps=50,
seed=42,
image=content_image.convert('RGB'),
controlnet_conditioning_scale=0.6,
)
# 文本编辑驱动的风格化合成
caption = 'a small house'
images = csgo.generate(pil_content_image=content_image, pil_style_image=style_image,
prompt=caption,
negative_prompt="text, watermark, lowres, low quality, worst quality, deformed, glitch, low contrast, noisy, saturation, blurry",
content_scale=1.0,
style_scale=1.0,
guidance_scale=10,
num_images_per_prompt=num_sample,
num_samples=1,
num_inference_steps=50,
seed=42,
image=content_image.convert('RGB'),
controlnet_conditioning_scale=0.4,
)
# 文本驱动的风格化合成
caption = 'a cat'
# 如果内容图像仍然干扰生成结果,将内容图像设置为空图像。
# content_image = Image.fromarray(np.zeros((content_image.size[0], content_image.size[1], 3), dtype=np.uint8)).convert('RGB')
images = csgo.generate(pil_content_image=content_image, pil_style_image=style_image,
prompt=caption,
negative_prompt="text, watermark, lowres, low quality, worst quality, deformed, glitch, low contrast, noisy, saturation, blurry",
content_scale=1.0,
style_scale=1.0,
guidance_scale=10,
num_images_per_prompt=num_sample,
num_samples=1,
num_inference_steps=50,
seed=42,
image=content_image.convert('RGB'),
controlnet_conditioning_scale=0.01,
)
演示
🔥 更多结果请访问我们的 主页 🔥
内容-风格组合
循环转换
文本驱动的风格合成
文本编辑驱动的风格合成
Star 历史
致谢
本项目由 InstantX 团队开发,保留所有版权。
引用 💖
如果您发现 CSGO 对您的研究有帮助,欢迎 🌟 此仓库并引用我们的工作:
@article{xing2024csgo,
title={CSGO: 文本生成图像中的内容-风格组合},
author={彭星 and 王浩帆 and 孙彦鹏 and 王启勋 and 柏旭 and 艾浩 and 黄仁远 and 李泽超},
year={2024},
journal = {arXiv 2408.16766},
}
Stable Diffusion V1 5
Openrail
稳定扩散是一种潜在的文本到图像扩散模型,能够根据任何文本输入生成逼真的图像。
图像生成
S
stable-diffusion-v1-5
3.7M
518
Stable Diffusion Inpainting
Openrail
基于稳定扩散的文本到图像生成模型,具备图像修复能力
图像生成
S
stable-diffusion-v1-5
3.3M
56
Stable Diffusion Xl Base 1.0
SDXL 1.0是基于扩散的文本生成图像模型,采用专家集成的潜在扩散流程,支持高分辨率图像生成
图像生成
S
stabilityai
2.4M
6,545
Stable Diffusion V1 4
Openrail
稳定扩散是一种潜在文本到图像扩散模型,能够根据任意文本输入生成逼真图像。
图像生成
S
CompVis
1.7M
6,778
Stable Diffusion Xl Refiner 1.0
SD-XL 1.0优化器模型是Stability AI开发的图像生成模型,专为提升SDXL基础模型生成的图像质量而设计,特别擅长最终去噪步骤处理。
图像生成
S
stabilityai
1.1M
1,882
Stable Diffusion 2 1
基于扩散的文本生成图像模型,支持通过文本提示生成和修改图像
图像生成
S
stabilityai
948.75k
3,966
Stable Diffusion Xl 1.0 Inpainting 0.1
基于Stable Diffusion XL的潜在文本到图像扩散模型,具备通过遮罩进行图像修复的功能
图像生成
S
diffusers
673.14k
334
Stable Diffusion 2 Base
基于扩散的文生图模型,可根据文本提示生成高质量图像
图像生成
S
stabilityai
613.60k
349
Playground V2.5 1024px Aesthetic
其他
开源文生图模型,能生成1024x1024分辨率及多种纵横比的美学图像,在美学质量上处于开源领域领先地位。
图像生成
P
playgroundai
554.94k
723
Sd Turbo
SD-Turbo是一款高速文本生成图像模型,仅需单次网络推理即可根据文本提示生成逼真图像。
图像生成
S
stabilityai
502.82k
380
精选推荐AI模型
Llama 3 Typhoon V1.5x 8b Instruct
专为泰语设计的80亿参数指令模型,性能媲美GPT-3.5-turbo,优化了应用场景、检索增强生成、受限生成和推理任务
大型语言模型
Transformers

支持多种语言
L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一个基于SODA数据集训练的超小型对话模型,专为边缘设备推理设计,体积仅为Cosmo-3B模型的2%左右。
对话系统
Transformers

英语
C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基于RoBERTa架构的中文抽取式问答模型,适用于从给定文本中提取答案的任务。
问答系统
中文
R
uer
2,694
98
AIbase是一个专注于MCP服务的平台,为AI开发者提供高质量的模型上下文协议服务,助力AI应用开发。
简体中文