【Mixture of Diffusers】Outpaintingのようなものに挑戦。(建物の写真に空を追加)


左が元の建物の画像です。右が空を追加した画像です。
github.com

環境構築

Windows 11
Python 3.10
CUDA 11.7
pip install torch==2.0.1+cu117 torchvision==0.15.2+cu117 --index-url https://download.pytorch.org/whl/cu117
pip install git+https://github.com/huggingface/diffusers.git
pip install accelerate transformers safetensors scipy

実行

準備

こちらから画像(IIC.png)をダウンロードさせて頂きました。

Diffusersのリポジトリから「mixture_canvas.py」をダウンロードして51行目を変更しました。

self.region_seed = np.random.randint(9999999999)

「9999999999」の数字が大きすぎることによって以下のエラーが出ます。

ValueError: high is out of bounds for int32

適当に数字を下げて下さい。自分は3桁削除しました。

Pythonスクリプト

from PIL import Image
from diffusers import LMSDiscreteScheduler
from mixture_canvas import StableDiffusionCanvasPipeline, Image2ImageRegion, Text2ImageRegion, preprocess_image

# Load and preprocess guide image
iic_image = preprocess_image(Image.open("IIC.png").convert("RGB"))

# Creater scheduler and model (similar to StableDiffusionPipeline)
scheduler = LMSDiscreteScheduler(beta_start=0.00085, beta_end=0.012, beta_schedule="scaled_linear", num_train_timesteps=1000)
pipeline = StableDiffusionCanvasPipeline.from_pretrained(
    #"CompVis/stable-diffusion-v1-4,
    "./stable-diffusion-v1-4", 
    scheduler=scheduler)

pipeline.to("cuda")

image = pipeline(
    canvas_height=800,
    canvas_width=352,
    regions=[
        Text2ImageRegion(0, 800, 0, 352, guidance_scale=8,
            prompt=f"Christmas postcard, a charming house in the countryside surrounded by snow, a giant christmas tree, under a starry night sky, by jakub rozalski and alayna danner and guweiz, elegant, highly detailed, smooth, sharp focus, artstation, stunning masterpiece"),
        Image2ImageRegion(800-352, 800, 0, 352, reference_image=iic_image, strength=0.9),
    ],
    num_inference_steps=57,
    seed=5525475061,
)["images"][0]

image.save('result.png')




このエントリーをはてなブックマークに追加