Download README.md from jmclean/esp32-sprite-maker: direct link, hf CLI and curl.
- Browser
- Download file 6.26 kB
-
https://huggingface.co/jmclean/esp32-sprite-maker/resolve/main/README.md
- Command line
-
hf download hf://jmclean/esp32-sprite-maker/README.md
-
curl -L -o README.md https://huggingface.co/jmclean/esp32-sprite-maker/resolve/main/README.md
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 (MIT)
Model Sources
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:
cc -O2 -o draw host/draw.c -lm
./draw knight -n 8 -o knights.png
On an M5Stack CoreS3, from the repository's firmware/ folder:
pio run -e m5stack-cores3 -t upload_model
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'straining/weights.pyturns them into a checkpoint training can start from.
Training Details
Training Data
Pixel Art Atlas (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:
- 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.
- 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.