Skip to content

Latest commit

 

History

History
112 lines (80 loc) · 5.02 KB

README.md

File metadata and controls

112 lines (80 loc) · 5.02 KB

🤗 Noise Conditional Score Networks

CI Document ermongroup/ncsn Model on HF PyPI

🤗 diffusers implementation of the paper "Generative Modeling by Estimating Gradients of the Data Distribution" [Yang+ NeurIPS'19].

How to use

Use without installation

You can load the pretrained pipeline directly from the HF Hub as follows:

import torch
from diffusers import DiffusionPipeline
from diffusers.utils import make_image_grid

# Specify the device to use
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

#
# Load the pipeline from the Hugging Face Hub
#
pipe = DiffusionPipeline.from_pretrained(
    "py-img-gen/ncsn-mnist", trust_remote_code=True
)
pipe = pipe.to(device)

# Generate samples; here, we specify the seed and generate 16 images
output = pipe(
    batch_size=16,
    generator=torch.manual_seed(42),
)

# Create a grid image from the generated samples
image = make_image_grid(images=output.images, rows=4, cols=4)
image.save("output.png")

Use with installation

First, install the package from this repository:

pip install diffusers-ncsn

Then, you can use the package as follows:

import torch

from ncsn.pipeline_ncsn import NCSNPipeline

# Specify the device to use
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

#
# Load the pipeline from the HF Hub through the NCSNPipeline of this library
#
pipe = NCSNPipeline.from_pretrained("py-img-gen/ncsn-mnist", trust_remote_code=True)
pipe = pipe.to(device)

# Generate samples; here, we specify the seed and generate 16 images
output = pipe(
    batch_size=16,
    generator=torch.manual_seed(42),
)

# Create a grid image from the generated samples
image = make_image_grid(images=output.images, rows=4, cols=4)
image.save("output.png")

Pretrained models and pipeline

Model on HF

Showcase

MNIST

Example of generating MNIST character images using the model trained with train_mnist.py.

mnist

Notes on uploading pipelines to the HF Hub with custom components

While referring to 📝 Load community pipelines and components - huggingface diffusers, pay attention to the following points.

License

diffusers-ncsn is licensed under Apache 2.0. A full copy of the license can be found on GitHub.

Acknowledgements