--- library_name: "fastforks" pipeline_tag: "object-detection" license: "other" license_name: "cc-by-sa-3.0" license_link: "https://github.com/facebookresearch/detectron2/blob/1e3e13bbf607b54f62205c4c33922521822fb298/MODEL_ZOO.md" tags: - "detection" - "object-detection" - "instance-segmentation" - "cuda" - "pytorch" - "fastforks" --- # detectron2 Mask / Faster R-CNN (R50-FPN) (fastforks) Mask R-CNN (He et al. 2017) and Faster R-CNN (Ren et al. 2015) from the detectron2 model zoo, COCO, ResNet-50 + FPN backbone, RPN proposals, ROIAlign box head (+ mask head); returns boxes, classes and instance masks at the input size. The portable `module()` is backbone + FPN. This repo is the model card only: it holds no weights. fastforks downloads the authors' weights from the links below and checks them against the SHA-256 in the model card. Code: . Kernels for the `kernels` backend: . Original code: at `1e3e13b`. Task: detection. Tier: stable. Outputs: `boxes`, `scores`, `labels`, `masks`. Backends: `portable`, `kernels`. Input: one RGB image. Output: boxes, class labels, scores and instance masks. ## Variants Weights are the authors' files (not hosted here). SHA-256 shortened to 12 hex digits; the full hashes are in [`card.toml`](https://github.com/kleinicke/fastforks/blob/main/src/fastforks/detection/models/rcnn/card.toml). | variant | weights (author link) | SHA-256 | weights licence | commercial use | |---|---|---|---|---| | `faster-rcnn-r50-fpn-3x-coco@1` | [faster_rcnn_R_50_FPN_3x.pkl](https://dl.fbaipublicfiles.com/detectron2/COCO-Detection/faster_rcnn_R_50_FPN_3x/137849458/model_final_280758.pkl) | `3c25caca37ba` | CC-BY-SA-3.0 | yes | | `mask-rcnn-r50-fpn-3x-coco@1` | [mask_rcnn_R_50_FPN_3x.pkl](https://dl.fbaipublicfiles.com/detectron2/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl) | `9a737e290372` | CC-BY-SA-3.0 | yes | ## Licence Original-code strings, recorded as they are (research-use package; check them before any other use). Code: Apache-2.0. Files: `LICENSE`. Training data: COCO 2017 (train, instance annotations) (COCO 2017 train (3x schedule); the ResNet-50 backbone was initialised from MSRA's ImageNet-1k model). - Licence note: The detectron2 model-zoo weights are CC-BY-SA-3.0 (share-alike), and the COCO images carry their own licences. Licence evidence: https://github.com/facebookresearch/detectron2/blob/1e3e13bbf607b54f62205c4c33922521822fb298/MODEL_ZOO.md (License section) ## Input size any H x W >= 32, padded to a multiple of 32 Tested up to (portable, fp16, RTX 5060 Ti 16 GB): `faster-rcnn-r50-fpn-3x-coco` 3000x4000 (0.6 GiB peak allocated, 0.7 reserved); `mask-rcnn-r50-fpn-3x-coco` 3000x4000 (0.6 GiB peak allocated, 0.7 reserved) ## Speed and memory ### Detection, synthetic, 800x1344 | model | time (ms): original fp32 | original | portable | kernels | kernels speed-up: vs original | vs portable | peak memory (MiB, allocated / reserved): original | portable | kernels | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `faster-rcnn-r50-fpn-3x-coco` | 83.6 | 41.4 | 22.77 | 19.47 | 2.1x | 1.2x | 626 / 708 | 390 / 490 | 391 / 450 | | `mask-rcnn-r50-fpn-3x-coco` | 85.4 | 43.5 | 24.59 | 20.98 | 2.1x | 1.2x | 604 / 650 | 352 / 440 | 353 / 400 | ### Startup and first call | model | load (s): original | portable | kernels | first call (s): original | portable | kernels | | --- | --- | --- | --- | --- | --- | --- | | `faster-rcnn-r50-fpn-3x-coco` | 0.73 | 0.53 | 0.14† | 0.04 | 0.25 | 0.04 | | `mask-rcnn-r50-fpn-3x-coco` | 0.97 | 1.50 | 0.22† | 0.84 | 0.42 | 0.04 | ### torch.compile and TensorRT | model | input | portable ms | compile ms | compile s (cold) | TensorRT fp16 ms | ONNX + build s | kernels ms | peak MiB (alloc / reserved): portable | compile | TensorRT (device) | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `faster-rcnn-r50-fpn-3x-coco` | 800x1344 | 22.77 | 18.9 | 26.0 | 5.3 | 16 | 19.47 | 390 / 490 | 413 / 438 | 258 | ### Fixed-size speed and peak memory, all models | model | mode | 640x480 | 1280x720 | 1920x1080 | 12 MP 4000x3000 | | --- | --- | --- | --- | --- | --- | | `faster-rcnn-r50-fpn-3x-coco` | portable | 18.5 ms / 309 / 420 | 21.5 ms / 338 / 426 | 22.2 ms / 352 / 454 | 27.2 ms / 602 / 734 | | `faster-rcnn-r50-fpn-3x-coco` | kernels | 16.1 ms / 310 / 422 | 18.7 ms / 339 / 460 | 18.4 ms / 353 / 488 | 24.6 ms / 602 / 736 | | `mask-rcnn-r50-fpn-3x-coco` | portable | 18.1 ms / 314 / 422 | 23.1 ms / 348 / 440 | 25.1 ms / 413 / 536 | 27.1 ms / 607 / 736 | | `mask-rcnn-r50-fpn-3x-coco` | kernels | 15.6 ms / 315 / 422 | 19.6 ms / 349 / 472 | 22.3 ms / 414 / 568 | 24.6 ms / 607 / 736 | Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB). Hardware, protocol and caveats: [benchmarks](https://github.com/kleinicke/fastforks/blob/main/docs/benchmarks.md) (RTX 5060 Ti 16 GB, sm_120). Original = the authors' code at the precision of portable (fp16, or `(fp32)` where fp16 is unsupported or not finite); original fp32 = its default fp32 run. Peak memory is the torch allocator's. ## Accuracy ### Parity with the original code Every variant is checked against golden outputs of the original code at its pinned commit. CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 1.0 and p99 <= 2.0 (absolute error of the output `boxes`). ## Usage ```python from fastforks import detection model = detection.load("faster-rcnn-r50-fpn-3x-coco") # mode="auto": the preferred backend from recorded measurements result = model("photo.jpg") result.boxes, result.scores, result.labels # [N, 4], [N], [N] result.backend # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16') ``` Install with `pip install fastforks` (see ). Other variants: `faster-rcnn-r50-fpn-3x-coco`, `mask-rcnn-r50-fpn-3x-coco`. ## Kernels backend `detection.load("faster-rcnn-r50-fpn-3x-coco", mode="kernels")` runs our CUDA kernels (`cudnn_hacc`). It needs a prebuilt kernel for your GPU architecture (downloaded from on first use) and a recent NVIDIA driver; if there is none it raises `BackendUnavailableError` with the reason and never falls back silently. `mode="auto"` picks `kernels` when it can run and logs the choice.