Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Lets Finetune Stable Diffusion
Search
payanotty
April 06, 2023
Technology
1.4k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Lets Finetune Stable Diffusion
payanotty
April 06, 2023
More Decks by payanotty
See All by payanotty
トークナイザー入門
payanotty
5
2.8k
LLM_Prompt_Recovery
payanotty
3
1.1k
Embeddingモデルを使ったベクトル化のしくみ、fine-tuning手法を解説
payanotty
15
6.6k
Transformerによるテキストベクトル化を解説
payanotty
6
4.4k
Kaggle_LLMコンペの攻略法を解説.pdf
payanotty
1
1.7k
ManimMLでイケてるアニメーションを作ろう
payanotty
0
870
Lets Finetune LLM
payanotty
3
1.5k
Stable Diffusion Web UI, Let Your Fave Eat Ramen
payanotty
1
1.2k
Deffusion解説
payanotty
3
1.1k
Other Decks in Technology
See All in Technology
LLM機能を自作して分かるSnowflake Cortex AIの強み
nayuts
0
270
大阪オフィスに Unitree Go2 がやってきたので Physical AI やってみた
dafujii
0
290
生成AIを使って「人が」考える技術 ― AI時代の人機共想と実践ノウハウ|UNITT AC2026
ishiirikie
0
550
AI時代のAPI開発を加速する品質ガードレール / API Quality Guardrails in the AI Era
yokawasa
0
120
AIに攻撃される前に、AIに攻撃させる
tsuchikazu
0
140
おそらく日本で唯一のDevRelインターン生として
husengs7
0
170
freeeらしさをAIとともに作る / Creating the freee Experience with AI
ymrl
0
190
生成AIと進める探索的データ分析(2026.10.03 第122回Tokyo.R勉強会)
tatamiya
2
1.4k
AIアプリを使い分けるための共通ツール基盤を考えてみる#devio2026
osawa
0
220
自主式軟體工廠
philipz
0
200
検証フェーズはAIの回答を判断するための学習機会
toru_kubota
2
490
転んだ話が背中を預ける理由になる / A_story_about_falling_down_gives_you_a_reason_to_watch_each_other_s_backs.pdf
pauli
2
180
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
710
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
560
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
260
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
250
Technical Leadership for Architectural Decision Making
baasie
3
590
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
It's Worth the Effort
3n
188
29k
RailsConf 2023
tenderlove
30
1.6k
Are puppies a ranking factor?
jonoalderson
2
4k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
Transcript
Stable Diffusionで 自分だけの お絵描きAIを作ろう 早野康太
自己紹介 • 名前 ◦ 早野 康太 • お仕事 ◦ 自然言語モデルの改善
• 春アニメおすすめ ◦ 僕ヤバ ◦ 水星の魔女 第2期 • 映画 ◦ BLUE GIANT → 神でした (原作一気買い)
Stable Diffusionとは • 文章を与えると画像を生成してくれるモデル • 2022年にStability AIが公開 ◦ Google Colaboratoryを使えばサクッと試せる
▪ https://huggingface.co/stabilityai/stable-diffusion-2
Stable Diffusionとは • モデルを誰でも利用できるため Stable Diffusionを使ったサービスや派生モデルの公開など さかんに行われている ◦ 画像生成bot ▪
Line, Discordなど ◦ 派生モデル ▪ NovelAI Diffusion ▪ Waifu Diffusion ▪ ほか、Huggingfaceで検索したら無限に出てくる • Models - Hugging Face
Stable Diffusionとは • Stable Diffusion ◦ 誰でも利用できる → 自分だけのオリジナルモデルを作成可能 ◦
lambdalabs/sd-pokemon-diffusers · Hugging Face
今回の発表では • Stable Diffusionをfine-tuneして オリジナルモデルを作成するデモを Google Colaboratoryで実践します ◦ データセットの作成→学習→モデル保存&ロードまでを ノートブックで完結させます
▪ 学習用notebook
前提とする知識 • PyTorch ◦ 今日お見せする学習コードはPyTorchで書かれています ◦ 最低限PyTorchで簡単なNN学習を実装できる程度の知識は必要です • 機械学習 ◦
深層学習の基本的な用語の意味については知っている前提で 進めます
アジェンダ • データセットの作成 ◦ 画像の収集 ◦ キャプション付け ▪ BLIPを利用して自動でキャプションをつけよう •
学習 ◦ Stable Diffusionの学習のやり方 ◦ 学習コードの解説 • 推論 ◦ 作ったモデルで画像を生成してみる
データセットの作成 • データセットの構成 ◦ 画像とキャプションが1対1に対応したもの 出典:ぼっち・ざ・ろっく! CloverWorks、アニプレックス、芳文社、 ©はまじあき/芳文社・アニプレックス キュビズムみたいな作画になった 後藤ひとり
画像 キャプション ×N
データセットの作成 • 画像収集 ◦ Safebooru (画像投稿サイト) のAPIを利用して収集 ▪ “umamusume”タグで絞り込んで15,000枚 •
キャプション付け ◦ BLIP: Bootstrapping Language-Image Pre-training for Unified Vision-Language Understanding and Generation ▪ 2022年1月に論文で発表されたモデル ▪ 画像を入力として その画像に即したキャプションを出力できる
データセットの作成 image file caption path/to/image1.png a group of cartoon
animals sitting next to ... path/to/image2.png an anime girl with long hair and a bow in her ... path/to/image3.png a couple of anime girls laying on top of a bed csv 画像ファイル
Stable Diffusionの学習 VAE VAE Denoising Autoencoder (UNET) Text Encoder input
text 出典:ぼっち・ざ・ろっく! CloverWorks、アニプレックス、芳文社、 ©はまじあき/芳文社・アニプレックス
Stable Diffusionの学習 VAE VAE Denoising Autoencoder (UNET) Text Encoder input
text 今回はここだけ 学習する 出典:ぼっち・ざ・ろっく! CloverWorks、アニプレックス、芳文社、 ©はまじあき/芳文社・アニプレックス
Stable Diffusionの学習 x 0 x 1 = x
0 + ε 1 x 2 = x 1 + ε 2 x 3 = x 2 + ε 3 z 1 = x 0 - ε θ (z 0 , 0) z 2 = z 1 - ε θ (z 1 , 1) z 3 = z 2 - ε θ (z 2 , 2) 出典:ぼっち・ざ・ろっく! CloverWorks、アニプレックス、芳文社、 ©はまじあき/芳文社・アニプレックス z 0
Stable Diffusionの学習 x 0 x 1 = x
0 + ε 1 x 2 = x 1 + ε 2 x 3 = x 2 + ε 3 z 1 = x 0 - ε θ (z 0 , 0) z 2 = z 1 - ε θ (z 1 , 1) z 3 = z 2 - ε θ (z 2 , 2) 出典:ぼっち・ざ・ろっく! CloverWorks、アニプレックス、芳文社、 ©はまじあき/芳文社・アニプレックス z 0 各タイムステップにおいて 付加したノイズをターゲットとして ロスを計算する
Stable Diffusionの学習 raw pixel value VAE latent noisy
latent + noise input text Text Encoder embedding UNET prediction loss velocity
Stable Diffusionの学習 raw pixel value VAE latent noisy
latent + noise input text Text Encoder embedding UNET prediction loss velocity 前処理
余談: velocityってなんぞ? x : 画像の値 ε : ノイズの値
z = αx + σε • Stable Diffusion 1.0 ◦ εがターゲット • Stable Diffusion 2.0 ◦ vがターゲット ※理屈がわかっていないため深入りしません α, σ : ノイズ付与のハイパラ (タイムステップごとに変動) v = dz / dφ Progressive Distillation for Fast Sampling of Diffusion Models
学習してみた結果 • 作りたかったモデル ◦ ウマ娘風の絵柄でイラストを生成するAI (3期も始まるので備えたい) • データセット
◦ 画像 ▪ Safebooru APIを使い”umamusume”タグで 収集した画像(10,000 - 15,000枚) ◦ キャプション ▪ 収集した画像をもとにBLIPで生成 • モデル ◦ backbone ▪ stabilityai/stable-diffusion-2
素のStable Diffusion • プロンプト ◦ “a girl in a
maid outfit holding a teapot”
UMA Diffusion • プロンプト ◦ “a girl in a
maid outfit holding a teapot” • 画像数: 10,000 • ハイパラ ◦ epochs: 30 ◦ batch_size: 4 ◦ lr: 5e-6 ◦ lr_scheduler: cosine ◦ warmup_ratio: 0.06 ◦ resolution: 512x512 ◦ transforms ▪ RandomCrop
UMA Diffusion • プロンプト ◦ “a girl in a
maid outfit holding a teapot” • 画像数: 15,000 • ハイパラ ◦ epochs: 30 ◦ batch_size: 4 ◦ lr: 5e-6 ◦ lr_scheduler: cosine ◦ warmup_ratio: 0.06 ◦ resolution: 512x512 ◦ transforms ▪ RandomCrop
UMA Diffusion • プロンプト ◦ “a girl in a
maid outfit holding a teapot” • 画像数: 10,000 • ハイパラ ◦ epochs: 30 ◦ batch_size: 4 ◦ lr: 5e-6 ◦ lr_scheduler: cosine ◦ warmup_ratio: 0.06 ◦ resolution: 512x384 ◦ transforms ▪ RandomCrop
UMA Diffusion • プロンプト ◦ “a girl in a
maid outfit holding a teapot” • 画像数: 15,000 • ハイパラ ◦ epochs: 30 ◦ batch_size: 4 ◦ lr: 5e-6 ◦ lr_scheduler: cosine ◦ warmup_ratio: 0.06 ◦ resolution: 512x384 ◦ transforms ▪ RandomCrop
finetune方法発展 • 今回はシンプルなfinetuneを紹介したが さまざまなfinetune手法が提案されている ◦ Text Inversion ▪ An
Image is Worth One Word: Personalizing Text-to-Image Generation using Textual Inversion ◦ DreamBooth ▪ DreamBooth: Fine Tuning Text-to-Image Diffusion Models for Subject-Driven Generation ◦ Hypernetworks ▪ NovelAI Improvements on Stable Diffusion ◦ LoRA ▪ GitHub - cloneofsimo/lora: Using Low-rank adaptation to quickly fine-tune diffusion models.
やってみた所感 • DNNの学習を触ったことがあるなら 学習コードを回すこと自体は全然難しくない ◦ 計算資源の確保が大変 (GPUメモリ16GB以上推奨) • 10,000枚程度の画像でもある程度のクオリティの
モデルを学習できた ◦ とはいえ安定したクオリティの出力は難しい ◦ 特に手の作画は崩れてしまう • よりクオリティを追求しようとするなら 発展的な手法を使ったfinetuneを試したいところ (いずれ挑戦したい)