画像生成AI stable-diffusionのImg2ImgとGoogle Colabで画像生成AIの画像をブラッシュアップする無料の方法
(2022/08/31 image_to_image.pyの更新を概要欄に反映しました)画像生成AI stable-diffusionさんのimg2img(StableDiffusionImg2ImgPipeline)をGoogle Colabさんで使うため、gitとpipを組み合わせてデフォルトのディレクトリにインストールしました。
0:00 stable-diffusion Img2Imgとは
0:11 Hugging Faceでの手順
【huggingface】
すでに「Access repository」まで完了していればSkipできます。
https://huggingface.co/
・Sing Upする。
・Sing Upで入力したメールアドレスにメールが届いているのでConfirmする。
・https://huggingface.co/settings/tokens で、Tokenをreadで新規作成する。
・https://huggingface.co/CompVis/stable-diffusion-v1-4 で合意のチェックボタンを入れてからAccess repositoryのボタンを押す。
0:38 Google Colabでの手順
【Google Colab】
https://colab.research.google.com/?hl=ja
編集メニュー > ノートブックの設定 > GPU を選択して保存。
!nvidia-smi
GPUの割り当て状況の確認用です。
!pip install transformers scipy ftfy
!git clone https://github.com/huggingface/diffusers.git
!pip install git+https://github.com/huggingface/diffusers.git
from huggingface_hub import notebook_login
notebook_login()
出てくるログイン画面にhuggingfaceさんで取得したTokenを入力します。
!git config --global credential.helper store
%cd diffusers
廃止:from examples.inference.image_to_image import StableDiffusionImg2ImgPipeline, preprocess:廃止
from diffusers import StableDiffusionImg2ImgPipeline
from PIL import Image
元になる画像「source.png」を、diffusersにドラッグアンドドロップします。
注: アップロードしたファイルはランタイムのリサイクル時に削除されます。
img = Image.open("source.png")
import torch
from torch import autocast
pipeimg = StableDiffusionImg2ImgPipeline.from_pretrained(
"CompVis/stable-diffusion-v1-4",
revision="fp16",
torch_dtype=torch.float16,
use_auth_token=True
).to("cuda")
init_image = img.resize((512, 512))
# 追加
import numpy as np
import PIL
def preprocess(image):
w, h = image.size
w, h = map(lambda x: x - x % 32, (w, h)) # resize to integer multiple of 32
image = image.resize((w, h), resample=PIL.Image.LANCZOS)
image = np.array(image).astype(np.float32) / 255.0
image = image[None].transpose(0, 3, 1, 2)
image = torch.from_numpy(image)
return 2.*image - 1.
init_image = preprocess(init_image)
prompt = "A kawaii vtuber."
with autocast("cuda"):
images = pipeimg([prompt], init_image=init_image, strength=0.75, guidance_scale=7.5)["sample"]
images[0].save("new_image.png")
2:1 クロージング
【配信後記】
最初は、img2img.pyを使おうとしたのですが、この やり方ですと、ldm.pyさんが「SyntaxError: Missing parentheses in call to 'print'. Did you mean print(self.face_rec_model_path)?」で止まってしまうのでローカルのパッケージとしてimage_to_image さんをimportする使い方を選びました。
https://github.com/huggingface/diffusers/blob/main/examples/inference/image_to_image.py が更新されて、「ImportError: cannot import name 'preprocess' from 'examples.inference.image_to_image' (/content/diffusers/examples/inference/image_to_image.py)」となってしまうため、手順を更新しました。2022/08/31
参考:https://colab.research.google.com/github/patil-suraj/Notebooks/blob/master/image_2_image_using_diffusers.ipynb
髪形:墓守さんチーム(HakamorisanTeam)様 ショートレイヤー(男女兼用) VRoid用ヘアプリセット https://booth.pm/ja/items/2198514
瞳:なお屋(Nao-ya)様 (無料あり)【VRoid向け瞳テクスチャ】宇宙スイング★バイカラーアイ https://booth.pm/ja/items/2574261
衣装:Lagrangesix 【lotz Design Store】様 VRoid正式版対応済☆★L6 Gothic Sailor (Color×5)★☆試着有【VroidStudio正式版用衣装テクスチャ】 https://lotz.booth.pm/items/3129935
ネイル:なおしま(7a04m)様 (無料あり)【VRoid用テクスチャ】大理石ネイル https://7a04m.booth.pm/items/2580306
アイメイク:やまろん製作所 様 【VRoid 旧Ver】アイメイク3種 https://booth.pm/ja/items/2738511
#aivtuber
#stablediffusion
#人工知能
Видео 画像生成AI stable-diffusionのImg2ImgとGoogle Colabで画像生成AIの画像をブラッシュアップする無料の方法 автора API JavaScript
Видео 画像生成AI stable-diffusionのImg2ImgとGoogle Colabで画像生成AIの画像をブラッシュアップする無料の方法 автора API JavaScript
Информация
4 декабря 2023 г. 17:23:15
00:02:15
Похожие видео