スポンサーリンク
これまでdiffusersとLoRAを使っていろんな画像を生成してきました
technoxs-stacker.hatenablog.com
目次
スポンサーリンク
この記事でわかること
Google colab上でdiffusersとupscalerを使って高解像度の画像を作る方法
1.実行環境
Google Colab
Diffusers
transformers==4.26.0
model : chilloutmix_NiPrunedFp32Fix
upscaler:stabilityai/stable-diffusion-x4-upscaler
2.生成コード
from diffusers import StableDiffusionUpscalePipeline def upscale(pipe, prompt, img, step=100): return pipe(prompt=prompt, image=img, num_inference_steps=step, guidance_scale=0).images[0] # make pipeline pipe_upscaler = StableDiffusionUpscalePipeline.from_pretrained("stabilityai/stable-diffusion-x4-upscaler", torch_dtype=torch.float16, revision="fp16") pipe_upscaler = pipe_upscaler.to("cuda") prompt = "任意のプロンプトを指定" im = Image.open(save_path).convert("RGB")#save_pathは画像の保存先を指定 low_res_img = im.resize((256, 256)) step = 200 pipe_upscaler(prompt=prompt, image=low_res_img, num_inference_steps=step, guidance_scale=0).images[0]
3.作成画像
通常(552 x 552 pixel)
高解像度後(1024 x 1024 pixel)
拡大比較してみると高解像度後のほうが、鮮明になりました
左:通常 / 右:高解像度後
スポンサーリンク