Skip to content

Commit

Permalink
Added working conditional MNIST generation notebook.
Browse files Browse the repository at this point in the history
  • Loading branch information
rkdan committed Jun 12, 2024
1 parent 6c916d0 commit 26c91b8
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 252 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/venv
docs/.DS_Store
docs/.DS_Store
diffusion-models/notebooks/mnist_data/
457 changes: 234 additions & 223 deletions diffusion-models/notebooks/hf_diffusers.ipynb

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion diffusion-models/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
torch==2.3.0
torchvision==0.18.0
matplotlib==3.9.0
seaborn==0.13.2
seaborn==0.13.2
diffusers==0.28.2
transformers==4.41.2
File renamed without changes.
49 changes: 49 additions & 0 deletions docs/hf_diffusers/hf_mnist_gen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
In this section we will introduce a core component of the Diffusers library `UNet2DModel`. This page will closely follow the notebook `hf_diffusers_mnist.ipynb`, so if you're interested in a quick run through and want to play around yourself, then check that out. Here, we will go through the code in more detail and explain the different components of the model, but feel free to refer back to this page.



## `UNet2DModel`
The `UNet2DModel` is a 2D U-Net model that is used for image generation. It abstracts out all of the annoying details of building the model, and allows you to focus on the important parts of your project.


``` python
model = UNet2DModel(
sample_size=28, # (1)
in_channels=1, # (2)
out_channels=1, # (3)
layers_per_block=1, # (4)
block_out_channels=(8, 16, 32), # (5)
down_block_types=(
"DownBlock2D",
"DownBlock2D",
"DownBlock2D",
),
up_block_types=(
"UpBlock2D",
"UpBlock2D",
"UpBlock2D",
),
num_class_embeds=10, # (6)
norm_num_groups=1, # (7)
)
```

1. The size of the input image. In this case, it is 28x28 pixels
2. The number of channels in the input image. In this case, it is 1, as the images are grayscale, but you would use 3 for RGB images
3. The number of channels in the output image. In this case, it is 1, as the images are grayscale, but you would use 3 for RGB images
4. The number of layers in each block
5. The number of output channels in each block - in a convolutional neural network, the number of channels is the number of filters that are applied to the input image.
6. The number of classes your dataset has if you are doing conditional generation.
7. The number of groups to use for the normalization layer. This is a hyperparameter that you can tune to improve the performance of your model.

There are a number of additional parameters, but these are the most important ones to understand when you are getting started with the `UNet2DModel`. Let's look at the block types in more detail, and some of the additional paramters

## Further reading
<div class="grid cards" markdown>

- :fontawesome-solid-book-open:{ .lg .middle } [__CI/CD - Pre-commit resources__](../resources/references.md#pre-commit)

---
Information on GitHub Actions, Black, Flake8, Mypy, Isort, and Git Hooks

</div>
4 changes: 4 additions & 0 deletions docs/hf_diffusers/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Hugging Face Diffusers
In this section, we make life easy for ourselves and use the Hugging Face Diffusers Library. We will look at two main tasks: image generation and ECG generation. We will start with image generation, and in doing so, we'll walk through most of the building blocks required to understand the second task.

Let's get started!
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<img src="./imgs/full_acc.png" alt="Logo" width=500>
</a>

# COURSE TITLE
# Introduction to diffusion models in generative AI

Welcome to the material for COURSE NAME.
Welcome to the material for Introduction to diffusion models in generative AI.

Please check the [official Mkdocs Material documentation](https://squidfunk.github.io/mkdocs-material/) for more information on how to use this template.

Expand Down
2 changes: 0 additions & 2 deletions docs/multi_2/index.md

This file was deleted.

16 changes: 0 additions & 16 deletions docs/multi_2/subpage_1.md

This file was deleted.

14 changes: 7 additions & 7 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
site_name: SITE NAME
repo_url: https://github.com/acceleratescience/REPO-TITLE
site_url: https://acceleratescience.github.io/REPO-TITLE/
site_name: Introduction to diffusion models in generative AI
repo_url: https://github.com/acceleratescience/diffusion-models
site_url: https://acceleratescience.github.io/diffusion-models/
nav:
- Home:
- Welcome!: index.md
Expand All @@ -10,10 +10,10 @@ nav:
- Multi Page 1:
- Subpage 1: multi_1/subpage_1.md
- Subpage 2: multi_1/subpage_2.md
- Multi Page 2:
- multi_2/index.md
- Page 1: multi_2/subpage_1.md
- Page 2: multi_2/subpage_2.md
- Hugging Face Diffusers:
- hf_diffusers/index.md
- Image Generation: hf_diffusers/hf_mnist_gen.md
- ECG Generation: hf_diffusers/hf_ecg_gen.md
- Resources:
- resources/index.md
- Slides: resources/slides.md
Expand Down

0 comments on commit 26c91b8

Please sign in to comment.