公開日:2023年2月2日
更新日:2023年2月7日(最新の結果を追加しました)
はじめに
「Tune-A-Video」というのを使ってショート動画を作りました。github.com
やったこと
用意した写真

このようなロボットの写真を数枚用意しました。
結果
上記のロボットがサーフィンしているショート動画を作成しました。いろいろ設定をいじった結果はこちらです。

動作環境
こちらのPCを使用しました。「Tune-A-Video」だけならVRAM 12GBで動作可能です。
Windowsでは「DreamBooth」をVRAM 12GBで動かすことにはまだ成功していません。
WSL2だと「bitsandbytes」が使えるのでVRAM 12GBあればtext encoderのファインチューンも含めて動作可能です。
(こちらを参照)
Windows 11 CUDA 11.6.2 Python 3.10.9
pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116 pip install diffusers[torch]==0.11.1 pip install transformers==4.26.0 pip install decord==0.6.0 pip install tensorboard==2.11.2 pip install modelcards==0.1.6 pip install omegaconf==2.3.0 pip install einops==0.6.0 pip install imageio==2.25.0 pip install ftfy==6.1.1 pip install xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl
xFormersはこちらからダウンロードしてインストールしました。
方法
DreamBoothで学習
こちらですでに完了しています。touch-sp.hatenablog.com
Tune-A-Videoで学習
公式通りに行いました。github.com
推論
from tuneavideo.pipelines.pipeline_tuneavideo import TuneAVideoPipeline from tuneavideo.models.unet import UNet3DConditionModel from tuneavideo.util import save_videos_grid import torch import argparse parser = argparse.ArgumentParser() parser.add_argument( '--model', type=str, required=True, help='model', ) parser.add_argument( '--base_model', type=str, required=True, help='base_model', ) opt = parser.parse_args() model_id = opt.model basemodel_id = opt.base_model unet = UNet3DConditionModel.from_pretrained(model_id, subfolder='unet', torch_dtype=torch.float16).to('cuda') pipe = TuneAVideoPipeline.from_pretrained(basemodel_id, unet=unet, torch_dtype=torch.float16).to("cuda") pipe.enable_xformers_memory_efficient_attention() prompt = "sks robo is surfing on the sea" video = pipe(prompt, video_length=8, height=512, width=512, num_inference_steps=50, guidance_scale=7.5).videos import os save_videos_grid(video, os.path.join('results',f"{basemodel_id}.gif"))
はまりポイント
1
進歩が速くて必ずしも最新のライブラリを集めればよいと言うものでもありません。動作できる環境を見つけるのに最も苦労しました。2
DreamBoothで学習したモデルをTune-A-Videoに渡すとき、unetフォルダ内のconfin.jsonは元のモデル(今回はStable Diffusion-v1-4)のものに替えておく必要があります。それをしないと以下のエラーが出ます。ValueError: unknown mid_block_type : UNetMidBlock2DCrossAttn