Improving the Stability of Diffusion Models for Content Consistent Super-Resolution
Paper β’ 2401.00877 β’ Published
How to use kharma1/ccsr_v2_repost with Diffusers:
pip install -U diffusers transformers accelerate
from diffusers import ControlNetModel, StableDiffusionControlNetPipeline
controlnet = ControlNetModel.from_pretrained("kharma1/ccsr_v2_repost")
pipe = StableDiffusionControlNetPipeline.from_pretrained(
"stabilityai/stable-diffusion-2-1-base,isometricneko/stable-diffusion-v2.1-clone", controlnet=controlnet
)This repository hosts the pre-trained weights for CCSR-v2 (Continuous Latent Diffusion for Image Super-Resolution), optimized for stable and step-flexible image upscaling.
This model repost contains the following folders:
stable-diffusion-2-1-base/ - Standard components of the Stable Diffusion 2.1 base model.controlnet/ - Custom ControlNet weights trained for Stage 1 of CCSR.vae/ - Fine-tuned VAE weights trained for Stage 2 of CCSR.To run super-resolution with these weights, you can use the official ccsr-pruned Python library.
pip install ccsr-pruned
# or using uv
uv add ccsr-pruned
import torch
from PIL import Image
from diffusers import AutoencoderKL
from ccsr import StableDiffusionControlNetCCSRPipeline, ControlNetCCSRModel
# Load the models using this Hugging Face repository as the source
repo_id = "kharma1/ccsr_v2_repost"
# 1. Load ControlNet, VAE, and Pipeline
controlnet = ControlNetCCSRModel.from_pretrained(repo_id, subfolder="controlnet", torch_dtype=torch.float16)
vae = AutoencoderKL.from_pretrained(repo_id, subfolder="vae", torch_dtype=torch.float16)
pipeline = StableDiffusionControlNetCCSRPipeline.from_pretrained(
f"{repo_id}/stable-diffusion-2-1-base",
controlnet=controlnet,
vae=vae,
torch_dtype=torch.float16,
).to("cuda")
# 2. Prepare low-quality input image (upscaled and divisible by 8)
lq_image = Image.open("input_lq.png").convert("RGB")
upscale_factor = 4
target_width = lq_image.size[0] * upscale_factor // 8 * 8
target_height = lq_image.size[1] * upscale_factor // 8 * 8
resized_image = lq_image.resize((target_width, target_height))
# 3. Generate High-Resolution Image
output = pipeline(
t_max=0.6667,
t_min=0.0,
tile_diffusion=True, # Saves VRAM on large images
tile_size=512,
tile_stride=256,
prompt="clean, high resolution, sharp details",
negative_prompt="blurry, low quality, noise, artifacts",
image=resized_image,
num_inference_steps=10,
guidance_scale=5.0,
conditioning_scale=1.0,
start_steps=19,
start_point="lr",
use_vae_encode_condition=True,
)
# 4. Save result
output.images[0].save("output_sr.png")
This work is based on the paper "Improving the stability and efficiency of diffusion models for content consistent super-resolution". If you use these models, please cite the original authors:
@article{sun2024improving,
title={Improving the stability and efficiency of diffusion models for content consistent super-resolution},
author={Sun, Lingchen and Wu, Rongyuan and Liang, Jie and Zhang, Zhengqiang and Yong, Hongwei and Zhang, Lei},
journal={arXiv preprint arXiv:2401.00877},
year={2024}
}
Base model
isometricneko/stable-diffusion-v2.1-clone