【Stable Diffusion】try to make a high resolution image with Diffusers upscaler
スポンサーリンク
I have used diffusers and LoRA to generate various images.
technoxs-stacker.hatenablog.com
This time I tried to see if I could create a high resolution image
This article is just a reminder, but I hope it will be useful for everyone!
contents
スポンサーリンク
abstract
How to use diffusers and upscaler on Google colab to create high resolution images.
1.requirement
Google Colab
Diffusers
transformers==4.26.0
model : chilloutmix_NiPrunedFp32Fix
upscaler:stabilityai/stable-diffusion-x4-upscaler
2.code
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 = "prompt text"
im = Image.open(save_path).convert("RGB")#save_path:path to image
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.result
normal(552 x 552 pixel)

high resolution(1024 x 1024 pixel)

The image is clearer after the high resolution when compared to the enlarged image.
left:normal / right:high resolution

スポンサーリンク