Tarul commited on
Commit
e37793c
·
verified ·
1 Parent(s): 6dafc5d

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +200 -0
README.md ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - text-to-image
5
+ - pixel-art
6
+ - game-assets
7
+ - sprite-generator
8
+ - offline
9
+ - tiny-model
10
+ - numpy-runtime
11
+ - int8-quantization
12
+ - self-supervised
13
+ - procedural-data
14
+ - gpt
15
+ - english-prompts
16
+ - awesome-ai
17
+ library_name: numpy
18
+ pipeline_tag: text-to-image
19
+ language: en
20
+ ---
21
+
22
+ # PXG-Tiny — 483k-param offline text → 16×16 pixel-sprite model
23
+
24
+ **68× smaller than a vision transformer's attention head budget — and it still
25
+ draws.** PXG-Tiny turns plain English into production-usable 16×16 pixel-art
26
+ sprites fully offline: 483,040 parameters, pure NumPy inference, CPU-only,
27
+ zero network calls.
28
+
29
+ **Author:** Chowdhury Tarul Ahsan · <tarulahsan@gmail.com>
30
+
31
+ | | |
32
+ |---|---|
33
+ | Live demo | https://huggingface.co/spaces/tarulahsan/pxg-tiny-demo |
34
+ | Landing site | https://tarulahsan.github.io/PXG-Tiny-AI/ |
35
+ | Code | https://github.com/tarulahsan/PXG-Tiny-AI |
36
+ | ModelScope | https://modelscope.cn/models/tarulahsan/pxg-tiny |
37
+
38
+ ![gallery](gallery.png)
39
+
40
+ # PXG-Tiny — offline text → 16×16 pixel-sprite model
41
+
42
+ **PXG-Tiny** is the deliberately miniature sibling of the Pixel AI (PXG) program:
43
+ a **483,040-parameter** generator that turns plain English into production-usable
44
+ 16×16 pixel-art sprites (weapons, potions, treasure, flora, tiles, buildings…)
45
+ fully offline. It ships as a ~1 MB weight bundle and runs on a pure **NumPy**
46
+ inference runtime with **no PyTorch and no GPU required**.
47
+
48
+ **Author:** Chowdhury Tarul Ahsan · <tarulahsan@gmail.com> · v0.4 (2026-08-27)
49
+
50
+ **Headline numbers** (final acceptance, v0.4):
51
+ full-grid verification **38/38 classes — 152/152 prompts (100%)** ·
52
+ independent fresh-phrasing sweep **99.1% (116/117)** · raw held-out
53
+ (46 prompts, retry disabled) **59.4%** · showcase gallery **31/31** ·
54
+ val top-1 **98.89%** · bundle ~1.8 MB fp32
55
+
56
+ ```
57
+ "a golden sword, glowing" ──► PXG-Tiny ──► 16×16 RGBA sprite (+ retries,
58
+ clarify/refuse questions)
59
+ ```
60
+
61
+ **Tags:** `text-to-image` `pixel-art` `game-assets` `sprite-generator`
62
+ `offline` `tiny-model` `numPy-runtime` `int8-quantization`
63
+ `self-supervised` `procedural-data` `gpt` `english-prompts`
64
+
65
+ ---
66
+
67
+ ## What it can do
68
+
69
+ | Capability | Detail |
70
+ |---|---|
71
+ | **38 grounded object classes** | weapons: sword, dagger, shield, staff · potions: round bottle, slim vial · treasure: chest, coin, gem, key · food: apple, bread · nature: oak/pine tree, bush, rock · tiles: grass/stone/water · building: house · **characters**: wizard, knight, archer, skeleton, zombie · **animals**: cat, dog, bird, fish, deer, mouse, bat · **furniture**: chair, table, stool · effects: fireball |
72
+ | Attribute grounding | materials (gold/iron/crystal/ruby/emerald/sapphire/amethyst/wood/copper/slate/terracotta), orientation (upright / lying sideways), glow, moss, berries, autumn leaves, size, roof colors — enforced only where the recipe supports them |
73
+ | Ask-first behavior | refuses photos / 3D / animations / other resolutions; asks clarifying questions on unknown objects or conflicting attribute words |
74
+ | Verifier-guided sampling | every generation is auto-checked against prompt-grounding constraints; failed seeds escalate through **self-guided palette bias → spatial priors (face box, vial margins, deer antler anchor) → canonical prompt anchoring** (8 tries) |
75
+ | Paraphrase-robust English | trained on **97,005** paraphrase-augmented rows across 38 classes: "made of pure iron", "of the crystal kind", "covered in moss", "whose orb is ruby", mid-adjectives, prose or comma forms |
76
+ | Deterministic & offline | char-level tokenizer with byte-fallback, fixed seeds, master-palette indices only |
77
+
78
+ ## Quick start (no build step)
79
+
80
+ ```bash
81
+ # single sprite
82
+ python3 cli.py "a golden sword" -o sword.png
83
+
84
+ # 4 variations on one sheet
85
+ python3 cli.py "an iron chest" --variations 4 --sheet chest_variants.png
86
+
87
+ # ask-first gate
88
+ python3 cli.py --ask "can you render a photo of my cat"
89
+
90
+ # batch: prompts.txt (one per line)
91
+ python3 cli.py --sheet-from-prompts prompts.txt --outdir sprites/
92
+ ```
93
+
94
+ Python API:
95
+
96
+ ```python
97
+ from pxg_tiny.pipeline import PXGPipeline
98
+
99
+ pipe = PXGPipeline() # loads ./weights bundle
100
+ grid, meta = pipe.generate_pixels("a ruby potion that glows", seed=7)
101
+ if grid is None:
102
+ print(meta["message"]) # clarify/refuse reply instead of pixels
103
+ else:
104
+ png_path = pipe.generate_png("a ruby potion that glows",
105
+ "ruby_potion.png")[1]["path"]
106
+ msg = PXGPipeline.ask("draw a 3d blender model") # -> refusal message
107
+ ```
108
+
109
+ Requirements: Python ≥3.9, `numpy`, `pillow` (rendering only; generation math
110
+ is NumPy-only).
111
+
112
+ ## Architecture (483k params)
113
+
114
+ ```
115
+ caption ids (32 slots) ─► intent encoder (bi attn + ReLU FFN, fp32)
116
+ ─► 8 prefix vectors
117
+ [8 prefixes | 256 visual tokens]
118
+ └─ 4× pre-LN causal blocks (d=96, 4 heads, FFN 256, tanh-GELU)
119
+ └─ 32-way softmax over master-palette indices (0 = transparent alpha)
120
+
121
+ per-token accuracy 98%+ teacher-forced; KV-cached incremental decode at
122
+ inference (~0.6 s per sprite on 2 CPU cores).
123
+ ```
124
+
125
+ *Visual "tokenizer"* is built-in by design: sprites are stored as grids of
126
+ 32 master-palette indices, so decoding is byte-exact and alpha transparency
127
+ is exact by construction.
128
+
129
+ ## Self-teaching training recipe
130
+
131
+ No external dataset was needed for v0.2:
132
+
133
+ 1. A procedural rasterizer (11 asset families) draws sprites whose every
134
+ caption word maps to a real rendered attribute — captions are honest by
135
+ construction.
136
+ 2. Counterfactual twin pairs share geometry but differ in exactly one
137
+ attribute word ("gold" vs "iron"), teaching word→pixel causality.
138
+ 3. **Paraphrase augmentation**: each ground-truth sprite is re-captioned in
139
+ multiple surface forms (relative clauses, "made of/from", "of the … kind",
140
+ "covered in moss", "lying sideways", polite frames, mid adjectives…) so the
141
+ encoder learns paraphrase *invariance*. The final corpus is **97,005 rows**
142
+ across 38 classes.
143
+ 4. Quality gates (connectivity, isolated pixels, attribute thresholds) are
144
+ calibrated so the ground-truth corpus passes 100%.
145
+
146
+ Training itself is `train/train_model.py` (CPU PyTorch, ~50 min @4,200 steps).
147
+ `train/quantize_export.py` exports the runnable bundle and proves numerical
148
+ parity against the torch reference.
149
+
150
+ ## Bundle contents (`weights/`)
151
+
152
+ | file | role |
153
+ |---|---|
154
+ | `gen_int8.npz` | all model weights (see metadata for precision layout) |
155
+ | `vq_int8.npz` | master palette (32×4 RGBA lookup = visual codebook) |
156
+ | `runtime.json` | geometry + default sampling config |
157
+ | `tokenizer.json` | text tokenizer table |
158
+ | `metadata.json` | params, metrics, parity report, license, provenance |
159
+
160
+ `pxg_tiny/runtime_pipeline.OfflinePipeline` implements everything needed to
161
+ run it; `PXGPipeline` wraps it with gates, retries, turnarounds and PNG export.
162
+
163
+ ## Testing
164
+
165
+ ```bash
166
+ pip install pytest
167
+ pytest tests/ -q # tokenizer, gates, NumPy kernels, end-to-end smoke
168
+ ```
169
+
170
+ ## Honest limitations
171
+
172
+ * 16×16 resolution only — larger canvases / spritesheets / tilemaps are
173
+ refused by design (the ask-first gate explains this).
174
+ * Class vocabulary is the 38 trained families; anything outside gets a
175
+ clarifying question rather than a hallucinated blob.
176
+ * Raw free-run sampling (verifier disabled) passes ~59% of hard held-out
177
+ prompts; the verifier-guided pipeline lifts the shipped user path to
178
+ ~100% (38-class grid) / 99.1% (fresh phrasings). Rare hard prompts can
179
+ still end on an `accept_degraded` last-resort sprite (see EVAL_REPORT §5).
180
+ * Some material × class combos the recipes never trained (e.g. "emerald
181
+ dagger") are silently downgraded to the class default instead of failing.
182
+ * Animation/multi-view consistency are roadmap items inherited from the main
183
+ PXG program, not in this tiny cut.
184
+
185
+ See [EVAL_REPORT.md](EVAL_REPORT.md) for the full v0.1 → v0.4 evaluation
186
+ journey and honest weakness list, and [TUTORIAL.md](TUTORIAL.md) for a
187
+ 5-minute quickstart.
188
+
189
+ ## OpenGameArt-CC0 hook
190
+
191
+ v0.2 did not require external data (procedural ground truth gives perfect
192
+ caption alignment). To enrich distribution realism later: download a CC0-only
193
+ subset, record SHA256 + page URL per file in `data/oga_manifest.json`, run the
194
+ same quality gates, then extend `CLASS_DEFS`. License hygiene stays CC0-only.
195
+
196
+ ## License
197
+
198
+ Code: **MIT** (see LICENSE). Weights + procedural corpus: **CC0** —
199
+ self-generated, no third-party assets ingested; sprites you generate are
200
+ yours to use anywhere, no attribution required.