DD-65 commited on
Commit
f7fcee0
·
verified ·
1 Parent(s): 23aed75

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: diffusers
4
+ pipeline_tag: conditional-image-generation
5
+ tags:
6
+ - diffusers
7
+ - ddpm
8
+ - conditional-image-generation
9
+ - mnist
10
+ - diffusion-models-class
11
+ ---
12
+
13
+ # DiffusionNumbers DDPM
14
+
15
+ DiffusionNumbers is a DDPM trained from scratch on the 60k training images of
16
+ [MNIST](https://huggingface.co/datasets/ylecun/mnist) on Apple Silicon. Training
17
+ took approximately 5 hours. It generates 64×64 grayscale images of a requested
18
+ handwritten digit from 0 to 9.
19
+
20
+ ## Usage
21
+
22
+ Install PyTorch, Diffusers, Safetensors, and Pillow, then run the model as
23
+ follows. Class labels have to be passed to the U-Net during every denoising
24
+ step:
25
+
26
+ ```python
27
+ import torch
28
+ from diffusers import DDPMPipeline
29
+ from PIL import Image
30
+
31
+ if torch.backends.mps.is_available():
32
+ device = "mps"
33
+ elif torch.cuda.is_available():
34
+ device = "cuda"
35
+ else:
36
+ device = "cpu"
37
+
38
+ pipe = DDPMPipeline.from_pretrained("DD-65/diffusionnumbers").to(device)
39
+
40
+ digit = 7
41
+ labels = torch.tensor([digit], device=device)
42
+ images = torch.randn((1, 1, 64, 64), device=device)
43
+
44
+ pipe.scheduler.set_timesteps(1000)
45
+ for timestep in pipe.scheduler.timesteps:
46
+ with torch.no_grad():
47
+ noise_prediction = pipe.unet(
48
+ images,
49
+ timestep,
50
+ class_labels=labels,
51
+ ).sample
52
+
53
+ images = pipe.scheduler.step(
54
+ noise_prediction,
55
+ timestep,
56
+ images,
57
+ ).prev_sample
58
+
59
+ image = (images[0, 0] / 2 + 0.5).clamp(0, 1)
60
+ image = image.mul(255).round().to(torch.uint8).cpu().numpy()
61
+ Image.fromarray(image).save("digit-7.png")
62
+ ```
63
+
64
+ Change `digit` to any integer from 0 through 9.
65
+ See also the [Github repo](https://github.com/DD-65/diffusionnumbers-code) for the complete training code and a more elaborate inference script.
66
+
67
+ ## Model details
68
+
69
+ - Architecture: `UNet2DModel` with a `DDPMScheduler`
70
+ - Parameters: 3.94 million
71
+ - Resolution: 64×64 grayscale (MNIST images have been subsampled)
72
+ - Conditioning: class labels for digits 0–9
73
+ - Training data: 60,000 MNIST training images
74
+ - Training: 40 epochs, batch size 128, AdamW with a `2e-4` learning rate
75
+ - Training objective: epsilon/noise prediction
76
+ - Scheduler training timesteps: 1,000
77
+
78
+ The original 28×28 images were resized to 64×64 and randomly scaled between
79
+ 90% and 110% during training.
80
+
81
+ ## Limitations
82
+
83
+ The model is designed for experimental image generation. It only generates
84
+ MNIST-like digits and is not a classifier or OCR model. Outputs can be malformed
85
+ or ambiguous, and their style and diversity are limited by the training data.
86
+
87
+ ## License
88
+
89
+ The model weights are released under the MIT license.
90
+
91
+ The model was trained on [MNIST](https://huggingface.co/datasets/ylecun/mnist),
92
+ which is also distributed under the MIT license.
model_index.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "DDPMPipeline",
3
+ "_diffusers_version": "0.39.0",
4
+ "scheduler": [
5
+ "diffusers",
6
+ "DDPMScheduler"
7
+ ],
8
+ "unet": [
9
+ "diffusers",
10
+ "UNet2DModel"
11
+ ]
12
+ }
scheduler/scheduler_config.json ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "DDPMScheduler",
3
+ "_diffusers_version": "0.39.0",
4
+ "beta_end": 0.02,
5
+ "beta_schedule": "linear",
6
+ "beta_start": 0.0001,
7
+ "clip_sample": true,
8
+ "clip_sample_range": 1.0,
9
+ "dynamic_thresholding_ratio": 0.995,
10
+ "num_train_timesteps": 1000,
11
+ "prediction_type": "epsilon",
12
+ "rescale_betas_zero_snr": false,
13
+ "sample_max_value": 1.0,
14
+ "steps_offset": 0,
15
+ "thresholding": false,
16
+ "timestep_spacing": "leading",
17
+ "trained_betas": null,
18
+ "variance_type": "fixed_small"
19
+ }
unet/config.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "UNet2DModel",
3
+ "_diffusers_version": "0.39.0",
4
+ "act_fn": "silu",
5
+ "add_attention": true,
6
+ "attention_head_dim": 8,
7
+ "attn_norm_num_groups": null,
8
+ "block_out_channels": [
9
+ 32,
10
+ 64,
11
+ 128
12
+ ],
13
+ "center_input_sample": false,
14
+ "class_embed_type": null,
15
+ "down_block_types": [
16
+ "DownBlock2D",
17
+ "DownBlock2D",
18
+ "AttnDownBlock2D"
19
+ ],
20
+ "downsample_padding": 1,
21
+ "downsample_type": "conv",
22
+ "dropout": 0.0,
23
+ "flip_sin_to_cos": true,
24
+ "freq_shift": 0,
25
+ "in_channels": 1,
26
+ "layers_per_block": 2,
27
+ "mid_block_scale_factor": 1,
28
+ "mid_block_type": "UNetMidBlock2D",
29
+ "norm_eps": 1e-05,
30
+ "norm_num_groups": 32,
31
+ "num_class_embeds": 10,
32
+ "num_train_timesteps": null,
33
+ "out_channels": 1,
34
+ "resnet_time_scale_shift": "default",
35
+ "sample_size": 64,
36
+ "time_embedding_dim": null,
37
+ "time_embedding_type": "positional",
38
+ "up_block_types": [
39
+ "AttnUpBlock2D",
40
+ "UpBlock2D",
41
+ "UpBlock2D"
42
+ ],
43
+ "upsample_type": "conv"
44
+ }
unet/diffusion_pytorch_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5e54c11a27dd40c56a8a9dcd94dbf9ac189e1d05ccbe3d76102cdc3705cd9197
3
+ size 15790724