|
Download README.md from PixilabAI/smalt-medium: direct link, hf CLI and curl.
- Browser
- Download file 5.07 kB
-
https://huggingface.co/PixilabAI/smalt-medium/resolve/main/README.md
- Command line
-
hf download hf://PixilabAI/smalt-medium/README.md
-
curl -L -o README.md https://huggingface.co/PixilabAI/smalt-medium/resolve/main/README.md
5.07 kB
| license: mit | |
| pipeline_tag: text-to-image | |
| library_name: pytorch | |
| tags: | |
| - pixel-art | |
| - text-to-image | |
| - sprites | |
| - game-assets | |
| - 16x16 | |
| - masked-diffusion | |
| - discrete-diffusion | |
| <p align="center"><img src="assets/logo.png" alt="smalt" width="584"></p> | |
| # smalt-medium · tiny text-to-pixel-art | |
| Made for **[nemini.ai](https://nemini.ai)** & **[pixilab.ai](https://pixilab.ai)**. | |
| <sub>The logo above, every letter and the slime, was drawn by its little sibling | |
| [smalt-small](https://huggingface.co/PixilabAI/smalt-small).</sub> | |
|  | |
| **smalt-medium** draws **16×16 game sprites from a short prompt**: potions, chests, swords, crowns, keys, monsters, | |
| knights. Type `red health potion`, get a clean, transparent, palette-exact sprite you can drop straight into a game. | |
| It is the bigger sibling of smalt-small: sharper shading, cleaner outlines and much better objects and creatures. | |
| | | | | |
| |---|---| | |
| | **Parameters** | 49.3M | | |
| | **Output** | 16×16 RGBA, every pixel one colour of a fixed 512-colour palette (index 0 = transparent) | | |
| | **Speed** | ~0.17 s for 4 sprites on a GPU · ~1.8 s for one sprite on 2 CPU threads | | |
| | **Dependencies** | `torch`, `tokenizers`, `safetensors`, `numpy`, `pillow` (no CLIP, no VAE) | | |
| | **License** | MIT (weights and code) | | |
| Smaller and faster: [smalt-small](https://huggingface.co/PixilabAI/smalt-small) (24.5M), which you can also try in the | |
| browser in **[smalt studio](https://huggingface.co/spaces/PixilabAI/smalt-studio)**. | |
| ## How it works | |
| Every pixel is a token from a 512-colour palette. The model starts from a fully masked 16×16 canvas and fills it in | |
| **in parallel, in about 16 steps**: at each step it predicts a colour for every empty pixel and keeps the ones it is | |
| most sure about. The prompt is read by its own small text encoder, trained together with the image model. Because the | |
| output is palette indices, sprites come out pixel-perfect: hard edges, no blur, no stray anti-aliasing, true | |
| transparency. | |
| The same loop does **inpainting**: lock some pixels, and the model fills the rest around them. | |
| ## Quickstart | |
| ```bash | |
| pip install torch tokenizers safetensors numpy pillow huggingface_hub | |
| ``` | |
| ```python | |
| import sys | |
| from huggingface_hub import snapshot_download | |
| path = snapshot_download("PixilabAI/smalt-medium") | |
| sys.path.insert(0, path) # the repo ships the small `smalt` package | |
| from smalt import SmaltPipeline | |
| pipe = SmaltPipeline(path) # cuda if available, else cpu | |
| sprites = pipe("red health potion", n=4, seed=0) # 4 × 16×16 RGBA PIL images | |
| for i, s in enumerate(sprites): | |
| s.resize((128, 128), 0).save(f"potion_{i}.png") # 0 = nearest neighbour, keeps pixels crisp | |
| ``` | |
| Several prompts in one batch: `pipe(["red key", "silver sword", "treasure chest"])`. | |
| **Settings** (keyword arguments): | |
| | | default | what it does | | |
| |---|---|---| | |
| | `steps` | 16 | decoding steps; 8 is faster, 24–32 a little cleaner | | |
| | `guidance` | 3.0 | how strictly the prompt is followed; 2–5 is the useful range | | |
| | `temperature` | 0.4 | lower = cleaner and more typical, higher = more variety (above ~1.0 adds stray pixels) | | |
| | `seed` | random | same seed + same settings = same sprites | | |
| **Inpainting**: pass a canvas of palette ids and a mask of the pixels to keep. | |
| ```python | |
| import numpy as np | |
| tok = pipe.tokens("blue mana potion", n=1, seed=3) # (1, 256) palette ids | |
| keep = np.zeros(256, bool); keep[128:] = True # keep the bottom half | |
| new = pipe("red health potion", n=4, canvas=tok[0].cpu().numpy(), keep=keep) | |
| ``` | |
| **Live steps**: `pipe.stream(prompt, n=4)` yields the canvas after every step (`step.tokens`, `step.preview`, | |
| `step.confidence`), handy for animations. | |
| ## Prompting | |
| Short prompts work best: **the thing, plus a word or two about it**. Two to six words. | |
|  | |
| - **Objects**: `red health potion`, `treasure chest`, `golden crown`, `iron shield`, `magic spellbook`. | |
| - **Creatures and characters**: `frog with a crown`, `purple slime monster`, `knight in silver armor`, `purple bat`, | |
| `fox`. | |
| - **One extra word helps a lot** when a prompt comes out wrong: | |
| | plain | better | | |
| |---|---| | |
| | `gold coin` (flat yellow disc) | `shiny gold coin` | | |
| | `orange fox` (orange texture) | `cute orange fox`, or just `fox` | | |
| | `mushroom` (comes out blue) | `red mushroom with white spots` | | |
| ## Limitations | |
| - 16×16 only. It is a sprite model, not a scene or portrait model. | |
| - Best at objects, creatures and characters. Tiles (`tile with …`) tend to come out as flat colour fields, letters | |
| (`text …`) are unreliable, effects and interface pieces are rough. | |
| - A colour word plus one short noun can turn into a texture pattern (`orange fox`); add a word (see the table above). | |
| - Silver and white metal can wash out to pale grey. | |
| - English prompts only. | |
| ## License | |
| MIT, see [LICENSE](LICENSE). Sprites you generate are yours to use, including commercially. | |
| Inspiration: [thejagstudio/tessera-small](https://huggingface.co/thejagstudio/tessera-small). | |