---
title: "Universal Image Segmentation with Mask2Former and OneFormer"
description: "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."
url: "https://swe.quest/articles/universal-image-segmentation-with-mask2former-and-oneformer-c9679decf8636d8b"
canonical: "https://huggingface.co/blog/mask2former"
source: "Hugging Face"
published: "2023-01-19"
difficulty: "medium"
kind: "How-to"
reading_minutes: 7
tags: ["computer-vision","machine-learning","python"]
---

# Universal Image Segmentation with Mask2Former and OneFormer

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2023-01-19, 7 min read, How-to. Original: [https://huggingface.co/blog/mask2former](https://huggingface.co/blog/mask2former)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Computer vision](https://swe.quest/tags/computer-vision.md) (AI & ML)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)
- [Python](https://swe.quest/tags/python.md) (Languages)

## Prerequisites

- PyTorch basics
- Transformer architecture basics ([easy posts on System design](https://swe.quest/tags/system-design.md?difficulty=easy))

## Keywords

Mask2Former, OneFormer, Hugging Face Transformers, MaskFormer, DETR, COCO, Swin Transformer

## Related posts

- [Perceiver IO: a scalable, fully-attentional model that works on any modality](https://swe.quest/articles/perceiver-io-a-scalable-fully-attentional-model-that-works-on-any-modality-f8a43e7ae2c87797.md): Hugging Face · 2021-12-15 · Hard · 21 min read · Machine learning, LLMs, Computer vision, Python
  Perceiver IO avoids the quadratic cost of self-attention by running attention over a small fixed set of latent variables (e.g. 256×1280).
- [Falcon Perception](https://swe.quest/articles/falcon-perception-59c8fff8e44842f2.md): Hugging Face · 2026-04-01 · Hard · 14 min read · Computer vision, Model training, Evaluation, Machine learning
  Falcon Perception is a 0.6B-parameter early-fusion Transformer that handles open-vocabulary grounding and segmentation in one backbone.
- [Fine-Tune a Semantic Segmentation Model with a Custom Dataset](https://swe.quest/articles/fine-tune-a-semantic-segmentation-model-with-a-custom-dataset-99839187c9e4f9fb.md): Hugging Face · 2022-03-17 · Medium · 9 min read · Computer vision, Model training, Python, Machine learning
  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.
- [Zero-shot image-to-text generation with BLIP-2](https://swe.quest/articles/zero-shot-image-to-text-generation-with-blip-2-6253370fee81620e.md): Hugging Face · 2023-02-15 · Medium · 7 min read · Computer vision, LLMs, Machine learning, Python
  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.
- [Welcome aMUSEd: Efficient Text-to-Image Generation](https://swe.quest/articles/welcome-amused-efficient-text-to-image-generation-12956b5ceb4a1912.md): Hugging Face · 2024-01-04 · Medium · 6 min read · Computer vision, Model training, Inference & serving, Open source
  aMUSEd is an open, permissively licensed reproduction of Google's MUSE that generates images with masked image modeling instead of latent diffusion.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
