Upload folder using huggingface_hub
Browse files- LICENSE +21 -0
- README.md +39 -1
- SHA256SUMS +4 -3
- generate_tiny_digits.py +26 -2
- requirements.txt +1 -0
- sample_grid.png +0 -0
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2026 shibatch
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
---
|
| 2 |
library_name: pytorch
|
| 3 |
pipeline_tag: text-to-image
|
|
|
|
| 4 |
datasets:
|
| 5 |
- ylecun/mnist
|
| 6 |
tags:
|
|
@@ -54,6 +55,10 @@ Generate an eight-digit image:
|
|
| 54 |
python generate_tiny_digits.py 31415926 --output 31415926.png
|
| 55 |
```
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
The script accepts the following useful options:
|
| 58 |
|
| 59 |
```bash
|
|
@@ -65,19 +70,42 @@ python generate_tiny_digits.py 2026 \
|
|
| 65 |
--output 2026.png
|
| 66 |
```
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
The output is a fixed `32 x 256` grayscale PNG. Short prompts are centered on
|
| 69 |
the eight available 32-pixel slots.
|
| 70 |
|
| 71 |
## Python example
|
| 72 |
|
| 73 |
```python
|
|
|
|
|
|
|
|
|
|
| 74 |
import torch
|
|
|
|
| 75 |
from PIL import Image
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
from tiny_digit_diffusion import ddim_sample, load_model
|
| 78 |
|
| 79 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 80 |
-
model = load_model("model", device)
|
| 81 |
|
| 82 |
image = ddim_sample(
|
| 83 |
model,
|
|
@@ -228,3 +256,13 @@ This checkpoint is intended for education, architecture experiments, tests,
|
|
| 228 |
and demonstrations of a complete conditional image generator at a very small
|
| 229 |
parameter count. It should not be interpreted as an official MNIST model or as
|
| 230 |
an image-generation counterpart of any production diffusion system.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
library_name: pytorch
|
| 3 |
pipeline_tag: text-to-image
|
| 4 |
+
license: mit
|
| 5 |
datasets:
|
| 6 |
- ylecun/mnist
|
| 7 |
tags:
|
|
|
|
| 55 |
python generate_tiny_digits.py 31415926 --output 31415926.png
|
| 56 |
```
|
| 57 |
|
| 58 |
+
On the first run, the script downloads `model/config.json` and
|
| 59 |
+
`model/model.safetensors` from `shibatch/tinydigitdiffusion3m` on Hugging
|
| 60 |
+
Face. Later runs reuse the local Hugging Face cache.
|
| 61 |
+
|
| 62 |
The script accepts the following useful options:
|
| 63 |
|
| 64 |
```bash
|
|
|
|
| 70 |
--output 2026.png
|
| 71 |
```
|
| 72 |
|
| 73 |
+
Use a different Hub revision with `--revision`, or override the repository
|
| 74 |
+
with `--repo-id`. To use model files already stored locally (including the
|
| 75 |
+
`model/` directory included in this distribution package), pass
|
| 76 |
+
`--model-dir`:
|
| 77 |
+
|
| 78 |
+
```bash
|
| 79 |
+
python generate_tiny_digits.py 2026 --model-dir ./model --output 2026.png
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
The output is a fixed `32 x 256` grayscale PNG. Short prompts are centered on
|
| 83 |
the eight available 32-pixel slots.
|
| 84 |
|
| 85 |
## Python example
|
| 86 |
|
| 87 |
```python
|
| 88 |
+
import sys
|
| 89 |
+
from pathlib import Path
|
| 90 |
+
|
| 91 |
import torch
|
| 92 |
+
from huggingface_hub import snapshot_download
|
| 93 |
from PIL import Image
|
| 94 |
|
| 95 |
+
repo_dir = Path(snapshot_download(
|
| 96 |
+
repo_id="shibatch/tinydigitdiffusion3m",
|
| 97 |
+
allow_patterns=[
|
| 98 |
+
"model/config.json",
|
| 99 |
+
"model/model.safetensors",
|
| 100 |
+
"tiny_digit_diffusion.py",
|
| 101 |
+
],
|
| 102 |
+
))
|
| 103 |
+
sys.path.insert(0, str(repo_dir))
|
| 104 |
+
|
| 105 |
from tiny_digit_diffusion import ddim_sample, load_model
|
| 106 |
|
| 107 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 108 |
+
model = load_model(repo_dir / "model", device)
|
| 109 |
|
| 110 |
image = ddim_sample(
|
| 111 |
model,
|
|
|
|
| 256 |
and demonstrations of a complete conditional image generator at a very small
|
| 257 |
parameter count. It should not be interpreted as an official MNIST model or as
|
| 258 |
an image-generation counterpart of any production diffusion system.
|
| 259 |
+
|
| 260 |
+
## License
|
| 261 |
+
|
| 262 |
+
The source code and model checkpoint in this package are released under the
|
| 263 |
+
MIT License. See `LICENSE` for the complete terms.
|
| 264 |
+
|
| 265 |
+
The MNIST images are not redistributed in this package. Training used MNIST
|
| 266 |
+
through `torchvision`; the [MNIST dataset card](https://huggingface.co/datasets/ylecun/mnist)
|
| 267 |
+
identifies its license as MIT and credits Yann LeCun, Corinna Cortes, and
|
| 268 |
+
Christopher J. C. Burges as the dataset curators.
|
SHA256SUMS
CHANGED
|
@@ -1,11 +1,12 @@
|
|
| 1 |
32c3d5d9a15f591030c3a116ba7d068f88aa3e59f3f50edfa173e9174fa8d627 .gitattributes
|
| 2 |
-
|
|
|
|
| 3 |
334a86682c1450ba57900e4ac690557b5ccab31feb67e780b0d8c56eeaabe1ab artifact_metadata.json
|
| 4 |
-
|
| 5 |
421b80e7ba8f6b89125b7d6f65bb2356a1df2c7f39b7c125001a093a09d20795 model/config.json
|
| 6 |
035ccfb2876e5d78a637e282288e6bfaff227d7a18b3e9fe4562ff2a441458c2 model/model.safetensors
|
| 7 |
e18e17c2ae10c8fa2a3947abc31ea4a0eac86fc5c2ecad39578b9fe027999aca requirements-train.txt
|
| 8 |
-
|
| 9 |
d382d9dae68f91c93c9da353ee49a746428ab0c64a4b3e43ac88024765bd4a79 sample_grid.png
|
| 10 |
38e6cb6b1daa5b27a6663a6c29455cfdd0255d43ae1b4f487d48417334d211bb tiny_digit_diffusion.py
|
| 11 |
8c70ce74440d2a4930ddef0199d68c191de598fca7220241ac75d46e9b72fb89 train_tiny_digit_diffusion.py
|
|
|
|
| 1 |
32c3d5d9a15f591030c3a116ba7d068f88aa3e59f3f50edfa173e9174fa8d627 .gitattributes
|
| 2 |
+
cdf09a0b07d7cdb2ea535ac3127541ea55d6a996787a8e1b9266015d69f708a2 LICENSE
|
| 3 |
+
ae30ff06819481a2d607ae9e294960ecbe9f41b1d4d2b32467cf0b7f79ba935f README.md
|
| 4 |
334a86682c1450ba57900e4ac690557b5ccab31feb67e780b0d8c56eeaabe1ab artifact_metadata.json
|
| 5 |
+
15751648e2d970f57428314a159319154a38bf24a37b1db0643e397c174e3336 generate_tiny_digits.py
|
| 6 |
421b80e7ba8f6b89125b7d6f65bb2356a1df2c7f39b7c125001a093a09d20795 model/config.json
|
| 7 |
035ccfb2876e5d78a637e282288e6bfaff227d7a18b3e9fe4562ff2a441458c2 model/model.safetensors
|
| 8 |
e18e17c2ae10c8fa2a3947abc31ea4a0eac86fc5c2ecad39578b9fe027999aca requirements-train.txt
|
| 9 |
+
974c4ced7ad83a8821cbdf74c6d5c40051f0ed61e65fb95feaa79bfecd59a046 requirements.txt
|
| 10 |
d382d9dae68f91c93c9da353ee49a746428ab0c64a4b3e43ac88024765bd4a79 sample_grid.png
|
| 11 |
38e6cb6b1daa5b27a6663a6c29455cfdd0255d43ae1b4f487d48417334d211bb tiny_digit_diffusion.py
|
| 12 |
8c70ce74440d2a4930ddef0199d68c191de598fca7220241ac75d46e9b72fb89 train_tiny_digit_diffusion.py
|
generate_tiny_digits.py
CHANGED
|
@@ -11,14 +11,19 @@ from PIL import Image
|
|
| 11 |
|
| 12 |
from tiny_digit_diffusion import ddim_sample, load_model
|
| 13 |
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def parse_args() -> argparse.Namespace:
|
| 16 |
parser = argparse.ArgumentParser()
|
| 17 |
parser.add_argument("prompt", help="A numeric prompt containing 1-8 digits, for example 2026.")
|
| 18 |
parser.add_argument(
|
| 19 |
"--model-dir",
|
| 20 |
-
default=
|
|
|
|
| 21 |
)
|
|
|
|
|
|
|
| 22 |
parser.add_argument("--output", default="generated_digits.png")
|
| 23 |
parser.add_argument("--steps", type=int, default=50)
|
| 24 |
parser.add_argument("--guidance-scale", type=float, default=1.0)
|
|
@@ -27,13 +32,32 @@ def parse_args() -> argparse.Namespace:
|
|
| 27 |
return parser.parse_args()
|
| 28 |
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
def main() -> None:
|
| 31 |
args = parse_args()
|
| 32 |
device = torch.device(
|
| 33 |
"cuda" if args.device == "auto" and torch.cuda.is_available() else
|
| 34 |
"cpu" if args.device == "auto" else args.device
|
| 35 |
)
|
| 36 |
-
|
|
|
|
| 37 |
image = ddim_sample(
|
| 38 |
model,
|
| 39 |
[args.prompt],
|
|
|
|
| 11 |
|
| 12 |
from tiny_digit_diffusion import ddim_sample, load_model
|
| 13 |
|
| 14 |
+
DEFAULT_REPO_ID = "shibatch/tinydigitdiffusion3m"
|
| 15 |
+
|
| 16 |
|
| 17 |
def parse_args() -> argparse.Namespace:
|
| 18 |
parser = argparse.ArgumentParser()
|
| 19 |
parser.add_argument("prompt", help="A numeric prompt containing 1-8 digits, for example 2026.")
|
| 20 |
parser.add_argument(
|
| 21 |
"--model-dir",
|
| 22 |
+
default=None,
|
| 23 |
+
help="Local model directory. If omitted, download the model from Hugging Face.",
|
| 24 |
)
|
| 25 |
+
parser.add_argument("--repo-id", default=DEFAULT_REPO_ID)
|
| 26 |
+
parser.add_argument("--revision", default="main")
|
| 27 |
parser.add_argument("--output", default="generated_digits.png")
|
| 28 |
parser.add_argument("--steps", type=int, default=50)
|
| 29 |
parser.add_argument("--guidance-scale", type=float, default=1.0)
|
|
|
|
| 32 |
return parser.parse_args()
|
| 33 |
|
| 34 |
|
| 35 |
+
def resolve_model_dir(
|
| 36 |
+
model_dir: str | None,
|
| 37 |
+
repo_id: str,
|
| 38 |
+
revision: str,
|
| 39 |
+
) -> Path:
|
| 40 |
+
if model_dir is not None:
|
| 41 |
+
return Path(model_dir).expanduser().resolve()
|
| 42 |
+
|
| 43 |
+
from huggingface_hub import snapshot_download
|
| 44 |
+
|
| 45 |
+
snapshot_dir = snapshot_download(
|
| 46 |
+
repo_id=repo_id,
|
| 47 |
+
revision=revision,
|
| 48 |
+
allow_patterns=["model/config.json", "model/model.safetensors"],
|
| 49 |
+
)
|
| 50 |
+
return Path(snapshot_dir) / "model"
|
| 51 |
+
|
| 52 |
+
|
| 53 |
def main() -> None:
|
| 54 |
args = parse_args()
|
| 55 |
device = torch.device(
|
| 56 |
"cuda" if args.device == "auto" and torch.cuda.is_available() else
|
| 57 |
"cpu" if args.device == "auto" else args.device
|
| 58 |
)
|
| 59 |
+
model_dir = resolve_model_dir(args.model_dir, args.repo_id, args.revision)
|
| 60 |
+
model = load_model(model_dir, device)
|
| 61 |
image = ddim_sample(
|
| 62 |
model,
|
| 63 |
[args.prompt],
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
torch>=2.3
|
| 2 |
safetensors>=0.4
|
| 3 |
Pillow>=10.0
|
|
|
|
|
|
| 1 |
torch>=2.3
|
| 2 |
safetensors>=0.4
|
| 3 |
Pillow>=10.0
|
| 4 |
+
huggingface_hub>=0.25
|
sample_grid.png
CHANGED
|
|
Git LFS Details
|