Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 7 min read How-to mediumAdept

Universal Image Segmentation with Mask2Former and OneFormer

Instance, semantic and panoptic segmentation have converged on "universal" architectures that treat every task as binary mask classification rather than per-pixel classification, a line running from DETR through MaskFormer to Mask2Former. Mask2Former passes backbone features through a pixel decoder and uses a Transformer decoder to turn queries into mask and class predictions, but still needs separate training per task. OneFormer adds a text encoder conditioned on the task, so a single panoptic training run matches state of the art on all three tasks, at the cost of extra latency. Code shows panoptic inference and post-processing with Mask2Former in 🤗 transformers, plus the class changes needed to fine-tune from MaskFormer notebooks.

Assumes: PyTorch basicsTransformer architecture basics

Related posts

  • Perceiver IO: a scalable, fully-attentional model that works on any modality

    Hugging Face hardMaster

    Perceiver IO avoids the quadratic cost of self-attention by running attention over a small fixed set of latent variables (e.g. 256×1280). Inputs of any modality enter only through cross-attention, where the latents supply the queries, and outputs are produced by cross-attention with trainable decoder queries. Walking through the Hugging Face Transformers implementation, the post traces tensor shapes through preprocessors, the latent encoder, decoders and postprocessors. Examples cover byte-level text classification and masked language modeling, which reaches 81.8 on GLUE without a tokenizer, and image classification with learned, Fourier or convolutional preprocessing.

  • Falcon Perception

    Hugging Face hardMaster

    Falcon Perception is a 0.6B-parameter early-fusion Transformer that handles open-vocabulary grounding and segmentation in one backbone. A hybrid attention mask makes image tokens attend bidirectionally and text/task tokens causally. Each instance is decoded through a coord → size → seg token chain using Fourier-feature heads and a dot-product mask head, which avoids Hungarian matching. It scores 68.0 Macro-F1 on SA-Co versus 62.3 for SAM 3 and leads by wide margins on the new PBench capability benchmark (spatial +21.9, OCR-guided +13.4, dense +14.2), but trails SAM 3 on presence calibration (MCC 0.64 vs 0.82). Training uses DINOv3/SigLIP2 multi-teacher distillation, a 54M-image dataset with 1:1 hard negatives, a three-stage curriculum and Muon for the heads, and a 0.3B Falcon OCR variant reuses the same architecture.

  • Fine-Tune a Semantic Segmentation Model with a Custom Dataset

    Hugging Face mediumAdept

    SegFormer, a hierarchical Transformer encoder with a lightweight MLP decoder, can be fine-tuned for semantic segmentation of sidewalk images for a delivery robot using Hugging Face transformers and datasets. The walkthrough loads the segments/sidewalk-semantic dataset, applies on-the-fly preprocessing with SegformerImageProcessor and ColorJitter augmentation, and fine-tunes the 14MB B0 variant with the Trainer API (lr 6e-5, batch size 2, 50 epochs). Evaluation uses mean IoU, which requires upsampling the model's quarter-resolution logits to label size. Inference follows the same pattern of bilinear interpolation plus argmax, and the model is pushed to the Hub with an auto-generated model card.

  • Zero-shot image-to-text generation with BLIP-2

    Hugging Face mediumAdept

    BLIP-2 connects a frozen pre-trained image encoder (ViT) to a frozen LLM (OPT or Flan-T5) through a lightweight Querying Transformer (Q-Former), the only trainable component. This cuts trainable parameters and pre-training cost while reaching state-of-the-art results on visual-language tasks. Q-Former is pre-trained in two stages. The first uses image-text contrastive, image-grounded generation and image-text matching losses. The second feeds its query outputs to the LLM as a visual prefix under a causal LM loss. Code examples with Hugging Face Transformers show zero-shot image captioning, prompted captioning, visual question answering with a "Question: Answer:" template, and chat-style prompting, which must stay within the 512-token context.

  • Welcome aMUSEd: Efficient Text-to-Image Generation

    Hugging Face mediumAdept

    aMUSEd is an open, permissively licensed reproduction of Google's MUSE that generates images with masked image modeling instead of latent diffusion. A VQGAN tokenizes images, a U-ViT conditioned on CLIP-L/14 text embeddings predicts masked tokens, and inference iteratively keeps the most confident predictions under a cosine mask schedule. At ~800M parameters it needs fewer inference steps than diffusion models and can inpaint zero-shot, though its image quality is not state of the art. It ships in diffusers, and fine-tuning fits in under 11GB of VRAM with 8-bit Adam and fp16, or about 7GB with LoRA.

The quest for software engineering knowledge.

Look:
Layout: