
【AI画像生成】(初心者向け)Google Colabを使って、無料でStable Diffusionで、美男美女アバターを作ろう!
低スペックマシンでもGoogle ColabでStableDiffusionが動かせる
最近流行りの生成AIで有名な画像生成。Stable Diffusionがメジャーな技術なんですが、GPU積んだPCしかできないと思っていました。
Midjourneyなどのオンラインのシステムは割と遅いし、いろいろ試すには不便。
そんな中、
【AI画像生成】Google ColabでStable Diffusion web UIを動かす方法」
なる記事があり早速試してみました。
なんと5分で設定完了!(無料でとありますが、Google Colabへの課金が必要です)




とこんな感じでKpop アイドル風の美男、美女の画像を生成することができます。
いまさらだけど、google colabで、stable diffusion動かして、自撮りから韓国風イケメンアバターを生成してもらったけど、どうだろう?
— Toshi⁷ MD,PhD 🇺🇸|アメリカで研究&開発 (@tokitky) July 3, 2023
定番だけどモデルはchilloutmixが良さそう!Pythonでちょっことやれば無料で好きなだけ作れるの良いかも?#stablediffusion#PyTorch pic.twitter.com/1Vz4S2AyIz
興味の設定方法は?
(以下貼り付け開始)
「AUTOMATIC1111/stable-diffusion-webui」を使う(方法その1)
つづいて、「AUTOMATIC1111/stable-diffusion-webui(https://github.com/AUTOMATIC1111/stable-diffusion-webui)」を、Colabで使う方法です。
まずはGoogleにログインして、Colabのページ(https://colab.research.google.com/?hl=ja)に移動しましょう。
「ノートブックを新規作成」をクリックして、新しいノートブックを作成します

「編集」から「ノートブックの設定」をクリックします。

「ハードウェア アクセラレータ」を「GPU」に変更し、「保存」をクリックします。

さらに、次のコマンドをノートにコピペします。
モデルは、ご自身が使いたいものに書きかえてください。
(貼り付け終わり)
とこれだけなんです。モデルはいろいろ調べたところ、Chilloutmixが実写系には良いようなので、
!git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
%cd /content/stable-diffusion-webui
!wget https://huggingface.co/ckpt/chilloutmix/resolve/main/chilloutmix_NiPrunedFp32Fix.safetensors -O /content/stable-diffusion-webui/models/Stable-diffusion/chilloutmix_NiPrunedFp32Fix.safetensors
!python launch.py --share --xformers --enable-insecure-extension-access
コードはこれで完了です。
これをrunすると

このような画面が出てくるのでこれを実行したまま、Running on Public URL のところにあるハイパーリンクを押してください。
いよいよ画像生成
Stable diffusionのworking 画面が出てきます。
Stable Diffusion Checkpointがchillout mixになっていることを確認し、

あとはプロンプト(呪文)を入れて、サンプリングステップと、サンプリングメソッドを入れると、画像が勝手に生成されます。
各種呪文についてはchichi-puiなどのサイトが詳しいです。
例えばこのkpopのお姉さんを出すのであれば、

promptは
masterpiece,(1 girl:1.2),(photorealistic:1.3),((24yo:1.3)), (((1 girl, Korean, kpop))),((brown contacts, sweaty white skin)), beautiful detailed eyes, (beautiful), fashion models, kpop, kpop idol, 8k,(( taken by a professional photographer)) ,(((wearing a black jacket, T-shirt))),beautiful detailed eyes, (face focus), looking into the camera, short black hair, (((screen background))), (dark colored clothes),
Negative promptは
EasyNegative, paintings, sketches, ugly,bad_anatomy,bad_hands,extra_hands,missing_fingers,broken hand,more than two hands,well proportioned hands,more than two legs,unclear eyes,missing_arms,mutilated,extra limbs,extra legs,cloned face,fused fingers,extra_digit, fewer_digits,extra_digits,jpeg_artifacts,signature,watermark,username,blurry, (worst quality:2), (low quality:2), (normal quality:2), lowres, ((monochrome)), ((grayscale)), skin spots, acnes, skin blemishes, age spot,((watermark:2)),((white letters:1.5)), mirror image, Vague , (((chest hair)))
となります。
またその他の設定はその下の部分に入れることになります。
Sampling Method: DPM++ SDE Keras
Step: 30
Width: 512 Hight: 512,
seeds -1
基本的にはサンプリングメソッドとステップ以外はいじらなくて大丈夫です。
これで上のGenerateというボタンを押すと画像生成ができ、できた画像はダウンロードできます。
なお何回か生成しているうちにGoogle Colabとのコネクションが切れるようですので、その場合はコードをrunし直してください。
自分の画像を元にアバターを作るには?
実はstable diffusionの画像生成のde faultはテキストからの画像合成(text2img)だったのですが、メニューのタブには(img2img)というものがあり、
自撮りなどの画像を利用して自分の写真に基づいたアバターや画像を作ることができます。
具体的にはこんな感じ

男性から男性、もしくは女性から男性であれば
プロンプトは
masterpiece,(1 boy:1.2),(photorealistic:1.3),((29yo:1.3)), (((1 girl, Korean, kpop))),((brown contacts, sweaty white skin)), beautiful detailed eyes, (beautiful), fashion models, kpop, kpop idol, 8k,(( taken by a professional photographer)) ,(((wearing a black jacket, T-shirt))),beautiful detailed eyes, (face focus), looking into the camera, short black hair, (((screen background))), (dark colored clothes),
ネガティブプロンプトは
EasyNegative, paintings, sketches, ugly,bad_anatomy,bad_hands,extra_hands,missing_fingers,broken hand,more than two hands,well proportioned hands,more than two legs,unclear eyes,missing_arms,mutilated,extra limbs,extra legs,cloned face,fused fingers,extra_digit, fewer_digits,extra_digits,jpeg_artifacts,signature,watermark,username,blurry, (worst quality:2), (low quality:2), (normal quality:2), lowres, ((monochrome)), ((grayscale)), skin spots, acnes, skin blemishes, age spot,((watermark:2)),((white letters:1.5)), mirror image, Vague , (((chest hair)))
後の設定は先ほどと同じで
Sampling Method: DPM++ SDE Keras
Step: 30
Width: 512 Hight: 512,
seeds -1
kpopアイドルのような美男系のアイコンが作れると思います。
いまさらだけど、google colabで、stable diffusion動かして、自撮りから韓国風イケメンアバターを生成してもらったけど、どうだろう?
— Toshi⁷ MD,PhD 🇺🇸|アメリカで研究&開発 (@tokitky) July 3, 2023
定番だけどモデルはchilloutmixが良さそう!Pythonでちょっことやれば無料で好きなだけ作れるの良いかも?#stablediffusion#PyTorch pic.twitter.com/1Vz4S2AyIz
男性から女性、女性から女性も同様
プロンプトが
ここから先は
¥ 300
この記事が気に入ったらチップで応援してみませんか?