CoolFace
Modelpublic

zeromodels/mask2former-swin-small-coco-instance

sourceHugging Facemitupdated 27d agoView on Hugging Face
0likes55downloads
Model Card

*See [our collection](https://huggingface.co/collections/zeromodels/mask2former-6a8eaf66faaf81a53d54fa03) for all versions of Mask2Former.*

Run Mask2Former with Keras 3: JAX, PyTorch, or TensorFlow

![GitHub](https://github.com/IMvision12/ZeroModels) ![Docs](https://imvision12.github.io/ZeroModels/mask2former/) ![Collection](https://huggingface.co/collections/zeromodels/mask2former-6a8eaf66faaf81a53d54fa03)

zeromodels/mask2former-swin-small-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-small-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

python
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-small-coco-instance")
processor = Mask2FormerImageProcessor.from_weights("zeromodels/mask2former-swin-small-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>"):

VariantHubTask
mask2former-swin-tiny-coco-instance`zeromodels/mask2former-swin-tiny-coco-instance`instance
mask2former-swin-small-coco-instance`zeromodels/mask2former-swin-small-coco-instance`instance
mask2former-swin-base-coco-instance`zeromodels/mask2former-swin-base-coco-instance`instance
mask2former-swin-large-coco-instance`zeromodels/mask2former-swin-large-coco-instance`instance
mask2former-swin-tiny-coco-panoptic`zeromodels/mask2former-swin-tiny-coco-panoptic`panoptic
mask2former-swin-tiny-ade-semantic`zeromodels/mask2former-swin-tiny-ade-semantic`semantic

Tips

  • Set KERAS_BACKEND before 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-small-coco-instance").

Special Thanks

A huge thank you to the Facebook AI Research Mask2Former authors for creating and releasing these models.

License: MIT.