🚀 Video Mask2Former
Video Mask2Former 是一個在 YouTubeVIS-2021 實例分割數據集上訓練的模型(大尺寸版本,採用 Swin 主幹網絡)。它源自論文 Mask2Former for Video Instance Segmentation,並首次在 此倉庫 中發佈。Video Mask2Former 是原始 Mask2Former 論文 Masked-attention Mask Transformer for Universal Image Segmentation 的擴展。
需要說明的是,發佈 Mask2Former 的團隊並未為此模型編寫模型卡片,本模型卡片由 Hugging Face 團隊編寫。
✨ 主要特性
- 統一範式:Mask2Former 通過預測一組掩碼和相應的標籤,以相同的範式處理實例分割、語義分割和全景分割任務,將這 3 種任務都視為實例分割。
- 性能卓越:相較於之前的 SOTA 模型 MaskFormer,Mask2Former 在性能和效率上均有提升。具體通過以下方式實現:用更先進的多尺度可變形注意力 Transformer 替代像素解碼器;採用帶掩碼注意力的 Transformer 解碼器,在不增加額外計算量的情況下提升性能;通過在子採樣點上計算損失而非整個掩碼,提高訓練效率。
- 視頻分割表現出色:在論文 Mask2Former for Video Instance Segmentation 中,作者表明 Mask2Former 在不修改架構、損失函數甚至訓練流程的情況下,在視頻實例分割任務上也達到了先進水平。
📚 詳細文檔
模型描述
Mask2Former 以相同的範式處理實例分割、語義分割和全景分割任務,即通過預測一組掩碼和相應的標籤,將這 3 種任務都當作實例分割來處理。它在性能和效率上超越了之前的 SOTA 模型 MaskFormer,主要通過以下幾點改進:
- 用更先進的多尺度可變形注意力 Transformer 替代像素解碼器。
- 採用帶掩碼注意力的 Transformer 解碼器,在不引入額外計算的情況下提升性能。
- 通過在子採樣點上計算損失而非整個掩碼,提高訓練效率。
在論文 Mask2Former for Video Instance Segmentation 中,作者證明了 Mask2Former 在不改變架構、損失函數和訓練流程的情況下,在視頻實例分割任務上也能取得先進的性能。

預期用途與限制
你可以使用此特定檢查點進行實例分割。你可以訪問 模型中心 查找該模型其他可能令你感興趣的微調版本。
💻 使用示例
基礎用法
以下是如何使用此模型的示例代碼:
import torch
import torchvision
from huggingface_hub import hf_hub_download
from transformers import AutoImageProcessor, Mask2FormerForUniversalSegmentation
processor = AutoImageProcessor.from_pretrained("facebook/video-mask2former-swin-large-youtubevis-2021-instance")
model = Mask2FormerForUniversalSegmentation.from_pretrained("facebook/video-mask2former-swin-large-youtubevis-2021-instance")
file_path = hf_hub_download(repo_id="shivi/video-demo", filename="cars.mp4", repo_type="dataset")
video = torchvision.io.read_video(file_path)[0]
video_frames = [image_processor(images=frame, return_tensors="pt").pixel_values for frame in video]
video_input = torch.cat(video_frames)
with torch.no_grad():
outputs = model(**video_input)
class_queries_logits = outputs.class_queries_logits
masks_queries_logits = outputs.masks_queries_logits
result = image_processor.post_process_video_instance_segmentation(outputs, target_sizes=[tuple(video.shape[1:3])])[0]
predicted_video_instance_map = result["segmentation"]
如需更多代碼示例,請參考 文檔。
📄 許可證
本項目採用 MIT 許可證。
屬性 |
詳情 |
模型類型 |
Video Mask2Former 模型,在 YouTubeVIS-2021 實例分割數據集上訓練(大尺寸版本,Swin 主幹網絡) |
訓練數據 |
YouTubeVIS-2021 |
標籤 |
視覺、圖像分割 |