Altdiffusion
基于AltCLIP和Stable Diffusion框架开发的双语文本到图像生成模型,支持中英文输入
下载量 26
发布时间 : 11/15/2022
模型简介
AltDiffusion是一个多语言文本到图像生成模型,基于稳定扩散架构,特别优化了中英文双语生成能力。模型保留了原版Stable Diffusion的所有功能,并在部分场景下表现更优。
模型特点
双语生成能力
支持中英文输入生成高质量图像,实现语义对齐
保留原版功能
完整保留Stable Diffusion所有功能,部分场景效果更优
商业友好许可
采用OpenRAIL-M许可证,允许商业用途和权重再分发
模型能力
文本到图像生成
中英文双语理解
高质量图像合成
艺术风格转换
使用案例
创意设计
概念艺术生成
根据文字描述生成游戏/影视概念艺术
可生成如'黑暗精灵公主'等精细角色设计
商业插画创作
快速生成符合需求的商业插画素材
支持8K高清细节输出
教育娱乐
双语学习辅助
通过中英文对照生成可视化学习材料
实现语义一致的双语图像生成
🚀 AltDiffusion
AltDiffusion是一个多模态模型,支持中英文双语输入。它基于Stable Diffusion训练,在中英文对齐方面表现出色,能生成高质量的图像。
🚀 快速开始
模型信息
属性 | 详情 |
---|---|
模型类型 | Stable Diffusion |
训练数据 | WuDao数据集 和 LAION |
模型权重
第一次运行AltDiffusion模型时会自动从 这里 下载如下权重:
模型名称 | 大小 | 描述 |
---|---|---|
StableDiffusionSafetyChecker | 1.13G | 图片的安全检查器 |
AltDiffusion | 8.0G | 双语AltDiffusion模型 |
AltCLIP | 3.22G | 双语AltCLIP模型 |
运行环境
支持通过 Gradio Web UI 运行AltDiffusion:
模型参数
模块名称 | 参数量 |
---|---|
AutoEncoder | 83.7M |
Unet | 865M |
AltCLIP TextEncoder | 859M |
✨ 主要特性
- 双语支持:支持中英文输入,实现多语言文本到图像的生成。
- 高性能:在中英文对齐方面表现出色,保留了原版Stable Diffusion的大部分能力,部分场景表现更优。
- 多场景适用:可用于生成各种风格和主题的图像,如幻想、写实、艺术等。
📦 安装指南
运行Diffusers示例前,需要安装以下依赖:
pip install git+https://github.com/huggingface/diffusers.git torch transformers accelerate sentencepiece
💻 使用示例
基础用法
🧨Diffusers示例
from diffusers import AltDiffusionPipeline, DPMSolverMultistepScheduler
import torch
pipe = AltDiffusionPipeline.from_pretrained("BAAI/AltDiffusion", torch_dtype=torch.float16, revision="fp16")
pipe = pipe.to("cuda")
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
prompt = "黑暗精灵公主,非常详细,幻想,非常详细,数字绘画,概念艺术,敏锐的焦点,插图"
# or in English:
# prompt = "dark elf princess, highly detailed, d & d, fantasy, highly detailed, digital painting, trending on artstation, concept art, sharp focus, illustration, art by artgerm and greg rutkowski and fuji choko and viktoria gavrilenko and hoang lap"
image = pipe(prompt, num_inference_steps=25).images[0]
image.save("./alt.png")
Transformers示例
import os
import torch
import transformers
from transformers import BertPreTrainedModel
from transformers.models.clip.modeling_clip import CLIPPreTrainedModel
from transformers.models.xlm_roberta.tokenization_xlm_roberta import XLMRobertaTokenizer
from diffusers.schedulers import DDIMScheduler, LMSDiscreteScheduler, PNDMScheduler
from diffusers import StableDiffusionPipeline
from transformers import BertPreTrainedModel,BertModel,BertConfig
import torch.nn as nn
import torch
from transformers.models.xlm_roberta.configuration_xlm_roberta import XLMRobertaConfig
from transformers import XLMRobertaModel
from transformers.activations import ACT2FN
from typing import Optional
class RobertaSeriesConfig(XLMRobertaConfig):
def __init__(self, pad_token_id=1, bos_token_id=0, eos_token_id=2,project_dim=768,pooler_fn='cls',learn_encoder=False, **kwargs):
super().__init__(pad_token_id=pad_token_id, bos_token_id=bos_token_id, eos_token_id=eos_token_id, **kwargs)
self.project_dim = project_dim
self.pooler_fn = pooler_fn
# self.learn_encoder = learn_encoder
class RobertaSeriesModelWithTransformation(BertPreTrainedModel):
_keys_to_ignore_on_load_unexpected = [r"pooler"]
_keys_to_ignore_on_load_missing = [r"position_ids", r"predictions.decoder.bias"]
base_model_prefix = 'roberta'
config_class= XLMRobertaConfig
def __init__(self, config):
super().__init__(config)
self.roberta = XLMRobertaModel(config)
self.transformation = nn.Linear(config.hidden_size, config.project_dim)
self.post_init()
def get_text_embeds(self,bert_embeds,clip_embeds):
return self.merge_head(torch.cat((bert_embeds,clip_embeds)))
def set_tokenizer(self, tokenizer):
self.tokenizer = tokenizer
def forward(self, input_ids: Optional[torch.Tensor] = None) :
attention_mask = (input_ids != self.tokenizer.pad_token_id).to(torch.int64)
outputs = self.base_model(
input_ids=input_ids,
attention_mask=attention_mask,
)
projection_state = self.transformation(outputs.last_hidden_state)
return (projection_state,)
model_path_encoder = "BAAI/RobertaSeriesModelWithTransformation"
model_path_diffusion = "BAAI/AltDiffusion"
device = "cuda"
seed = 12345
tokenizer = XLMRobertaTokenizer.from_pretrained(model_path_encoder, use_auth_token=True)
tokenizer.model_max_length = 77
text_encoder = RobertaSeriesModelWithTransformation.from_pretrained(model_path_encoder, use_auth_token=True)
text_encoder.set_tokenizer(tokenizer)
print("text encode loaded")
pipe = StableDiffusionPipeline.from_pretrained(model_path_diffusion,
tokenizer=tokenizer,
text_encoder=text_encoder,
use_auth_token=True,
)
print("diffusion pipeline loaded")
pipe = pipe.to(device)
prompt = "Thirty years old lee evans as a sad 19th century postman. detailed, soft focus, candle light, interesting lights, realistic, oil canvas, character concept art by munkácsy mihály, csók istván, john everett millais, henry meynell rheam, and da vinci"
with torch.no_grad():
image = pipe(prompt, guidance_scale=7.5).images[0]
image.save("3.png")
高级用法
您可以在predict_generate_images
函数里通过改变参数来调整设置,具体信息如下:
参数名 | 类型 | 描述 |
---|---|---|
prompt | str | 提示文本 |
out_path | str | 输出路径 |
n_samples | int | 输出图片数量 |
skip_grid | bool | 如果为True, 会将所有图片拼接在一起,输出一张新的图片 |
ddim_step | int | DDIM模型的步数 |
plms | bool | 如果为True, 则会使用plms模型 |
scale | float | 这个值决定了文本在多大程度上影响生成的图片,值越大影响力越强 |
H | int | 图片的高度 |
W | int | 图片的宽度 |
C | int | 图片的channel数 |
seed | int | 随机种子 |
注意:模型推理要求一张至少10G以上的GPU。
📚 详细文档
🔧 技术细节
AltDiffusion模型基于Stable Diffusion,使用了名为AltCLIP的双语CLIP模型作为支持。通过训练,模型在中英文对齐方面表现出色,能够根据不同的文本输入生成高质量的图像。
📄 许可证
该模型通过 CreativeML Open RAIL-M license 获得许可。作者对您生成的输出不主张任何权利,您可以自由使用它们并对它们的使用负责,不得违反本许可中的规定。该许可证禁止您分享任何违反任何法律、对他人造成伤害、传播任何可能造成伤害的个人信息、传播错误信息和针对弱势群体的任何内容。您可以出于商业目的修改和使用模型,但必须包含相同使用限制的副本。有关限制的完整列表,请阅读许可证 。
引用
AltCLIP相关
@article{https://doi.org/10.48550/arxiv.2211.06679,
doi = {10.48550/ARXIV.2211.06679},
url = {https://arxiv.org/abs/2211.06679},
author = {Chen, Zhongzhi and Liu, Guang and Zhang, Bo-Wen and Ye, Fulong and Yang, Qinghong and Wu, Ledell},
keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences},
title = {AltCLIP: Altering the Language Encoder in CLIP for Extended Language Capabilities},
publisher = {arXiv},
year = {2022},
copyright = {arXiv.org perpetual, non-exclusive license}
}
AltDiffusion相关
@misc{ye2023altdiffusion,
title={AltDiffusion: A Multilingual Text-to-Image Diffusion Model},
author={Fulong Ye and Guang Liu and Xinya Wu and Ledell Wu},
year={2023},
eprint={2308.09991},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
更多生成结果
中英文对齐能力
英文提示
prompt: dark elf princess, highly detailed, d & d, fantasy, highly detailed, digital painting, trending on artstation, concept art, sharp focus, illustration, art by artgerm and greg rutkowski and fuji choko and viktoria gavrilenko and hoang lap
中文提示
prompt: 黑暗精灵公主,非常详细,幻想,非常详细,数字绘画,概念艺术,敏锐的焦点,插图
中文表现能力
提示
prompt: 带墨镜的男孩肖像,充满细节,8K高清
提示
prompt: 带墨镜的中国男孩肖像,充满细节,8K高清
长图生成能力
提示
prompt: 一只带着帽子的小狗
原版 stable diffusion
AltDiffusion
注: 此处长图生成技术由右脑科技(RightBrain AI)提供。
Clip Vit Large Patch14 336
基于Vision Transformer架构的大规模视觉语言预训练模型,支持图像与文本的跨模态理解
文本生成图像
Transformers

C
openai
5.9M
241
Fashion Clip
MIT
FashionCLIP是基于CLIP开发的视觉语言模型,专门针对时尚领域进行微调,能够生成通用产品表征。
文本生成图像
Transformers 英语

F
patrickjohncyh
3.8M
222
Gemma 3 1b It
Gemma 3是Google推出的轻量级先进开放模型系列,基于与Gemini模型相同的研究和技术构建。该模型是多模态模型,能够处理文本和图像输入并生成文本输出。
文本生成图像
Transformers

G
google
2.1M
347
Blip Vqa Base
Bsd-3-clause
BLIP是一个统一的视觉语言预训练框架,擅长视觉问答任务,通过语言-图像联合训练实现多模态理解与生成能力
文本生成图像
Transformers

B
Salesforce
1.9M
154
CLIP ViT H 14 Laion2b S32b B79k
MIT
基于OpenCLIP框架在LAION-2B英文数据集上训练的视觉-语言模型,支持零样本图像分类和跨模态检索任务
文本生成图像
Safetensors
C
laion
1.8M
368
CLIP ViT B 32 Laion2b S34b B79k
MIT
基于OpenCLIP框架在LAION-2B英语子集上训练的视觉-语言模型,支持零样本图像分类和跨模态检索
文本生成图像
Safetensors
C
laion
1.1M
112
Pickscore V1
PickScore v1 是一个针对文本生成图像的评分函数,可用于预测人类偏好、评估模型性能和图像排序等任务。
文本生成图像
Transformers

P
yuvalkirstain
1.1M
44
Owlv2 Base Patch16 Ensemble
Apache-2.0
OWLv2是一种零样本文本条件目标检测模型,可通过文本查询在图像中定位对象。
文本生成图像
Transformers

O
google
932.80k
99
Llama 3.2 11B Vision Instruct
Llama 3.2 是 Meta 发布的多语言多模态大型语言模型,支持图像文本到文本的转换任务,具备强大的跨模态理解能力。
文本生成图像
Transformers 支持多种语言

L
meta-llama
784.19k
1,424
Owlvit Base Patch32
Apache-2.0
OWL-ViT是一个零样本文本条件目标检测模型,可以通过文本查询搜索图像中的对象,无需特定类别的训练数据。
文本生成图像
Transformers

O
google
764.95k
129
精选推荐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