🚀 CogView4-6B コントロールLoRA
このプロジェクトは、THUDM/CogView4-6B モデルを用いて画像を細かく編集するためのコントロールLoRAです。画像のスタイル変更や設定変更など、様々な編集が可能です。
🚀 クイックスタート
このコントロールLoRAを使用するには、以下の手順に従ってください。
コードの入手
ソースコードはこちらのリポジトリにあります。
https://github.com/a-r-r-o-w/finetrainers
推論コード
以下のコードを使用して、画像の編集を行うことができます。
import torch
from diffusers import CogView4Pipeline
from diffusers.utils import load_image
from finetrainers.models.utils import _expand_linear_with_zeroed_weights
from finetrainers.patches import load_lora_weights
from finetrainers.patches.dependencies.diffusers.control import control_channel_concat
dtype = torch.bfloat16
device = torch.device("cuda")
generator = torch.Generator().manual_seed(0)
pipe = CogView4Pipeline.from_pretrained("THUDM/CogView4-6B", torch_dtype=dtype)
in_channels = pipe.transformer.config.in_channels
patch_channels = pipe.transformer.patch_embed.proj.in_features
pipe.transformer.patch_embed.proj = _expand_linear_with_zeroed_weights(pipe.transformer.patch_embed.proj, new_in_features=2 * patch_channels)
load_lora_weights(pipe, "finetrainers/CogView4-6B-Edit-LoRA-v0", "cogview4-lora")
pipe.set_adapters("cogview4-lora", 0.9)
pipe.to(device)
prompt = "Make the image look like it's from an ancient Egyptian mural."
control_image = load_image("examples/training/control/cogview4/omni_edit/validation_dataset/0.png")
height, width = 1024, 1024
with torch.no_grad():
latents = pipe.prepare_latents(1, in_channels, height, width, dtype, device, generator)
control_image = pipe.image_processor.preprocess(control_image, height=height, width=width)
control_image = control_image.to(device=device, dtype=dtype)
control_latents = pipe.vae.encode(control_image).latent_dist.sample(generator=generator)
control_latents = (control_latents - pipe.vae.config.shift_factor) * pipe.vae.config.scaling_factor
with control_channel_concat(pipe.transformer, ["hidden_states"], [control_latents], dims=[1]):
image = pipe(prompt, latents=latents, num_inference_steps=30, generator=generator).images[0]
image.save("output.png")
📚 詳細ドキュメント
モデル情報
属性 |
詳情 |
モデルタイプ |
コントロールLoRA |
ベースモデル |
THUDM/CogView4-6B |
データセット |
sayapaul/OmniEdit-mini |
ライブラリ名 |
diffusers |
使用例
以下は、このコントロールLoRAを使用した画像編集の例です。
入力テキスト |
出力画像 |
Change it to look like it's in the style of an impasto painting. |
output1.png |
change the setting to spring with blooming trees |
output2.png |
transform the setting to a stormy space |
output3.png |
重要な注意事項
⚠️ 重要提示
これは実験的なチェックポイントであり、汎化性能が低いことが知られています。