CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
huggingface

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: huggingface/notebooks
Path: blob/main/diffusers/latent_diffusion_upscaler.ipynb
Views: 2535
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)

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]
upscaled_image
Image in a Jupyter notebook