Diffusers implementation of Noise Conditional Score Networks (NCSN) [Yang+ NeuriPS'19]
Project description
🤗 Noise Conditional Score Networks
🤗 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 git+https://github.com/py-img-gen/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
Showcase
MNIST
Example of generating MNIST character images using the model trained with train_mnist.py.
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.
- Change the
_class_nameattribute inmodel_index.jsonto["pipeline_ncsn", "NCSNPipeline"]. - Upload
pipeline_ncsn.pyto the root of the pipeline repository. - Upload custom components to each subfolder:
- Upload
scheduling_ncsn.pyto theschedulersubfolder. - Upload
unet_2d_ncsn.pyto theunetsubfolder.
- Upload
- Ensure that the custom components are placed in each subfolder because they are referenced by relative paths from
pipeline_ncsn.py.- Based on this, the code in this library is also placed in the same directory structure as the HF Hub.
- For example,
pipeline_ncsn.pyimportsunet_2d_ncsn.pyasfrom .unet.unet_2d_ncsn import UNet2DModelForNCSNbecause it is placed in theunetsubfolder.
License
diffusers-ncsn is licensed under Apache 2.0. A full copy of the license can be found on GitHub.
Acknowledgements
- JeongJiHeon/ScoreDiffusionModel: The Pytorch Tutorial of Score-based and Diffusion Model https://github.com/JeongJiHeon/ScoreDiffusionModel/tree/main
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file diffusers_ncsn-0.0.1.tar.gz.
File metadata
- Download URL: diffusers_ncsn-0.0.1.tar.gz
- Upload date:
- Size: 103.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.26
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a75a7cfb812265251f38d5d5705f3198c70344987885a19407b42564b6ffce0
|
|
| MD5 |
b30f8019ca80c3f6c67c9ba2a1f341a0
|
|
| BLAKE2b-256 |
0f2244ba15194a1f8111b2f7096b7918fd97f44d36da0d015be21a91cc5333e9
|
File details
Details for the file diffusers_ncsn-0.0.1-py3-none-any.whl.
File metadata
- Download URL: diffusers_ncsn-0.0.1-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.26
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccc15a30543171762ee4c69bbc01f5792539da5e96873a65db9b3ef0365182c1
|
|
| MD5 |
861f9f177200e10a69ff56ce2f903212
|
|
| BLAKE2b-256 |
33266b76f69d5bb69e96cfef0712ef07d48bdb99c68f9fd90854698580fcecd2
|