pixy

pixy: 16Γ—16 sprites in your palette. Treasure, weapons, magic, creatures, food, nature and props, all drawn by the model.

16Γ—16 pixel-art sprites in your palette. pixy is a small model (about 40M parameters, plus a frozen CLIP text encoder) that draws a sprite from a text prompt, an image, or both. It can only use the colours you give it.

  • Bring any palette of up to 32 colours: PICO-8, Game Boy, your game's own colours, or colours taken from an image. The palette is an input, and the output head can only point at palette entries. Colours outside the palette can't be produced, and palettes never seen in training still work.
  • Image β†’ sprite: a photo, icon or drawing of a single object becomes a clean 16Γ—16 sprite in your palette.
  • Try it: https://pixy-chi.vercel.app
  • Runs in the browser. The ONNX exports run in onnxruntime-web. On a laptop GPU (WebGPU) one sprite takes about half a second.
  • PyTorch weights too (pytorch/), with the model definition and a short sampling script.

What it can draw

One object per sprite, on a transparent background, in whatever palette you give it. Things it draws well (all made by this model):

  • Treasure and items: crowns, gold coins, gems and diamonds, keys, treasure chests, scrolls
  • Weapons and armour: swords, axes, bows, shields
  • Potions and magic: health and mana potions, magic orbs, crystals, wizard hats, dragon eggs
  • Creatures: slimes, ghosts, skulls, cats, frogs, owls, fish
  • Food: apples, pumpkins, cheese, burgers
  • Nature: mushrooms, trees, cacti, fire flowers, hearts
  • Props: candles, lanterns, rockets, bombs

It also turns an image of a single object (a photo, an icon, a drawing) into a sprite, and can recolour an existing sprite or make variations of it. It doesn't do scenes, tilesets, characters larger than 16Γ—16, animation or text.

Use the PyTorch weights

pip install torch transformers safetensors pillow huggingface_hub
hf download harryfrz/pixy --include "pytorch/*" "config.json" --local-dir pixy
cd pixy/pytorch
python sample.py --prompt "spooky mushroom" --palette endesga32 --n 8 --out mushrooms.png
python sample.py --prompt "golden key" --palette "#0f380f,#306230,#8bac0f,#9bbc0f"   # any hex list, 1 to 32 colours

sample.py downloads the CLIP text encoder (openai/clip-vit-base-patch32) on first use. With the same seed it produces the same sprites as the original training checkpoint (checked pixel for pixel). From Python: from sample import generate, parse_palette and generate("golden key", parse_palette("pico8"), n=4, seed=0) returns a [n, 16, 16] array of palette indices (0 is transparent, k is colour k).

How it works

  • Masked discrete diffusion (MaskGIT-style). Start from a fully masked 16Γ—16 grid and fill in all pixels in parallel over about 12 steps, most confident first, with classifier-free guidance.
  • Input sequence: [CLIP text tokens | palette tokens | 256 pixel tokens].
    • Palette colours are embedded from their OKLab values, with no position information, so the palette is an unordered set.
    • A pixel holding colour k is embedded with the same vector as palette entry k.
  • Palette-pointer output head: each pixel scores every palette entry plus one "transparent" option. Shuffling the palette shuffles the outputs identically.
  • Optional guide image: a rough 16Γ—16 picture added to the pixel tokens. It was trained on synthetic degradations of real sprites, so the model learns to turn a rough image back into clean pixel art.

Model inputs and outputs

text_*.onnx

  • Inputs: input_ids and attention_mask, both int64 [B, 32]. Tokenize with CLIP and pad to 32 with 49407.
  • Output: features float32 [B, 33, 512]. The pooled token comes first, then the 32 token states.

sprite_*.onnx (all masks are float32, with 1 meaning true)

Input Shape Meaning
text [B, 33, 512] features from the text encoder
text_mask [B, 33] 1 for real tokens; the first entry is always 1
drop_text [B] 1 for the unconditional branch of classifier-free guidance
pal_lab [B, 32, 3] the palette in OKLab, padded to 32
pal_valid [B, 32] 1 for real palette entries
pix int32 [B, 256] -1 masked, 0 transparent, k for palette entry k (1-based)
guide [B, 256, 4] guide image, OKLab + alpha (zeros if there's no guide)
has_guide [B] 1 if a guide image is given
  • Output: logits [B, 256, 33]. Index 0 is transparent and index k is palette entry k. Padded palette slots get a large negative logit.

Sampling uses 12 steps with guidance scale 3, unmasking the most confident pixels first on a cosine schedule. Every export was checked against the PyTorch model: given the same random numbers, the browser produces pixel-identical sprites in fp32.

Evaluation

Measured on 200 subjects held out of training entirely:

Task Score
Image β†’ sprite (synthetic degradations), pixels exactly right 95.7%
Image β†’ sprite, no prompt 95.5%
Text β†’ sprite, masked-pixel accuracy 69.9%

The fp16 export loses no accuracy: 81.90% against 81.88% for fp32 on a held-out masked-pixel test.

Limitations

  • Only 16Γ—16 sprites, of single objects. Busy scenes and full-frame photos don't work well.
  • In palettes very different from the training palettes, colours are sometimes chosen oddly. For example, a red apple can come out blue in Sweetie-16.
  • A vague prompt combined with a loosely followed image can drift into a different object.

Training data and licence

  • Licence: MIT, for the sprite model weights and the code. The bundled CLIP text encoder keeps its own MIT licence (Copyright (c) 2021 OpenAI); keep both notices when you redistribute the files.
  • Training data: Angais/pixel-art-atlas-1.4m, released under CC0 1.0 (public domain dedication), which lets you train on it and license the result as you like. The sprites in it were generated with Krea 2. The dataset card notes that CC0 doesn't override the Krea 2 Community License, which limits commercial use of Krea's model and its outputs to companies under US$1M annual revenue (Β§2.3) and doesn't restrict training other models on outputs. If you plan heavy commercial use, read those terms yourself; this is not legal advice.
  • Text encoder: the text tower of openai/clip-vit-base-patch32 (MIT), unchanged apart from the export.
  • Preset palettes: from Lospec, credited to their authors.
  • Inspiration: inspired by thejagstudio/tessera-small. No code, weights or configs from it were used.
Downloads last month
30
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Dataset used to train harryfrz/pixy