機械犬
城の夕日宮崎アニメーション
花が倒れます
半分の鶏と半分の男、強い
鶏肉、あなたはとても美しいです
Skypaint、Skypaintにアクセスしてください
WeChatのQRコードをスキャンして、MINIプログラムで体験することもできます。 
Skypaint Text Generation Picture Modelは、主に2つの部分、つまり迅速な単語テキストエンコーダーモデルと拡散モデルで構成されています。したがって、最適化は2つのステップに分割されます。まず、Openai-Clipに基づいて、Skypaintが中国と英語の認識能力を持つように最適化され、その後、Skypaintが最適化され、高品質の写真を作成するための現代の芸術能力があります。
モデルダウンロードアドレスSkypaint-V1.0
from diffusers import StableDiffusionPipeline
device = 'cuda'
pipe = StableDiffusionPipeline . from_pretrained ( "path_to_our_model" ). to ( device )
prompts = [
'机械狗' ,
'城堡 大海 夕阳 宫崎骏动画' ,
'花落知多少' ,
'鸡你太美' ,
]
for prompt in prompts :
prompt = 'sai-v1 art, ' + prompt
image = pipe ( prompt ). images [ 0 ]
image . save ( "%s.jpg" % prompt )——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
Skyclipは、中国語と英語のバイリンガルクリップモデルをトレーニングする効率的な方法を使用して得られるクリップモデルです。このメソッドは、Openai-Clipのテキストエンコーダーのみを変更し、Openai-Clipを使用して画像とテキストの検索機能を実現するために使用できます。
Openai-Clipのテキストは、教師モデルと同じサイズを採用しています1、L2、COS距離を使用して、学生モデルの中国語と英語のHidden_stateを徐々に教師モデルのHidden_stateに徐々にアプローチするようにします。並列コーパスの中国と英語には自然な不平等特性があるため、平行中国と英語を可能な限り近くにするために、トレーニングプロセス中に中国語のデコーダーを追加し、学生モデルの中国語と英語のdestate_StateをデコーダーのHidden_state入力として使用し、翻訳タスクを通じて中国と英語の整合を達成するのを支援します。
現在、FlickR30K-CNのSkyclipのゼロショットパフォーマンスを評価し、主に中国の能力を確保するために、いくつかの関連する能力を確保しました。
flickr30k-cn検索:
| タスク | テキストから画像へ | 画像からテキスト | 氏 | ||||
|---|---|---|---|---|---|---|---|
| 設定 | ゼロショット | ゼロショット | |||||
| メトリック | R@1 | R@5 | r@10 | R@1 | R@5 | r@10 | |
| Taiyi-326m | 53.8 | 79.9 | 86.6 | 64.0 | 90.4 | 96.1 | 78.47 |
| altclip | 50.7 | 75.4 | 83.1 | 73.4 | 92.8 | 96.9 | 78.72 |
| ウーコン | 51.9 | 78.6 | 85.9 | 75 | 94.4 | 97.7 | 80.57 |
| R2D2 | 42.6 | 69.5 | 78.6 | 63.0 | 90.1 | 96.4 | 73.37 |
| CNクリップ | 68.1 | 89.7 | 94.5 | 80.2 | 96.6 | 98.2 | 87.87 |
| Skyclip | 58.8 | 82.6 | 89.6 | 78.8 | 96.1 | 98.3 | 84.04 |
from PIL import Image
import requests
import clip
import torch
from transformers import BertTokenizer
from transformers import CLIPProcessor , CLIPModel , CLIPTextModel
import numpy as np
query_texts = [ '一个人' , '一辆汽车' , '两个男人' , '两个女人' ] # 这里是输入提示词,可以随意替换。
# 加载SkyCLIP 中英文双语 text_encoder
text_tokenizer = BertTokenizer . from_pretrained ( "./tokenizer" )
text_encoder = CLIPTextModel . from_pretrained ( "./text_encoder" ). eval ()
text = text_tokenizer ( query_texts , return_tensors = 'pt' , padding = True )[ 'input_ids' ]
url = "http://images.cocodataset.org/val2017/000000040083.jpg" #这里可以换成任意图片的url
# 加载CLIP的image encoder
clip_model = CLIPModel . from_pretrained ( "openai/clip-vit-large-patch14" )
clip_text_proj = clip_model . text_projection
processor = CLIPProcessor . from_pretrained ( "openai/clip-vit-large-patch14" )
image = processor ( images = Image . open ( requests . get ( url , stream = True ). raw ), return_tensors = "pt" )
with torch . no_grad ():
image_features = clip_model . get_image_features ( ** image )
text_features = text_encoder ( text )[ 0 ]
# sep_token对应于openai-clip的eot_token
sep_index = torch . nonzero ( text == student_tokenizer . sep_token_id )
text_features = text_features [ torch . arange ( text . shape [ 0 ]), sep_index [:, 1 ]]
# 乘text投影矩阵
text_features = clip_text_proj ( text_features )
image_features = image_features / image_features . norm ( dim = 1 , keepdim = True )
text_features = text_features / text_features . norm ( dim = 1 , keepdim = True )
# 计算余弦相似度 logit_scale是尺度系数
logit_scale = clip_model . logit_scale . exp ()
logits_per_image = logit_scale * image_features @ text_features . t ()
logits_per_text = logits_per_image . t ()
probs = logits_per_image . softmax ( dim = - 1 ). cpu (). numpy ()
print ( np . around ( probs , 3 ))私たちのデータは、フィルタリングされたLaionデータセットをトレーニングデータとして使用し、テキストの前には「SAI-V1 ART」がタグとして先行し、モデルがより迅速に必要なスタイルと品質を学習できるようにします。 事前に訓練されたモデルでは、安定した拡散V1-5を事前訓練として使用し、16 A100を50時間使用しました。 現在、モデルはまだ継続的に最適化されており、将来的にはより安定したモデルの更新があります。

