Mask R-CNN

Mask R-CNN adds a per-region mask branch to Faster R-CNN, predicting a segmentation mask alongside each box it detects. LibreYOLO ports the torchvision implementation for detection and instance segmentation.

Tasks
detection, instance segmentation
Sizes
r50 at 800 px
Install
pip install libreyolo
Support tier
Inference only, since v. Predict, validate and export only. Training features do not apply.
Upstream
Mask R-CNN by PyTorch, BSD-3-Clause. Paper, source
Licenses
Code BSD-3-Clause, weights BSD-3-Clause. Commercial use

Install

Mask R-CNN needs no optional extra. Everything it imports is in the base install.

bash
pip install libreyolo

Predict

Weights download from Hugging Face on first use and are cached locally.

Python
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreMaskRCNNr50.pt")result = model(SAMPLE_IMAGE, save=True) print(result.masks.data.shape)for box in result.boxes:    print(box.cls, box.conf, box.xyxy)
CLI
libreyolo predict model=LibreMaskRCNNr50.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=True
Boxes only
from libreyolo import LibreYOLO, SAMPLE_IMAGE # task="detect" skips the mask head and returns boxes from the same# checkpoint, with no masks in the result.model = LibreYOLO("LibreMaskRCNNr50.pt", task="detect")result = model(SAMPLE_IMAGE) print(result.boxes.xyxy)

The returned Results object is the one every family returns, so swapping in a different detector is a one line change. Loading the checkpoint with no task argument returns instance masks, since segmentation is this family's default task; result.masks then carries them alongside the boxes. Passing task="detect" loads the same weights without the mask head and returns boxes only. conf and iou set the confidence and NMS thresholds; Mask R-CNN keeps its upstream NMS step, unlike a query-based detector. See prediction for sources, streaming and result handling.

Variants

One backbone: ResNet-50 with a feature pyramid, using torchvision's v2 Mask R-CNN builder. The published checkpoint carries a BSD-3-Clause license and serves both tasks in this family, so there is no size to choose between.

Validate

val() returns a dictionary of metrics/ keys. Against this checkpoint's default segmentation task, the plain metrics/mAP50-95 key holds the mask score, and the same run reports boxes under the (B) suffix so both are available from one pass.

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreMaskRCNNr50.pt")metrics = model.val(data="my-dataset.yaml") print(metrics["metrics/mAP50-95"])      # masksprint(metrics["metrics/mAP50-95(B)"])   # boxes
CLI
libreyolo val model=LibreMaskRCNNr50.pt data=my-dataset.yaml

Export

TaskONNXTorchScriptExecuTorchTensorRTOpenVINOPaddleMNNRKNNncnnTFLiteCoreMLCore AI
DetectionDetection to ONNX: supported. Detection to TorchScript: not supportedDetection to ExecuTorch: not supportedDetection to TensorRT: not supportedDetection to OpenVINO: not supportedDetection to Paddle: not supportedDetection to MNN: not supportedDetection to RKNN: not supportedDetection to ncnn: not supportedDetection to TFLite: not supportedDetection to CoreML: not supportedDetection to Core AI: not supported
Instance segmentationInstance segmentation to ONNX: supported. Instance segmentation to TorchScript: not supportedInstance segmentation to ExecuTorch: not supportedInstance segmentation to TensorRT: not supportedInstance segmentation to OpenVINO: not supportedInstance segmentation to Paddle: not supportedInstance segmentation to MNN: not supportedInstance segmentation to RKNN: not supportedInstance segmentation to ncnn: not supportedInstance segmentation to TFLite: not supportedInstance segmentation to CoreML: not supportedInstance segmentation to Core AI: not supported

Mask R-CNN exports to ONNX only, at batch size 1. The exported graph keeps the upstream resize and mask-paste steps inside it, so LibreYOLO forces dynamic=True regardless of what is passed, to keep the graph valid for sources that are not square. An exported .onnx file loads back through LibreYOLO() on its file suffix and returns the same Results.

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreMaskRCNNr50.pt")model.export(format="onnx", imgsz=800)
CLI
libreyolo export model=LibreMaskRCNNr50.pt format=onnx imgsz=800
Use the exported file
from libreyolo import LibreYOLO, SAMPLE_IMAGE # The factory routes on the file suffix, so an exported artifact loads# like any checkpoint and returns the same Results object.model = LibreYOLO("LibreMaskRCNNr50.onnx")result = model(SAMPLE_IMAGE) print(result.masks.data.shape)

Checkpoints

Every published weight file for this family. The one checkpoint below is listed under detect, but the same file loads for segmentation too: pass no task argument and it returns masks by default.

FileInput (px)Weights license
Detection
LibreMaskRCNNr50.pt800bsd-3-clause

Every file above exists in the LibreYOLO org today and downloads on first use.

Licensing

Check the license on the Hugging Face repository of the specific weights you download. Every checkpoint in the LibreYOLO org carries one, and they are not always the same across a family. That repository is the authoritative source; the summary below describes what applied when this page was last verified.

This is a description of the licenses involved, not legal advice. If the answer matters commercially, read the licenses yourself and take your own counsel.

Original work
Mask R-CNN, PyTorch
Upstream license
BSD-3-Clause
LibreYOLO code
MIT
Weights
BSD-3-Clause, republished at huggingface.co/LibreYOLO
Interpretation
BSD-3-Clause is a permissive license, so this code can be used in commercial and closed-source products with no obligation on your own application code. It asks only that you keep the copyright notice and disclaimer with any copy you redistribute, and it carries no patent grant. The published checkpoint used for parity testing is not distributed in the LibreYOLO source tree: torchvision's own documentation notes that a pretrained model's terms may depend on its training data, so the Hugging Face mirror ships the BSD text on that implied basis and repeats the caveat rather than issuing an explicit checkpoint-specific grant.

Mask R-CNN is built as a subclass of LibreYOLO's Faster R-CNN wrapper: it shares the same torchvision source and BSD-3-Clause license, and adds the mask predictor and mask RoI head from the same ported commit.

Verified against LibreYOLO v1.5.0. Support tables, checkpoints and benchmark numbers on this page are generated from the released library and the published weights, not written by hand.