jmclean commited on
Commit
d37df3e
·
verified ·
1 Parent(s): 967b8e3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +188 -0
README.md CHANGED
@@ -1,3 +1,191 @@
1
  ---
2
  license: cc-by-nc-4.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: cc-by-nc-4.0
3
+ library_name: esp32-ai
4
+ pipeline_tag: unconditional-image-generation
5
+ tags:
6
+ - esp32
7
+ - esp32-s3
8
+ - microcontroller
9
+ - embedded
10
+ - edge
11
+ - per-layer-embeddings
12
+ - int4
13
+ - pixel-art
14
+ - sprites
15
+ datasets:
16
+ - Angais/pixel-art-atlas-1.4m
17
  ---
18
+
19
+ # Model Card for ESP32 Sprite Maker
20
+
21
+ A 717,000-parameter transformer that draws new 16 x 16 pixel-art game characters, one
22
+ pixel at a time, on an ESP32-S3 microcontroller (M5Stack CoreS3), with nothing off the chip.
23
+
24
+ ![Sprites drawn by the model](sprites.png)
25
+
26
+ ## Model Details
27
+
28
+ ### Model Description
29
+
30
+ The model writes a sprite as a sequence of tokens: a character token (knight, wizard,
31
+ witch, robot, slime, ghost, dragon, skeleton, zombie, goblin, pirate, ninja, alien, cat,
32
+ frog, monster), then 256 pixels row by row, each either transparent or one of 32 colours.
33
+ It runs on the ESP32-S3 with 4-bit weights, drawing each pixel on screen as it is written,
34
+ in about 18 seconds a sprite.
35
+
36
+ - **Developed by:** Justin McLean
37
+ - **Model type:** decoder-only transformer with per-layer embeddings, autoregressive over
38
+ pixel tokens
39
+ - **License:** CC BY-NC 4.0
40
+ - **Inference code:** [slvDev/esp32-ai](https://github.com/slvDev/esp32-ai) (MIT)
41
+
42
+ ### Model Sources
43
+
44
+ - **Repository:** https://github.com/OWNER/esp32-sprite-maker
45
+
46
+ ## Uses
47
+
48
+ ### Direct Use
49
+
50
+ Generating original 16 x 16 character sprites for non-commercial games, demos and
51
+ learning, on an ESP32-S3 board or on a computer (the repository's `host/draw.c`).
52
+
53
+ ### Out-of-Scope Use
54
+
55
+ Commercial use: the training sprites were generated with Krea 2, whose commercial-use
56
+ terms apply (see Licence). Characters other than the 16 it was trained on, or sizes and
57
+ palettes other than 16 x 16 and 32 colours.
58
+
59
+ ## Bias, Risks, and Limitations
60
+
61
+ - Some characters are much more recognisable than others (see Evaluation): goblins,
62
+ zombies, wizards and aliens are the weakest, and look-alike pairs (wizard and witch,
63
+ pirate and ninja) get mixed up.
64
+ - Sprites are sampled, so quality varies from one to the next.
65
+ - The training sprites are themselves AI-generated, and their captions were not reviewed
66
+ sprite by sprite.
67
+
68
+ ### Recommendations
69
+
70
+ Draw a few and keep the ones you like. Use temperature 0.8: higher gives more variety but
71
+ more broken shapes.
72
+
73
+ ## How to Get Started with the Model
74
+
75
+ On a computer, with only a C compiler, from the GitHub repository:
76
+
77
+ ```bash
78
+ cc -O2 -o draw host/draw.c -lm
79
+ ```
80
+
81
+ ```bash
82
+ ./draw knight -n 8 -o knights.png
83
+ ```
84
+
85
+ On an M5Stack CoreS3, from the repository's `firmware/` folder:
86
+
87
+ ```bash
88
+ pio run -e m5stack-cores3 -t upload_model
89
+ ```
90
+
91
+ ```bash
92
+ pio run -e m5stack-cores3 -t upload
93
+ ```
94
+
95
+ ## Files
96
+
97
+ - `model.bin`: the device model, 4-bit weights (0.38 MB). Flashed at 0x790000.
98
+ - `tokenizer.json`: the token layout: the 32-colour palette (plus transparent), the 16
99
+ character tokens and the end-of-sprite token.
100
+ - `sprite-maker.safetensors`: full-precision weights (2.9 MB), for fine-tuning. The
101
+ repository's `training/weights.py` turns them into a checkpoint training can start from.
102
+
103
+ ## Training Details
104
+
105
+ ### Training Data
106
+
107
+ [Pixel Art Atlas](https://huggingface.co/datasets/Angais/pixel-art-atlas-1.4m)
108
+ (1.4 million 16 x 16 sprites, CC0). Each sprite is mapped to a fixed 32-colour palette
109
+ fitted to the sprites' colours. Character sprites are those whose subject ends in one of
110
+ the 16 character names (36,436 sprites), used with left-right mirrored copies.
111
+
112
+ ### Training Procedure
113
+
114
+ Two stages:
115
+
116
+ 1. All 1.4 million sprites, with an "other" start token for non-characters and character
117
+ sprites repeated 8 times (with mirrors): outlines, shading and solid shapes.
118
+ 2. A fine-tune on the character sprites only, so each character token means its
119
+ character.
120
+
121
+ #### Training Hyperparameters
122
+
123
+ - **Stage 1:** 12,000 steps, batch 32 x 257 tokens, AdamW, learning rate 1e-3 with 200
124
+ warmup steps and cosine decay, weight decay 0.1
125
+ - **Stage 2:** 1,500 steps from stage 1, learning rate 3e-4 with 50 warmup steps
126
+ - **Training regime:** fp32; each training window starts at the start of a sprite
127
+
128
+ #### Speeds, Sizes, Times
129
+
130
+ - 716,832 parameters (698,400 in the transformer core); 0.38 MB on the device at 4 bits
131
+ - About 40 minutes of training on an Apple M3 MacBook (stage 1 about 35 minutes)
132
+ - About 18 seconds a sprite on an ESP32-S3 at 240 MHz (13.9 pixels a second)
133
+
134
+ ## Evaluation
135
+
136
+ ### Testing Data, Factors & Metrics
137
+
138
+ 2,000 sprites, 125 per character, drawn at temperature 0.8 with the device model and
139
+ arithmetic (`host/draw.c`), measured two ways:
140
+
141
+ - **Memorisation:** the closest training sprite of the same character, in pixels
142
+ different.
143
+ - **Consistency:** how often a small classifier trained on the real character sprites
144
+ recognises each generated sprite as its own character. On held-out real sprites the
145
+ classifier scores 87%, the ceiling for these scores.
146
+
147
+ ### Results
148
+
149
+ **Memorisation:** none. No generated sprite is an exact or near copy (13 pixels or fewer
150
+ different) of a training sprite; the closest typically differs by about 110 of 256 pixels.
151
+
152
+ **Consistency:**
153
+
154
+ | Character | Looks like itself | Most often mistaken for |
155
+ |---|---|---|
156
+ | slime | 96% | monster |
157
+ | cat | 82% | monster |
158
+ | knight | 68% | monster |
159
+ | skeleton | 65% | knight |
160
+ | dragon | 62% | monster |
161
+ | robot | 58% | knight |
162
+ | ghost | 57% | slime |
163
+ | frog | 54% | monster |
164
+ | ninja | 51% | pirate |
165
+ | monster | 51% | slime |
166
+ | witch | 50% | wizard |
167
+ | pirate | 50% | ninja |
168
+ | alien | 36% | monster |
169
+ | wizard | 35% | witch |
170
+ | zombie | 28% | monster |
171
+ | goblin | 19% | knight |
172
+
173
+ ## Technical Specifications
174
+
175
+ ### Model Architecture and Objective
176
+
177
+ 5 transformer layers, width 128, 4 attention heads, SwiGLU feed-forward, RoPE positions,
178
+ per-layer embeddings of width 32, output head tied to the token embedding. Trained with
179
+ next-token cross-entropy over a 64-token vocabulary, context 257 tokens.
180
+
181
+ ### Compute Infrastructure
182
+
183
+ - **Training:** Apple M3 MacBook (PyTorch, MPS)
184
+ - **Inference:** ESP32-S3 (M5Stack CoreS3) with 8 MB PSRAM, or any computer
185
+
186
+ ## Licence
187
+
188
+ CC BY-NC 4.0. Trained on the Pixel Art Atlas by Angais, released under CC0. Its sprites
189
+ were generated with Krea 2: Krea claims no ownership of generated outputs, but the Krea 2
190
+ Community License's commercial-use terms apply to them, so this model is for
191
+ non-commercial use.