Update README.md
Browse files123---license: cc-by-nc-4.0---123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191---license: cc-by-nc-4.0library_name: esp32-aipipeline_tag: unconditional-image-generationtags:- esp32- esp32-s3- microcontroller- embedded- edge- per-layer-embeddings- int4- pixel-art- spritesdatasets:- Angais/pixel-art-atlas-1.4m---# Model Card for ESP32 Sprite MakerA 717,000-parameter transformer that draws new 16 x 16 pixel-art game characters, onepixel at a time, on an ESP32-S3 microcontroller (M5Stack CoreS3), with nothing off the chip.## Model Details### Model DescriptionThe 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 overpixel 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/OWNER/esp32-sprite-maker## Uses### Direct UseGenerating original 16 x 16 character sprites for non-commercial games, demos andlearning, on an ESP32-S3 board or on a computer (the repository's `host/draw.c`).### Out-of-Scope UseCommercial use: the training sprites were generated with Krea 2, whose commercial-useterms apply (see Licence). Characters other than the 16 it was trained on, or sizes andpalettes 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 reviewedsprite by sprite.### RecommendationsDraw a few and keep the ones you like. Use temperature 0.8: higher gives more variety butmore broken shapes.## How to Get Started with the ModelOn a computer, with only a C compiler, from the GitHub repository:```bashcc -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:```bashpio run -e m5stack-cores3 -t upload_model``````bashpio 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 16character tokens and the end-of-sprite token.- `sprite-maker.safetensors`: full-precision weights (2.9 MB), for fine-tuning. Therepository'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 palettefitted to the sprites' colours. Character sprites are those whose subject ends in one ofthe 16 character names (36,436 sprites), used with left-right mirrored copies.### Training ProcedureTwo stages:1. All 1.4 million sprites, with an "other" start token for non-characters and charactersprites repeated 8 times (with mirrors): outlines, shading and solid shapes.2. A fine-tune on the character sprites only, so each character token means itscharacter.#### Training Hyperparameters- **Stage 1:** 12,000 steps, batch 32 x 257 tokens, AdamW, learning rate 1e-3 with 200warmup 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 & Metrics2,000 sprites, 125 per character, drawn at temperature 0.8 with the device model andarithmetic (`host/draw.c`), measured two ways:- **Memorisation:** the closest training sprite of the same character, in pixelsdifferent.- **Consistency:** how often a small classifier trained on the real character spritesrecognises each generated sprite as its own character. On held-out real sprites theclassifier scores 87%, the ceiling for these scores.### Results**Memorisation:** none. No generated sprite is an exact or near copy (13 pixels or fewerdifferent) 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 Objective5 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 withnext-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## LicenceCC BY-NC 4.0. Trained on the Pixel Art Atlas by Angais, released under CC0. Its spriteswere generated with Krea 2: Krea claims no ownership of generated outputs, but the Krea 2Community License's commercial-use terms apply to them, so this model is fornon-commercial use.
README.md+188