Metadata-Version: 2.4
Name: mayaku
Version: 1.0.0
Summary: Backend-portable detection / segmentation / keypoint library inspired by Detectron2.
Project-URL: Homepage, https://github.com/datamarkin/mayaku
Author-email: Emrah Nazif <emrah@datamarkin.com>, Datamarkin <support@datamarkin.com>
License: 
                                         Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in the appropriate
              comment syntax for the file format. We also recommend that a
              file or class name and description of purpose be included on the
              same "printed page" as the copyright notice for easier
              identification within third-party archives.
        
           Copyright [yyyy] [name of copyright owner]
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
License-File: LICENSE
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.10
Requires-Dist: numpy>=1.26
Requires-Dist: pillow>=10.0
Requires-Dist: pycocotools>=2.0.7
Requires-Dist: pydantic>=2.6
Requires-Dist: pyyaml>=6.0
Requires-Dist: torch>=2.4
Requires-Dist: torchvision>=0.19
Requires-Dist: typer>=0.12
Provides-Extra: coreml
Requires-Dist: coremltools>=7.2; extra == 'coreml'
Provides-Extra: dev
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.5; extra == 'dev'
Requires-Dist: types-pillow; extra == 'dev'
Requires-Dist: types-pyyaml; extra == 'dev'
Provides-Extra: onnx
Requires-Dist: onnx>=1.16; extra == 'onnx'
Provides-Extra: openvino
Requires-Dist: openvino>=2024.3; extra == 'openvino'
Provides-Extra: tensorrt
Requires-Dist: onnx>=1.16; extra == 'tensorrt'
Requires-Dist: tensorrt>=10.0; (sys_platform != 'darwin') and extra == 'tensorrt'
Description-Content-Type: text/markdown

# Mayaku

