AnimateDiff をたくさん調べてて見つけた https://animatediff.github.io にいた猫が可愛すぎたので マヌルネコ LoRA を使ってみました。
この記事では AnimateDiff は触りません!
ぬこを触ります!!
ぬこを触ります!!
使用したモデル等は以下になります。
・リアル系モデルから yayoi_mix
・イラスト系モデルから MeinaMix
・そして マヌルネコ LoRA
それでは、、、
猫まみれ~
yayoi_mix
MeinaMix
スクリプト全体
スクリプト全体 (折りたたみ)
事前準備
!pip install -U diffusers["torch"] transformers accelerate peft controlnet_aux
!wget -O lora.safetensors "https://civitai.com/api/download/models/97261?type=Model&format=SafeTensor"
モデルのロード等 (AutoPipelineForText2Image, DPMSolverMultistepScheduler)
import torch from diffusers import AutoPipelineForText2Image, DPMSolverMultistepScheduler # SD 1.5系のモデルを AnimateDiffPipeline でロード pipe = AutoPipelineForText2Image.from_pretrained( "Meina/MeinaMix_V11", custom_pipeline="lpw_stable_diffusion", # 重み付け用のコミュニティパイプライン torch_dtype=torch.float16 ).to("cuda") # モーションローラをロード pipe.load_lora_weights( ".", weights="lora.safetensors", adapter_name="lora" ) pipe.fuse_lora(lora_scale=0.6) # スケジューラーを設定 (DPM++ 2M Karras) pipe.scheduler = DPMSolverMultistepScheduler.from_config( pipe.scheduler.config, use_karras_sigmas=True, ) # enable memory savings pipe.enable_vae_slicing() # pipe.enable_model_cpu_offload() # エラーになったのでコメントアウト
パイプライン実行
from datetime import datetime from zoneinfo import ZoneInfo # パイプラインの実行 prompts = "省略" negative_prompt = "worst quality, low quality, nsfw, logo, text" image = pipe( prompt, negative_prompt=negative_prompt, guidance_scale=7.5, num_inference_steps=25, ).images[0] # Asia/Tokyo タイムゾーンの現在時刻を YYYYMMDDhhmmss 形式で得る formattedNow = datetime.now(tz=ZoneInfo("Asia/Tokyo")).strftime("%Y%m%d%H%M%S") # ディレクトリを作成する (存在していてもエラーにはしない) image.save(f"{formattedNow}.png")
まとめ
ぬこ