Instructions to use zeromodels/mask2former-swin-tiny-coco-instance with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- KerasFormers
How to use zeromodels/mask2former-swin-tiny-coco-instance with KerasFormers:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Keras
How to use zeromodels/mask2former-swin-tiny-coco-instance with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://zeromodels/mask2former-swin-tiny-coco-instance") - Notebooks
- Google Colab
- Kaggle
See our collection for all versions of Mask2Former.
Run Mask2Former with Keras 3: JAX, PyTorch, or TensorFlow
kerasformers/mask2former-swin-tiny-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-tiny-coco-instance for kerasformers. 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 kerasformers.models.mask2former import Mask2FormerUniversalSegment, Mask2FormerImageProcessor
model = Mask2FormerUniversalSegment.from_weights("kerasformers/mask2former-swin-tiny-coco-instance")
processor = Mask2FormerImageProcessor.from_weights("kerasformers/mask2former-swin-tiny-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("kerasformers/<variant>"):
| Variant | Hub | Task |
|---|---|---|
mask2former-swin-tiny-coco-instance |
kerasformers/mask2former-swin-tiny-coco-instance |
instance |
mask2former-swin-small-coco-instance |
kerasformers/mask2former-swin-small-coco-instance |
instance |
mask2former-swin-base-coco-instance |
kerasformers/mask2former-swin-base-coco-instance |
instance |
mask2former-swin-large-coco-instance |
kerasformers/mask2former-swin-large-coco-instance |
instance |
mask2former-swin-tiny-coco-panoptic |
kerasformers/mask2former-swin-tiny-coco-panoptic |
panoptic |
mask2former-swin-tiny-ade-semantic |
kerasformers/mask2former-swin-tiny-ade-semantic |
semantic |
Tips
- Set
KERAS_BACKENDbefore importing Keras / kerasformers. - 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-tiny-coco-instance").
Special Thanks
A huge thank you to the Facebook AI Research Mask2Former authors for creating and releasing these models.
License: MIT.
- Downloads last month
- 41
Model tree for zeromodels/mask2former-swin-tiny-coco-instance
Base model
facebook/mask2former-swin-tiny-coco-instance
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://zeromodels/mask2former-swin-tiny-coco-instance")