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.
- 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.
pip install libreyoloPredict
Weights download from Hugging Face on first use and are cached locally.
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)libreyolo predict model=LibreMaskRCNNr50.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=Truefrom 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.
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)"]) # boxeslibreyolo val model=LibreMaskRCNNr50.pt data=my-dataset.yamlExport
| Task | ONNX | TorchScript | ExecuTorch | TensorRT | OpenVINO | Paddle | MNN | RKNN | ncnn | TFLite | CoreML | Core AI |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Detection | Detection to ONNX: supported. | Detection to TorchScript: not supported | Detection to ExecuTorch: not supported | Detection to TensorRT: not supported | Detection to OpenVINO: not supported | Detection to Paddle: not supported | Detection to MNN: not supported | Detection to RKNN: not supported | Detection to ncnn: not supported | Detection to TFLite: not supported | Detection to CoreML: not supported | Detection to Core AI: not supported |
| Instance segmentation | Instance segmentation to ONNX: supported. | Instance segmentation to TorchScript: not supported | Instance segmentation to ExecuTorch: not supported | Instance segmentation to TensorRT: not supported | Instance segmentation to OpenVINO: not supported | Instance segmentation to Paddle: not supported | Instance segmentation to MNN: not supported | Instance segmentation to RKNN: not supported | Instance segmentation to ncnn: not supported | Instance segmentation to TFLite: not supported | Instance segmentation to CoreML: not supported | Instance 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.
from libreyolo import LibreYOLO model = LibreYOLO("LibreMaskRCNNr50.pt")model.export(format="onnx", imgsz=800)libreyolo export model=LibreMaskRCNNr50.pt format=onnx imgsz=800from 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.
| File | Input (px) | Weights license |
|---|---|---|
| Detection | ||
| LibreMaskRCNNr50.pt | 800 | bsd-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
- Upstream source
- github.com/pytorch/vision
- 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.