yumeの日記: ゼロから始める機械学習・画像生成 あすなろ編
昨日の続き。
GPUが早速届いたので早速やっていく。
--
昨日はかなりぼんやりした認識のまま進んでいたが、色々見ていくうちに少しわかってきた。
まず、俺が最初に見た「Stable Diffsionで動画を生成するやつ」はReplicateに公開されているコンテナの一種だ。
Replicateは、オープンソースの機械学習モデルをコンテナとして共有するサイトのようだ。個人個人がgithubやクラウドにアップして、使いたきゃ自分で組めよ~、という状態をなんとかしたみたいな感じらしい。
Stable Diffusion自体もReplicateでコンテナとして公開されている。
つまり、Replicateで公開されているあらゆる機械学習セットは、WSL2で実行してあげればコンテナ組み立てから生成まですぐにやってくれるということだ。すごい。
--
それで……昨日の最後の呪文だけど、これがどうもうまくいかない。
呪文の内容を見るかぎりでは、glid-3-xlのコンテナを組み立ててアボカドの画像を生成しようとしているらしいが、「Loading latent diffusion model from inpaint.pt」のラインでタイムアウトしてしまう。Latent diffusion modelが何を指すかはよくわからん。
とにかく、glid-3-xlはStable Diffusionのヴァリアントのようだ。
最終的な目的は、動画を生成することだったので、ここでは無理にコレにこだわる必要はなさそうである。
というわけで、Stable Diffusionの方を実行してみることにした。
入力は次のとおり。
引数がstringの部分は""で囲ってやる必要があるようだ。
cog predict r8.im/stability-ai/stable-diffusion@sha256:a9758cbfbd5f3c2094457d996681af52552901775aa2d6dd0b17fd15df959bef \
-i prompt="tall rectangular black monolith, monkeys in the desert looking at a large tall monolith, a detailed matte painting by Wes Anderson, behance, light and space, reimagined by industrial light and magic, matte painting, criterion collection" \
-i width=512 \
-i height=512 \
-i prompt_strength=0.8 \
-i num_outputs=1 \
-i num_inference_steps=50 \
-i guidance_scale=7.5
書き出せた画像はコレ。すんなり成功した。
各パラメータの意味はちょっとわからないが、widthとheightくらいはわかる。フルHD(1920x1080)の画像を書き出したいところだが、対応する解像度は 128, 256, 512, 768, 1024 の5段階らしい。
近い比率のwidth=1024, height=768で試す。
しかし……。
RuntimeError: CUDA out of memory. Tried to allocate 9.00 GiB (GPU 0; 24.00 GiB total capacity; 7.27 GiB already allocated; 5.13 GiB free; 16.24 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF
ⅹ /predictions call returned status 500
なんとメモリが足りないエラーが返ってきた。そんなぁ。RTX 3090でも太刀打ちできんとは。
ちょっと対処法を調べよう。
Minerva曰く、低VRAM用に最適化された低速なバージョンもあるらしい。
しかしこれはReplicateにはないな……。
まぁいいか。高解像度化するモデルもReplicateにはあるし、静止画に関してはとりあえず一旦置いておく。
--
次は動画を書き出してみよう。
deforum_stable_diffusionを試す。
入力は次のとおり。
cog predict r8.im/deforum/deforum_stable_diffusion@sha256:e22e77495f2fb83c34d5fae2ad8ab63c0a87b6b573b6208e1535b23b89ea66d6 \
-i max_frames=100 \
-i animation_prompts="0: a beautiful portrait of a woman by Artgerm, trending on Artstation" \
-i angle="0:(0)" \
-i zoom="0: (1.04)" \
-i translation_x="0: (0)" \
-i translation_y="0: (0)" \
-i color_coherence="Match Frame 0 LAB" \
-i sampler="plms" \
-i fps=24
しかし……。エラーで終了。メッセージは:ⅹ Failed to get container status: exit status 1
モデルの読み込みまではうまくいっていたようだが……。ちょっと対処法がわからないな。
もう一個の動画用コンテナを試してみよう。
stable-diffusion-animationは、始まりと終わりの画像をプロンプトで指定してやると、メキメキと動く動画が書き出せるらしい。
入力は次のとおり。
cog predict r8.im/andreasjansson/stable-diffusion-animation@sha256:b8cb0e3516a1383a46ed5d773b11d495fe39cf921b3d79ce5407ab980494f75b \
-i prompt_start="tall rectangular black monolith, monkeys in the desert looking at a large tall monolith, a detailed matte painting by Wes Anderson, behance, light and space, reimagined by industrial light and magic, matte painting, criterion collection" \
-i prompt_end="tall rectangular black monolith, a white room in the future with a bed, victorian details and a tall black monolith, a detailed matte painting by Wes Anderson, behance, light and space, reimagined by industrial light and magic, matte painting, criterion collection" \
-i width=512 \
-i height=512 \
-i num_inference_steps=50 \
-i prompt_strength=0.9 \
-i num_animation_frames=25 \
-i num_interpolation_steps=5 \
-i guidance_scale=7.5 \
-i gif_frames_per_second=20 \
-i gif_ping_pong=true \
-i film_interpolation=true \
-i intermediate_output=false \
-i output_format="mp4"
結果はコレ。すごい。
しかもこっちは解像度を指定できる。使用したVRAMは18GB弱だったかな。
--
これで一通り動画が書き出せるようになったので、次は解像度をどうするかとか考えていく。
ゼロから始める機械学習・画像生成 あすなろ編 More ログイン