前回の記事で SD 1.4 向けの T2I-Adapter をまとめました。
今回の記事では SD 1.5 向けで生成した画像と SD 1.4 向けで生成した画像を比較してみます。
Canny Adapter (SD 1.5)
スクリプト全体
スクリプト全体 (折りたたみ)
事前定義
# Canny Edge を抽出するメソッド def make_canny_condition(image, low_threshold, high_threshold): image = np.array(image) image = cv2.Canny(image, low_threshold, high_threshold) # image = image[:, :, None] # image = np.concatenate([image, image, image], axis=2) return Image.fromarray(image)
※ SD 1.4 向けと同じスクリプトです。
投入画像の準備
import cv2 import numpy as np from diffusers.utils import load_image from PIL import Image # 元画像の準備 init_image_url = "https://huggingface.co/TencentARC/t2iadapter_canny_sd14v1/resolve/main/images/canny_input.png" init_image = load_image(init_image_url) # Canny Edge 画像 canny_image = make_canny_condition(init_image, 100, 200)
※ SD 1.4 向けと同じスクリプトです。
Adapter, Pipeline の準備
import torch from diffusers import T2IAdapter, StableDiffusionAdapterPipeline # アダプターの準備 adapter = T2IAdapter.from_pretrained( "TencentARC/t2iadapter_canny_sd15v2", torch_dtype=torch.float16 ) # パイプラインの準備 pipe = StableDiffusionAdapterPipeline.from_pretrained( "runwayml/stable-diffusion-v1-5", adapter=adapter, torch_dtype=torch.float16, ).to("cuda")
パイプラインの実行
import torch from diffusers.utils import make_image_grid # パイプラインの実行 prompt = "a rabbit wearing glasses" image = pipe( prompt, image=canny_image, generator=torch.Generator("cuda").manual_seed(0), ).images[0] # 出力結果 make_image_grid([init_image, canny_image, image], rows=1, cols=3)
T2I-Adapter-sd14 vs T2I-Adapter-sd15
Sketch Adapter (SD 1.5)
スクリプト全体
スクリプト全体 (折りたたみ)
投入画像の準備
from controlnet_aux import PidiNetDetector from diffusers.utils import load_image # 元画像の準備 init_image_url = "https://huggingface.co/TencentARC/t2iadapter_sketch_sd14v1/resolve/main/images/sketch_in.png" init_image = load_image(init_image_url) # Sketch 画像 detector = PidiNetDetector.from_pretrained('lllyasviel/Annotators') sketch_image = detector(init_image)
※ SD 1.4 向けと同じスクリプトです。
Adapter, Pipeline の準備
import torch from diffusers import T2IAdapter, StableDiffusionAdapterPipeline # アダプターの準備 adapter = T2IAdapter.from_pretrained( "TencentARC/t2iadapter_zoedepth_sd15v1", torch_dtype=torch.float16 ) # パイプラインの準備 pipe = StableDiffusionAdapterPipeline.from_pretrained( "runwayml/stable-diffusion-v1-5", adapter=adapter, safety_checker=None, torch_dtype=torch.float16, variant="fp16" ).to('cuda')
パイプラインの実行
import torch from diffusers.utils import make_image_grid # パイプラインの実行 prompt = "royal chamber with fancy bed" image = pipe( prompt, image=sketch_image, generator=torch.Generator().manual_seed(0) ).images[0] # 出力結果 make_image_grid([init_image, sketch_image, image], rows=1, cols=3)
※ SD 1.4 向けと同じスクリプトです。
T2I-Adapter-sd14 vs T2I-Adapter-sd15
Depth Adapter (SD 1.5)
スクリプト全体
スクリプト全体 (折りたたみ)
投入画像の準備
from controlnet_aux import MidasDetector from diffusers.utils import load_image # 元画像の準備 init_image_url = "https://huggingface.co/TencentARC/t2iadapter_depth_sd14v1/resolve/main/images/depth_input.png" init_image = load_image(init_image_url) # Depth 画像 detector = MidasDetector.from_pretrained("lllyasviel/Annotators") depth_image = detector(init_image)
※ SD 1.4 向けと同じスクリプトです。
Adapter, Pipeline の準備
import torch from diffusers import T2IAdapter, StableDiffusionAdapterPipeline # アダプターの準備 adapter = T2IAdapter.from_pretrained( "TencentARC/t2iadapter_depth_sd15v2", torch_dtype=torch.float16 ) # パイプラインの準備 pipe = StableDiffusionAdapterPipeline.from_pretrained( "runwayml/stable-diffusion-v1-5", adapter=adapter, safety_checker=None, torch_dtype=torch.float16, variant="fp16" ).to('cuda')
パイプラインの実行
import torch from diffusers.utils import make_image_grid # パイプラインの実行 prompt = "storm trooper giving a speech" image = pipe( prompt, image=depth_image, generator=torch.Generator().manual_seed(1) ).images[0] # 出力結果 make_image_grid([init_image, depth_image, image], rows=1, cols=3)
※ SD 1.4 向けと同じスクリプトです。
T2I-Adapter-sd14 vs T2I-Adapter-sd15
ZoeDepth Adapter (SD 1.5)
初見の Zoe Depth とやらですが、スクリプトがエラーになってしまい試すことができませんでした。 具体的には以下の箇所でエラーでした。
RuntimeError Traceback (most recent call last) <ipython-input-4-5dc355c5b894> in <cell line: 61>() 59 return img 60 ---> 61 model = torch.hub.load("isl-org/ZoeDepth", "ZoeD_N", pretrained=True) 62 63 /usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py in load_state_dict(self, state_dict, strict, assign) 2151 2152 if len(error_msgs) > 0: -> 2153 raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( 2154 self.__class__.__name__, "\n\t".join(error_msgs))) 2155 return _IncompatibleKeys(missing_keys, unexpected_keys) RuntimeError: Error(s) in loading state_dict for ZoeDepth: