Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
huggingface
GitHub Repository: huggingface/notebooks
Path: blob/main/diffusers/latent_diffusion_upscaler.ipynb
5906 views
Kernel: Python 3

Open In Colab

Image super-resolution using Latent Diffusion

This colab notebook shows how to use the Latent Diffusion image super-resolution model using 🧨 diffusers libray.

The model was originally released in Latent Diffusion repo. It's a simple, 4x super-resolution model diffusion model. This model is not conditioned on text.

Install the Deps

!pip install -qq diffusers==0.11.1 accelerate
Installing build dependencies ... done Getting requirements to build wheel ... done Preparing wheel metadata ... done |████████████████████████████████| 175 kB 5.1 MB/s |████████████████████████████████| 182 kB 46.5 MB/s Building wheel for diffusers (PEP 517) ... done

Imports

import torch from PIL import Image import requests from io import BytesIO from diffusers import LDMSuperResolutionPipeline

Load the pipeline

device = "cuda" pipe = LDMSuperResolutionPipeline.from_pretrained( "CompVis/ldm-super-resolution-4x-openimages") pipe = pipe.to(device)
Fetching 6 files: 0%| | 0/6 [00:00<?, ?it/s]

Get the image for demo

# let's download an image url = "https://i.pinimg.com/236x/af/84/56/af8456faa55d76bd9afa18cd2fd72d58.jpg" response = requests.get(url) low_res_img = Image.open(BytesIO(response.content)).convert("RGB") low_res_img = low_res_img.resize((128, 128)) low_res_img
Image in a Jupyter notebook

Run pipeline to upscale the image

# run pipeline in inference (sample random noise and denoise) upscaled_image = pipe(low_res_img, num_inference_steps=100, eta=1).images[0]
0%| | 0/100 [00:00<?, ?it/s]
upscaled_image
Image in a Jupyter notebook