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