[![CI](https://github.com/datamarkin/mayaku/actions/workflows/ci.yml/badge.svg)](https://github.com/datamarkin/mayaku/actions/workflows/ci.yml)
[![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue)](https://www.python.org)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue)](LICENSE)

**Detectron2's R-CNN family, ported to where it actually deploys.** A clean reimplementation of Faster R-CNN, Mask R-CNN, and Keypoint R-CNN that runs on **Apple Silicon**, exports cleanly to **ONNX** / **CoreML** / **OpenVINO** / **TensorRT**, and reproduces all 12 of Detectron2's model-zoo checkpoints to within ±0.1 AP. Pure Python — **no custom CUDA kernels**, **no compiled extensions**, **no wheel chase**. Apache 2.0.

> The 12 D2 model-zoo configs ship pre-converted — `mayaku predict --weights faster_rcnn_R_50_FPN_3x image.jpg` runs on Apple Silicon the first time you call it. Same architectures, same numbers (±0.1 AP), with the deployment paths Detectron2 never had: `.mlpackage`, `.onnx`, `.xml`, `.engine`.

## Why migrate from Detectron2?

| | Detectron2 | Mayaku |
|---|---|---|
| Apple Silicon (MPS) train + eval | not supported | first-class |
| `pip install -e .` on macOS | painful (custom CUDA kernels, ABI mismatches) | works out of the box |
| ONNX export | community-maintained, brittle, broken for keypoint | parity-tested (atol=1e-3, opset 17) |
| CoreML export | not first-class | shipped CLI verb, fp16/fp32, `mlprogram` |
| OpenVINO export | not first-class | shipped CLI verb |
| TensorRT export | not first-class | shipped CLI verb |
| Configuration | yacs / LazyConfig | Pydantic v2 (frozen, fail-at-load) |
| Last release | v0.6 (Nov 2021) | active |

You don't have to retrain or convert anything. All 12 model-zoo checkpoints reproduce D2's published COCO val2017 numbers within ±0.1 AP and ship [pre-converted and hosted](#pre-converted-models) — `mayaku predict --weights <name>` fetches on first use. Switch the runtime, keep the weights.

### Small things that matter

- **Channel order is RGB, not BGR.** Detectron2 inherits Caffe2's BGR convention; Mayaku is RGB-native end-to-end ([ADR 002](docs/decisions/002-rgb-native-image-ingestion.md)). Feed a `cv2.imread`-shaped BGR array and Mayaku will run without complaint and produce **wrong detections, no error raised**. Either swap channels at the boundary (`img = img[:, :, ::-1]` or `mayaku.utils.bgr_to_rgb`) or — better — load with `mayaku.utils.image.read_image` (Pillow under the hood, RGB by default).

- **Pixel mean / std are RGB-ordered.** The defaults are `[123.675, 116.280, 103.530]` / `[58.395, 57.120, 57.375]` (matching torchvision's ImageNet stats in RGB). If you copy a D2 yacs config that pins `PIXEL_MEAN = [103.53, 116.28, 123.675]` (BGR), the model normalises with the channels swapped and you again silently get bad features. Don't override the defaults unless your dataset truly needs different stats — and if you do, write them in RGB order.

- **Fine-tuned `.pkl` files need a one-time conversion.** The 12 zoo checkpoints are [already converted and hosted](#pre-converted-models) — you don't need to do anything for the standard configs. If you have your own fine-tuned `.pkl` from a D2 training run, D2's caffe2-flavoured key names (`conv.norm.*`, `shortcut.*`, `fpn_lateral{N}`) won't `load_state_dict` into Mayaku's torchvision-flavoured layout. Run `python tools/convert_d2_checkpoint.py your_model.pkl -o your_model.pth` once. See [Bringing your own Detectron2 checkpoint](#bringing-your-own-detectron2-checkpoint) below.

## Detectron2 parity

All 12 checkpoints reproduce Detectron2's published numbers within ±0.1 AP. Maximum observed gap across the sweep: **+0.08 AP**.

| Config | D2 published | Mayaku | Δ |
|---|---|---|---|
| `faster_rcnn_R_50_FPN_3x` | 40.2 | 40.23 | +0.03 |
| `faster_rcnn_R_101_FPN_3x` | 42.0 | 42.00 | +0.00 |
| `faster_rcnn_X_101_32x8d_FPN_3x` | 43.0 | 43.07 | +0.07 |
| `mask_rcnn_R_50_FPN_3x` (box / mask) | 41.0 / 37.2 | 40.98 / 37.17 | -0.02 / -0.03 |
| `mask_rcnn_R_101_FPN_3x` (box / mask) | 42.9 / 38.6 | 42.93 / 38.63 | +0.03 / +0.03 |
| `mask_rcnn_X_101_32x8d_FPN_3x` (box / mask) | 44.3 / 39.5 | 44.28 / 39.52 | -0.02 / +0.02 |
| `keypoint_rcnn_R_50_FPN_3x` (box / kpt) | 55.4 / 65.5 | 55.45 / 65.49 | +0.05 / -0.01 |
| `keypoint_rcnn_R_101_FPN_3x` (box / kpt) | 56.4 / 66.1 | 56.43 / 66.04 | +0.03 / -0.06 |
| `keypoint_rcnn_X_101_32x8d_FPN_3x` (box / kpt) | 57.3 / 66.0 | 57.26 / 66.08 | -0.04 / +0.08 |

Full per-checkpoint table including the 1x configs: [`docs/d2_parity_report.md`](docs/d2_parity_report.md). Reproduce the entire sweep with `bash tools/convert_all_d2.sh` (downloads each `.pkl`, converts, evaluates, regenerates the report).

These numbers come from loading and **evaluating** D2's converged weights in Mayaku — not from training from scratch. Training-from-scratch parity (270k iters on COCO, ending at D2's published numbers) is on the roadmap, not measured.

## Pre-converted models

Pass a model name instead of a path; the CLI fetches it on first use:

```bash
mayaku predict configs/detection/faster_rcnn_R_50_FPN_3x.yaml image.jpg \
    --weights faster_rcnn_R_50_FPN_3x
```

Or pre-stage with `mayaku download <name>` (all variants) or `mayaku download <name> --target <variant>`. Cached under `~/.cache/mayaku/v1/models/`, SHA256-verified.

**Variants:** `pth` (PyTorch) · `onnx` (dynamic) · `onnx-fixed` (TRT-friendly) · `coreml-fp16` (Apple Silicon) · `openvino` (Intel CPU/iGPU/Arc/NPU).

### Detection

| Model | pth | onnx | onnx-fixed | coreml-fp16 | openvino |
|---|:---:|:---:|:---:|:---:|:---:|
| faster_rcnn_R_50_FPN_1x | [⬇](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_R_50_FPN_1x.pth) | [⬇](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_R_50_FPN_1x.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_R_50_FPN_1x.800x1344.fixed.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_R_50_FPN_1x.fp16.mlpackage.zip) | [xml](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_R_50_FPN_1x.openvino.xml) · [bin](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_R_50_FPN_1x.openvino.bin) |
| faster_rcnn_R_50_FPN_3x | [⬇](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_R_50_FPN_3x.pth) | [⬇](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_R_50_FPN_3x.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_R_50_FPN_3x.800x1344.fixed.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_R_50_FPN_3x.fp16.mlpackage.zip) | [xml](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_R_50_FPN_3x.openvino.xml) · [bin](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_R_50_FPN_3x.openvino.bin) |
| faster_rcnn_R_101_FPN_3x | [⬇](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_R_101_FPN_3x.pth) | [⬇](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_R_101_FPN_3x.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_R_101_FPN_3x.800x1344.fixed.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_R_101_FPN_3x.fp16.mlpackage.zip) | [xml](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_R_101_FPN_3x.openvino.xml) · [bin](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_R_101_FPN_3x.openvino.bin) |
| faster_rcnn_X_101_32x8d_FPN_3x | [⬇](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_X_101_32x8d_FPN_3x.pth) | [⬇](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_X_101_32x8d_FPN_3x.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_X_101_32x8d_FPN_3x.800x1344.fixed.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_X_101_32x8d_FPN_3x.fp16.mlpackage.zip) | [xml](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_X_101_32x8d_FPN_3x.openvino.xml) · [bin](https://dtmfiles.com/mayaku/v1/models/detection/faster_rcnn_X_101_32x8d_FPN_3x.openvino.bin) |

### Segmentation

| Model | pth | onnx | onnx-fixed | coreml-fp16 | openvino |
|---|:---:|:---:|:---:|:---:|:---:|
| mask_rcnn_R_50_FPN_1x | [⬇](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_R_50_FPN_1x.pth) | [⬇](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_R_50_FPN_1x.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_R_50_FPN_1x.800x1344.fixed.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_R_50_FPN_1x.fp16.mlpackage.zip) | [xml](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_R_50_FPN_1x.openvino.xml) · [bin](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_R_50_FPN_1x.openvino.bin) |
| mask_rcnn_R_50_FPN_3x | [⬇](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_R_50_FPN_3x.pth) | [⬇](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_R_50_FPN_3x.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_R_50_FPN_3x.800x1344.fixed.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_R_50_FPN_3x.fp16.mlpackage.zip) | [xml](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_R_50_FPN_3x.openvino.xml) · [bin](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_R_50_FPN_3x.openvino.bin) |
| mask_rcnn_R_101_FPN_3x | [⬇](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_R_101_FPN_3x.pth) | [⬇](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_R_101_FPN_3x.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_R_101_FPN_3x.800x1344.fixed.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_R_101_FPN_3x.fp16.mlpackage.zip) | [xml](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_R_101_FPN_3x.openvino.xml) · [bin](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_R_101_FPN_3x.openvino.bin) |
| mask_rcnn_X_101_32x8d_FPN_3x | [⬇](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_X_101_32x8d_FPN_3x.pth) | [⬇](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_X_101_32x8d_FPN_3x.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_X_101_32x8d_FPN_3x.800x1344.fixed.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_X_101_32x8d_FPN_3x.fp16.mlpackage.zip) | [xml](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_X_101_32x8d_FPN_3x.openvino.xml) · [bin](https://dtmfiles.com/mayaku/v1/models/segmentation/mask_rcnn_X_101_32x8d_FPN_3x.openvino.bin) |

### Keypoints

| Model | pth | onnx | onnx-fixed | coreml-fp16 | openvino |
|---|:---:|:---:|:---:|:---:|:---:|
| keypoint_rcnn_R_50_FPN_1x | [⬇](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_R_50_FPN_1x.pth) | [⬇](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_R_50_FPN_1x.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_R_50_FPN_1x.800x1344.fixed.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_R_50_FPN_1x.fp16.mlpackage.zip) | [xml](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_R_50_FPN_1x.openvino.xml) · [bin](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_R_50_FPN_1x.openvino.bin) |
| keypoint_rcnn_R_50_FPN_3x | [⬇](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_R_50_FPN_3x.pth) | [⬇](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_R_50_FPN_3x.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_R_50_FPN_3x.800x1344.fixed.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_R_50_FPN_3x.fp16.mlpackage.zip) | [xml](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_R_50_FPN_3x.openvino.xml) · [bin](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_R_50_FPN_3x.openvino.bin) |
| keypoint_rcnn_R_101_FPN_3x | [⬇](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_R_101_FPN_3x.pth) | [⬇](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_R_101_FPN_3x.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_R_101_FPN_3x.800x1344.fixed.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_R_101_FPN_3x.fp16.mlpackage.zip) | [xml](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_R_101_FPN_3x.openvino.xml) · [bin](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_R_101_FPN_3x.openvino.bin) |
| keypoint_rcnn_X_101_32x8d_FPN_3x | [⬇](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_X_101_32x8d_FPN_3x.pth) | [⬇](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_X_101_32x8d_FPN_3x.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_X_101_32x8d_FPN_3x.800x1344.fixed.onnx) | [⬇](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_X_101_32x8d_FPN_3x.fp16.mlpackage.zip) | [xml](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_X_101_32x8d_FPN_3x.openvino.xml) · [bin](https://dtmfiles.com/mayaku/v1/models/keypoints/keypoint_rcnn_X_101_32x8d_FPN_3x.openvino.bin) |

`coreml-fp16` is a zipped `.mlpackage` directory — `mayaku download` unpacks it; if you fetch directly, `unzip` it yourself.

**TensorRT engines aren't hosted** — they're tied to a specific GPU architecture and TRT version, so a hosted file would fail to load on mismatched hardware. Build locally on your CUDA host from the `onnx-fixed` artifact:

```bash
mayaku download faster_rcnn_R_50_FPN_3x --target onnx-fixed
mayaku export tensorrt configs/detection/faster_rcnn_R_50_FPN_3x.yaml \
    --weights faster_rcnn_R_50_FPN_3x \
    --output ~/faster_rcnn_R_50_FPN_3x.engine \
    --sample-height 800 --sample-width 1344
```

Machine-readable index: [`manifest.json`](https://dtmfiles.com/mayaku/v1/models/manifest.json) (size + SHA256 per file; dtmfiles also publishes a `.sha256` sidecar next to every artifact).

## What you get

| | |
|---|---|
| Detectors | Faster R-CNN · Mask R-CNN · Keypoint R-CNN (56×56 heatmaps) |
| Backbones | ResNet-50, ResNet-101, ResNeXt-101 (32×8d) — all with FPN |
| Backends | CUDA · MPS · CPU (single codebase, single wheel) |
| Export targets | `mayaku export {onnx, coreml, openvino, tensorrt}` — all four parity-tested. TensorRT needs a CUDA host. |
| Configuration | Pydantic v2, frozen + extra-forbidden, validated at load |
| Distributed | DDP via `torchrun` (`nccl` on CUDA, `gloo` elsewhere) |
| License | Apache 2.0 |

See [`docs/architecture.md`](docs/architecture.md) for module layout and [`docs/portability.md`](docs/portability.md) for the per-backend matrix.

## Install

```bash
pip install mayaku
```

That's enough for inference, training, evaluation, and `mayaku download`. Export targets are optional extras — install only what you need:

```bash
pip install mayaku[onnx]        # ONNX export (adds the onnx validation package)
pip install mayaku[coreml]      # CoreML export (macOS only)
pip install mayaku[openvino]    # OpenVINO export (Intel targets)
pip install mayaku[tensorrt]    # TensorRT export (CUDA Linux only)
```

**onnxruntime is not bundled in `[onnx]`** because the CPU and CUDA wheels are separate packages — installing the wrong one is the most common source of `libcudart.so` / `.dll` errors. Install the variant that matches your host:

```bash
pip install onnxruntime          # CPU · Apple Silicon · any host without NVIDIA GPU
pip install onnxruntime-gpu      # CUDA Linux / Windows — must match your CUDA version
```

If either is missing when needed, the CLI reports the correct install command for your hardware. You can combine extras freely: `pip install mayaku[onnx,coreml]`. The `tensorrt` extra carries a PEP 508 marker that makes it a no-op on macOS, so `pip install mayaku[onnx,coreml,openvino,tensorrt]` is safe to run on any host.

**Contributing:**

```bash
git clone https://github.com/datamarkin/mayaku
pip install -e ".[dev,onnx]"
```

## Bringing your own Detectron2 checkpoint

The 12 zoo checkpoints are [already converted and hosted](#pre-converted-models) — you don't need to do anything for the standard configs. This section is only for the case where you have a fine-tuned D2 `.pkl` from your own training run and want to keep using those weights.

```bash
# Convert your fine-tuned D2 .pkl → Mayaku .pth (one-shot, no network)
python tools/convert_d2_checkpoint.py your_model_final.pkl -o your_model.pth

# Use the converted .pth like any other Mayaku checkpoint
mayaku predict configs/detection/faster_rcnn_R_50_FPN_3x.yaml image.jpg \
    --weights your_model.pth --device mps
```

Covers Faster / Mask / Keypoint R-CNN with R-50 / R-101 / X-101_32x8d FPN — the same architectures Mayaku ships. Head-specific rename rules are inert when the source `.pkl` doesn't contain them, so a Faster R-CNN checkpoint converts cleanly without flags. See [`tools/README.md`](tools/README.md) for the full rename table and edge cases.

If your D2 setup uses anything Mayaku doesn't ship (DCN, Cascade, Panoptic, DETR, ViTDet…), the converter can't help — see [Small things that matter](#small-things-that-matter) for the missing pieces.

## Quickstart — CLI

The `mayaku` console script bundles four subcommands. Every one takes a YAML config plus per-task arguments.

### Train

```bash
mayaku train configs/detection/faster_rcnn_R_50_FPN_3x.yaml \
    --json /data/coco/annotations/instances_train2017.json \
    --images /data/coco/train2017 \
    --output runs/frcnn_r50 \
    --pretrained-backbone \   # ImageNet weights for the ResNet (recommended)
    --device cuda             # cpu / mps / cuda; default = auto
```

Pass `--pretrained-backbone` for fine-tuning. The schema's `backbone.freeze_at=2` default freezes the ResNet stem + res2, which is only meaningful when those stages already carry useful features. For genuine from-scratch training, set `model.backbone.freeze_at: 0` in the YAML and omit the flag.

`--max-iter N` overrides `solver.max_iter` for smoke runs; `--log-period N` controls per-iteration log frequency (default 20).

### Evaluate

```bash
mayaku eval configs/detection/faster_rcnn_R_50_FPN_3x.yaml \
    --weights runs/frcnn_r50/model_final.pth \
    --json /data/coco/annotations/instances_val2017.json \
    --images /data/coco/val2017
```

Prints the COCO `AP / AP50 / AP75 / APs / APm / APl` dict for boxes, plus masks/keypoints when the meta-architecture asks for them.

### Predict (single image)

```bash
mayaku predict configs/detection/faster_rcnn_R_50_FPN_3x.yaml path/to/image.jpg \
    --weights runs/frcnn_r50/model_final.pth \
    --output detections.json
```

### Download

```bash
# List all available models and variants
mayaku download --list

# Download all variants of a model (pth + onnx + onnx-fixed + coreml-fp16 + openvino)
mayaku download faster_rcnn_R_50_FPN_3x

# Download a single variant
mayaku download faster_rcnn_R_50_FPN_3x --target coreml-fp16

# Pre-stage everything for an offline deployment machine
mayaku download --all

# Skip SHA256 verification (air-gapped or offline-cached environments)
mayaku download faster_rcnn_R_50_FPN_3x --no-verify
```

Artifacts are cached under `~/.cache/mayaku/v1/models/` (or `$XDG_CACHE_HOME/mayaku/…`). Passing a bare model name to `--weights` in `eval` and `predict` triggers the same fetch automatically on first use.

### Export

```bash
# ONNX (required target, opset 17, dynamic batch + spatial axes by default)
mayaku export onnx configs/detection/faster_rcnn_R_50_FPN_3x.yaml \
    --weights runs/frcnn_r50/model_final.pth --output model.onnx

# Same surface for the other targets
mayaku export coreml ...    --output model.mlpackage
mayaku export openvino ...  --output model.xml      # .bin written alongside
mayaku export tensorrt ...  --output model.engine   # CUDA host required
```

Per-target details (what's *in* the exported graph, what stays Python-side, parity tolerances, runtime examples) live in [`docs/export/`](docs/export/).

## Quickstart — Python API

```python
import torch
from mayaku.cli._factory import build_detector
from mayaku.config import load_yaml
from mayaku.inference import Predictor

cfg = load_yaml("configs/detection/faster_rcnn_R_50_FPN_3x.yaml")
model = build_detector(cfg).eval()
model.load_state_dict(
    torch.load("runs/frcnn_r50/model_final.pth", map_location="cpu",
               weights_only=True)
)

pred = Predictor.from_config(cfg, model)
instances = pred("path/to/image.jpg")
# -> mayaku.structures.Instances with .pred_boxes, .scores, .pred_classes
#    (and .pred_masks / .pred_keypoints when the architecture asks for them),
#    all in original-image pixel coordinates.
```

For a complete fine-tuning script (custom dataset discovery, COCO eval hook, Mac-friendly defaults), see [`examples/finetune.py`](examples/finetune.py). For training your own loop, see [`docs/architecture.md`](docs/architecture.md) §"Engine" — `mayaku.engine.SimpleTrainer` / `AMPTrainer` are usable directly.

## Configuration

Configs are pydantic v2 models (see `mayaku.config.schemas`); YAML is the on-disk encoding. Defaults match the Detectron2 3x schedule modulo the overrides recorded in the [decision log](docs/decisions/) (RGB channel order, no rotated boxes, no deformable conv, `device="auto"`).

Minimal example:

```yaml
model:
  meta_architecture: faster_rcnn
  backbone:
    name: resnet50
    norm: FrozenBN
  roi_heads:
    num_classes: 80
solver:
  max_iter: 90000
  steps: [60000, 80000]
  base_lr: 0.02
input:
  min_size_train: [640, 672, 704, 736, 768, 800]
  max_size_train: 1333
```

Configs are frozen and reject unknown fields — you'll get a validation error at load time, not a silent default mid-training.

## Deployment & throughput

Mayaku ships **CoreML, ONNX, OpenVINO, and TensorRT exports as deployment artifacts** for non-PyTorch targets — iOS apps, macOS apps, Linux CPU servers, Windows ML stacks, edge devices, INT8 quantization workflows. **The artifacts are the value, not raw throughput on a developer machine.**

Empirical pattern, measured across three platforms in `benchmarks/`:

- **GPU-available targets (CUDA, Apple Silicon MPS)**: PyTorch eager is essentially optimal for the R-CNN graph shape — multi-output FPN with stride-2 lateral connections defeats the deployment runtimes' fusion templates. Use the exports when you need the artifact format for a non-PyTorch target, not for a speed gain on a developer box.
- **CPU-only Intel targets**: OpenVINO genuinely beats PyTorch CPU by **2.65×** on R-CNN R-50 FPN. The one row where the deployment-runtime claim is real, not just rhetorical. Useful for embedded servers, edge boxes, virtualised CPU instances.
- **Backbone-only feature extraction (any platform)**: ~6× over framework eager on Mac/CUDA, ~3× on Intel CPU. Classifier-shaped graphs are exactly what these runtimes are designed for.

Full per-platform numbers and analysis in [`docs/vs_detectron2.md`](docs/vs_detectron2.md) §"A note on export throughput" and ADRs [004](docs/decisions/004-coreml-export-positioning.md) (CoreML), [005](docs/decisions/005-onnx-tensorrt-positioning.md) (ONNX/TRT/OpenVINO).

## What's deliberately not shipped

- **Deformable convolution** ([ADR 001](docs/decisions/001-drop-deformable-convolution.md)) — the portability cost wasn't worth the marginal AP. D2's strongest DCN-cascade configs sit ~2–4 AP above what Mayaku can reach; we don't try to match them.
- **BGR channel-order configurability** ([ADR 002](docs/decisions/002-rgb-native-image-ingestion.md)) — RGB-native via PIL throughout.
- **Out-of-scope architectures**: rotated boxes, panoptic FPN, Cascade R-CNN, RetinaNet, DETR, ViTDet, PointRend, DensePose, and the rest of D2's `projects/`. Mayaku ships exactly three meta-architectures. For a researcher comparing detector families, D2 is still the right tool.
- **cv2-based image pipeline** — PIL only. Closes a known ~1–2 AP recipe gap on JPEG inputs against D2; a cv2 path is on the roadmap.

For the full honest comparison (including where D2 is still better), see [`docs/vs_detectron2.md`](docs/vs_detectron2.md).

## Roadmap

- **DINOv2 backbones** — ViT ladder (S / B / L / g) for stronger pretrained init, replacing the current ResNet/ResNeXt-only backbone surface. Not yet shipped.
- **Training-from-scratch parity validation** — current parity numbers come from loading + evaluating D2's converged weights, not training to them.
- **Opt-in cv2 image pipeline** — closes the recipe-level AP gap for users who want bit-tighter D2 parity.
- **CI** — `ruff + mypy + pytest` matrix across CPU / MPS / CUDA on every push. Currently testing is manual.
- **Expanded `examples/`** — minimal scripts for inference, fine-tuning, and per-target export.

## Documentation

- [`docs/architecture.md`](docs/architecture.md) — module layout end-to-end.
- [`docs/portability.md`](docs/portability.md) — backend matrix, op fallbacks, AMP rules, MPS quirks, distributed launchers.
- [`docs/extending.md`](docs/extending.md) — adding a backbone / head / dataset / augmentation / exporter.
- [`docs/vs_detectron2.md`](docs/vs_detectron2.md) — capability matrix, parity, non-goals, deployment-throughput analysis.
- [`docs/export/`](docs/export/) — per-target export recipes (ONNX, CoreML, OpenVINO, TensorRT).
- [`docs/decisions/`](docs/decisions/) — architecture decision records.

## Development

```bash
ruff check src tests
mypy
MAYAKU_DEVICE=cpu pytest          # also: mps, cuda
```

`MAYAKU_DEVICE` selects which backend the test suite runs on. Tests marked `cuda` / `mps` / `multi_gpu` / `tensorrt` auto-skip when the active backend or the optional dependency isn't available. There is no CI yet — testing is manual, cross-machine.

## License

Apache 2.0 — see [`LICENSE`](LICENSE).
