Downloads · 30 days
163
16% of all-time downloads
Mou11209203/ddpm-celebahq-256
ddpm-celebahq-256 is a unconditional image generation model from Mou11209203. Use it for the unconditional image generation task on the model card, and read the license before you ship it in a product. It is set up for diffusers. The card lists the license as apache-2.0.
This repository contains a denoising diffusion probabilistic model (DDPM) trained on the CelebA HQ dataset at a resolution of 256x256. The model is based on the original google/ddpm-celebahq-256 implementation and has…
Downloads · 30 days
163
16% of all-time downloads
All-time downloads
1K
Public
Parameters
114M
455 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors455 MB · 98%
From the Hugging Face model README
This repository contains a denoising diffusion probabilistic model (DDPM) trained on the CelebA HQ dataset at a resolution of 256x256. The model is based on the original google/ddpm-celebahq-256 implementation and has been updated to support safetensors for model storage.
UNet2DModelsafetensors.safetensors format, a safer and more efficient.Here are some sample images generated by the model at different diffusion steps:



To use this model, you can load it using the diffusers library from Hugging Face. You can load the model in safetensors format.
pip install torch diffusers safetensors
environment.yml file.
conda env create --file environment.yml
conda activate inpaint
To load the model and run inference, you can use the following code:
import torch
import numpy as np
import PIL.Image
from diffusers import UNet2DModel, DDPMScheduler
import tqdm
# 1. Initialize the model
# Choose a model ID, use google's with use_safetensors=False, use Mou11209203's with use_safetensors=True
repo_id = "google/ddpm-celebahq-256"
repo_id1 = "Mou11209203/ddpm-celebahq-256"
model = UNet2DModel.from_pretrained(repo_id1, use_safetensors=True)
model.to("cuda") # Move the model to GPU
print("model.config: ", model.config)
# 2. Initialize the scheduler
scheduler = DDPMScheduler.from_pretrained(repo_id1)
print("scheduler.config: ", scheduler.config)
# 3. Create an image with Gaussian noise
torch.manual_seed(1733783271) # Fix the random seed for reproducibility
noisy_sample = torch.randn(1, model.config.in_channels, model.config.sample_size, model.config.sample_size).to("cuda")
print(f"Noisy sample shape: {noisy_sample.shape}")
# 4. Define a function to display the image
def display_sample(sample, i):
image_processed = sample.cpu().permute(0, 2, 3, 1)
image_processed = (image_processed + 1.0) * 127.5
image_processed = image_processed.numpy().astype(np.uint8)
image_pil = PIL.Image.fromarray(image_processed[0])
print(f"Image at step {i}")
image_pil.show()
# 5. Reverse diffusion process
sample = noisy_sample
for i, t in enumerate(tqdm.tqdm(scheduler.timesteps)):
# 1. Predict the noise residual
with torch.no_grad():
residual = model(sample, t).sample
# 2. Compute the less noisy image and move x_t -> x_t-1
sample = scheduler.step(residual, t, sample).prev_sample
# 3. Optionally display the image (every 50 steps)
if (i + 1) % 50 == 0:
display_sample(sample, i + 1)
print("Denoising complete.")
DDPM models can use discrete noise schedulers such as:
for inference. Note that while the ddpm scheduler yields the highest quality, it also takes the longest. For a good trade-off between quality and inference speed you might want to consider the ddim or pndm schedulers instead.
See the following code:
# !pip install diffusers
from diffusers import DDPMPipeline, DDIMPipeline, PNDMPipeline
If you want to train your own model, please have a look at the official training example
The following files are available for download:
diffusion_pytorch_model.safetensorsenvironment.ymlconfig.jsonscheduler_config.jsonIf you use this model in your research or project, please cite the original google/ddpm-celebahq-256 repository:
@misc{google/ddpm-celebahq-256,
author = {Google Research},
title = {DDPM CelebAHQ 256},
year = {2022},
url = {https://huggingface.co/google/ddpm-celebahq-256}
}
This model is provided under the Apache 2.0 License.