File size: 6,264 Bytes
967b8e3 d37df3e 967b8e3 d37df3e 36f8f86 d37df3e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | ---
license: cc-by-nc-4.0
library_name: esp32-ai
pipeline_tag: unconditional-image-generation
tags:
- esp32
- esp32-s3
- microcontroller
- embedded
- edge
- per-layer-embeddings
- int4
- pixel-art
- sprites
datasets:
- Angais/pixel-art-atlas-1.4m
---
# Model Card for ESP32 Sprite Maker
A 717,000-parameter transformer that draws new 16 x 16 pixel-art game characters, one
pixel at a time, on an ESP32-S3 microcontroller (M5Stack CoreS3), with nothing off the chip.

## Model Details
### Model Description
The model writes a sprite as a sequence of tokens: a character token (knight, wizard,
witch, robot, slime, ghost, dragon, skeleton, zombie, goblin, pirate, ninja, alien, cat,
frog, monster), then 256 pixels row by row, each either transparent or one of 32 colours.
It runs on the ESP32-S3 with 4-bit weights, drawing each pixel on screen as it is written,
in about 18 seconds a sprite.
- **Developed by:** Justin McLean
- **Model type:** decoder-only transformer with per-layer embeddings, autoregressive over
pixel tokens
- **License:** CC BY-NC 4.0
- **Inference code:** [slvDev/esp32-ai](https://github.com/slvDev/esp32-ai) (MIT)
### Model Sources
- **Repository:** https://github.com/justinmclean/esp32-sprite-maker
## Uses
### Direct Use
Generating original 16 x 16 character sprites for non-commercial games, demos and
learning, on an ESP32-S3 board or on a computer (the repository's `host/draw.c`).
### Out-of-Scope Use
Commercial use: the training sprites were generated with Krea 2, whose commercial-use
terms apply (see Licence). Characters other than the 16 it was trained on, or sizes and
palettes other than 16 x 16 and 32 colours.
## Bias, Risks, and Limitations
- Some characters are much more recognisable than others (see Evaluation): goblins,
zombies, wizards and aliens are the weakest, and look-alike pairs (wizard and witch,
pirate and ninja) get mixed up.
- Sprites are sampled, so quality varies from one to the next.
- The training sprites are themselves AI-generated, and their captions were not reviewed
sprite by sprite.
### Recommendations
Draw a few and keep the ones you like. Use temperature 0.8: higher gives more variety but
more broken shapes.
## How to Get Started with the Model
On a computer, with only a C compiler, from the GitHub repository:
```bash
cc -O2 -o draw host/draw.c -lm
```
```bash
./draw knight -n 8 -o knights.png
```
On an M5Stack CoreS3, from the repository's `firmware/` folder:
```bash
pio run -e m5stack-cores3 -t upload_model
```
```bash
pio run -e m5stack-cores3 -t upload
```
## Files
- `model.bin`: the device model, 4-bit weights (0.38 MB). Flashed at 0x790000.
- `tokenizer.json`: the token layout: the 32-colour palette (plus transparent), the 16
character tokens and the end-of-sprite token.
- `sprite-maker.safetensors`: full-precision weights (2.9 MB), for fine-tuning. The
repository's `training/weights.py` turns them into a checkpoint training can start from.
## Training Details
### Training Data
[Pixel Art Atlas](https://huggingface.co/datasets/Angais/pixel-art-atlas-1.4m)
(1.4 million 16 x 16 sprites, CC0). Each sprite is mapped to a fixed 32-colour palette
fitted to the sprites' colours. Character sprites are those whose subject ends in one of
the 16 character names (36,436 sprites), used with left-right mirrored copies.
### Training Procedure
Two stages:
1. All 1.4 million sprites, with an "other" start token for non-characters and character
sprites repeated 8 times (with mirrors): outlines, shading and solid shapes.
2. A fine-tune on the character sprites only, so each character token means its
character.
#### Training Hyperparameters
- **Stage 1:** 12,000 steps, batch 32 x 257 tokens, AdamW, learning rate 1e-3 with 200
warmup steps and cosine decay, weight decay 0.1
- **Stage 2:** 1,500 steps from stage 1, learning rate 3e-4 with 50 warmup steps
- **Training regime:** fp32; each training window starts at the start of a sprite
#### Speeds, Sizes, Times
- 716,832 parameters (698,400 in the transformer core); 0.38 MB on the device at 4 bits
- About 40 minutes of training on an Apple M3 MacBook (stage 1 about 35 minutes)
- About 18 seconds a sprite on an ESP32-S3 at 240 MHz (13.9 pixels a second)
## Evaluation
### Testing Data, Factors & Metrics
2,000 sprites, 125 per character, drawn at temperature 0.8 with the device model and
arithmetic (`host/draw.c`), measured two ways:
- **Memorisation:** the closest training sprite of the same character, in pixels
different.
- **Consistency:** how often a small classifier trained on the real character sprites
recognises each generated sprite as its own character. On held-out real sprites the
classifier scores 87%, the ceiling for these scores.
### Results
**Memorisation:** none. No generated sprite is an exact or near copy (13 pixels or fewer
different) of a training sprite; the closest typically differs by about 110 of 256 pixels.
**Consistency:**
| Character | Looks like itself | Most often mistaken for |
|---|---|---|
| slime | 96% | monster |
| cat | 82% | monster |
| knight | 68% | monster |
| skeleton | 65% | knight |
| dragon | 62% | monster |
| robot | 58% | knight |
| ghost | 57% | slime |
| frog | 54% | monster |
| ninja | 51% | pirate |
| monster | 51% | slime |
| witch | 50% | wizard |
| pirate | 50% | ninja |
| alien | 36% | monster |
| wizard | 35% | witch |
| zombie | 28% | monster |
| goblin | 19% | knight |
## Technical Specifications
### Model Architecture and Objective
5 transformer layers, width 128, 4 attention heads, SwiGLU feed-forward, RoPE positions,
per-layer embeddings of width 32, output head tied to the token embedding. Trained with
next-token cross-entropy over a 64-token vocabulary, context 257 tokens.
### Compute Infrastructure
- **Training:** Apple M3 MacBook (PyTorch, MPS)
- **Inference:** ESP32-S3 (M5Stack CoreS3) with 8 MB PSRAM, or any computer
## Licence
CC BY-NC 4.0. Trained on the Pixel Art Atlas by Angais, released under CC0. Its sprites
were generated with Krea 2: Krea claims no ownership of generated outputs, but the Krea 2
Community License's commercial-use terms apply to them, so this model is for
non-commercial use. |