zeromodels/mask2former-swin-base-coco-instance
*See [our collection](https://huggingface.co/collections/zeromodels/mask2former-6a8eaf66faaf81a53d54fa03) for all versions of Mask2Former.*
Run Mask2Former with Keras 3: JAX, PyTorch, or TensorFlow
  
zeromodels/mask2former-swin-base-coco-instance
Paper: Masked-attention Mask Transformer for Universal Image Segmentation (arXiv:2112.01527) · HF Papers
Mask2Former improves MaskFormer with masked attention in the transformer decoder, restricting cross-attention to predicted mask regions for sharper boundaries and stronger universal segmentation.
For more details on the model, please go to the upstream model card.
Pure-Keras 3 conversion of `facebook/mask2former-swin-base-coco-instance` for zeromodels. One implementation runs unmodified on TensorFlow / Torch / JAX.
This is a instance checkpoint (Mask2FormerUniversalSegment) (trained for instance; architecture is universal).
✨ Quick start
import os
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
from PIL import Image
from zeromodels.models.mask2former import Mask2FormerUniversalSegment, Mask2FormerImageProcessor
model = Mask2FormerUniversalSegment.from_weights("zeromodels/mask2former-swin-base-coco-instance")
processor = Mask2FormerImageProcessor.from_weights("zeromodels/mask2former-swin-base-coco-instance")
image = Image.open("your_image.jpg").convert("RGB")
output = model(processor(image)["pixel_values"], training=False)
result = processor.post_process_panoptic_segmentation(
output, target_size=(image.height, image.width)
)
print(result["segmentation"].shape)Load any Mask2Former variant the same way with from_weights("zeromodels/<variant>"):
Tips
- Set
KERAS_BACKENDbefore importing Keras / zeromodels. - The task suffix is what the checkpoint was trained for; post-process accordingly.
- See Mask2Former docs and Loading Weights.
- Community / upstream weights:
Mask2FormerUniversalSegment.from_weights("hf:facebook/mask2former-swin-base-coco-instance").
Special Thanks
A huge thank you to the Facebook AI Research Mask2Former authors for creating and releasing these models.
License: MIT.
