Metadata-Version: 2.4
Name: mayaku
Version: 2.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: scipy>=1.11
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)](https://github.com/datamarkin/mayaku/blob/main/LICENSE)

**The computer vision library that learns *your* data fastest.**

Mayaku trains detection, instance segmentation, and keypoint models on your own data. It's
built around **UniQuery** — a query-based head — on a **ConvNeXt** backbone, and its base
models are **purpose-pretrained on Objects365** (365 classes) for fast fine-tuning, so they
transfer to *your* classes quickly. Pure Python, zero custom CUDA kernels: one `pip install mayaku` trains on CUDA,
Apple Silicon, ROCm, or CPU, and exports to ONNX, CoreML, OpenVINO, and TensorRT.
Apache 2.0.

![RF100-VL, nano class: mean AP vs training time, normalized to Mayaku's time per dataset](https://raw.githubusercontent.com/datamarkin/mayaku/main/curve_nano.png)

On [RF100-VL](https://rf100-vl.org/) — a 100-dataset benchmark of real, custom
datasets — Mayaku's nano model reaches a higher mean AP than either comparison, and reaches
it in shorter training time.

| Library | Params (M) | Mean AP @[.50:.95] | Training time |
|---|---:|---:|---:|
| **mayaku-n** | **12.9** | **0.535** | **1.0× (≈14 min)** |
| rfdetr-n | 30.5 | 0.513 | 7.7× (≈112 min) |
| yolo26n | 2.4 | 0.496 | 1.05× |

> **Benchmark scope:** nano class only, the **alphabetically first 20 of the 100** RF100-VL
> datasets, single RTX 3060. Each library runs its own default recipe to completion. Times
> are normalized to Mayaku's per-dataset time; the wall-clock shown is the median dataset.
> Parameter counts differ substantially across these models — they are listed so the
> comparison is read with that in mind.
> **The benchmark is still running** — the remaining datasets and the s/m/l tiers will be
> published as they finish, whatever they show.

> Built for developers with a few hundred images of *their own thing* — retail shelves,
> defects on a line, insect wings — not another COCO leaderboard entry.

---

## Highlights

- **Fine-tunes fast.** Strong accuracy on small custom datasets in minutes of wall-clock. See the RF100-VL result above. `auto_config` adapts the recipe (schedule, LR,
  augmentation) to your dataset size automatically.
- **Objects365-pretrained.** Base models are pretrained on a large, detection-native dataset
  (365 classes), a broad starting point for transfer.
- **UniQuery head.** Anchor-free, NMS-free, with image-conditioned query generation (QGN)
  and train-with-N / deploy-with-fewer refinement stages — a built-in speed/accuracy dial
  with no retraining. Detection and instance segmentation share one query representation;
  keypoints ride the same detector.
- **Four sizes, three tasks.** `mayaku-n` through `mayaku-l`, each in detection,
  instance-segmentation, and keypoint variants.
- **Runs everywhere.** Pure Python: no wheel chase, no ABI mismatches, no custom ops.
  CUDA / Apple Silicon (MPS) / ROCm / CPU from a single install.
- **Deploys everywhere.** Parity-tested exports to `onnx`, `coreml`, `openvino`, `tensorrt`.

## Install

```bash
pip install mayaku
```

That covers training, inference, evaluation, and model download. Export targets are optional
extras — install only what you need:

```bash
pip install mayaku[onnx]       # ONNX export
pip install mayaku[coreml]     # CoreML export (macOS)
pip install mayaku[openvino]   # OpenVINO export (Intel CPU/iGPU/NPU)
pip install mayaku[tensorrt]   # TensorRT export (CUDA Linux)
```

## Quickstart

Fine-tune on your own dataset. Point at COCO-format splits — a train annotation JSON and its
image directory; add a val split to get final eval. Pass a bundled model name as `weights`
and it fetches the pretrained checkpoint on first use; the class-specific head re-initialises
automatically when your class count differs.

```python
from pathlib import Path

from mayaku import train

result = train(
    weights="mayaku-n-det",
    train_annotations=Path("data/train/_annotations.coco.json"),
    train_images=Path("data/train"),
    val_annotations=Path("data/valid/_annotations.coco.json"),
    val_images=Path("data/valid"),
)
print(result["final_box_ap"], result["final_weights"])
```

Same thing from the CLI:

```bash
mayaku train --weights mayaku-n-det \
  --annotations data/train/_annotations.coco.json --images data/train \
  --val-annotations data/valid/_annotations.coco.json --val-images data/valid
```

Predict:

```python
from mayaku import from_pretrained

predictor = from_pretrained("mayaku-n-det")   # config + weights + device, auto
instances = predictor("photo.jpg")
print(instances.pred_boxes.tensor, instances.scores, instances.pred_classes)
```

```bash
mayaku predict mayaku-n-det photo.jpg --output result.json
```

## Throughput

Measured on a single **NVIDIA RTX 3060** — the most commonly owned GPU among Hugging Face
users ([HF hardware](https://huggingface.co/hardware)) — at 640px, TensorRT FP16, back-to-back
with no cooldown pauses between timed inferences. CUDA numbers first; MPS and CPU figures
will follow.

Two throughput numbers are reported: **engine** is the model forward pass alone, **end-to-end**
is the full path you actually run (decode → preprocess → inference → post-process). The
end-to-end number is the one that predicts your application's frame rate.

| Model | Params (M) | Engine FPS | **End-to-end FPS** | VRAM (MB) |
|---|---:|---:|---:|---:|
| `mayaku-n-det` | 12.9 | 247.7 | **198.8** | 314 |
| `mayaku-s-det` | 23.1 | 175.7 | **150.0** | 340 |
| `mayaku-m-det` | 36.0 | 137.6 | **121.0** | 370 |
| `mayaku-l-det` | 57.8 | 98.9 | **93.5** | 464 |

## Model zoo

Base models are hosted and fetched on first use — pass a name instead of a path. Every size
ships in three task variants, `mayaku-<size>-{det,seg,key}` (e.g. `mayaku-m-seg`).

| Name | Backbone | Tasks | Profile |
|---|---|---|---|
| `mayaku-n` | ConvNeXt-femto | det · seg · key | edge / real-time |
| `mayaku-s` | ConvNeXt-nano | det · seg · key | balanced |
| `mayaku-m` | ConvNeXt-tiny | det · seg · key | high accuracy |
| `mayaku-l` | ConvNeXt-tiny (wide) | det · seg · key | max accuracy |
| `mayaku-xl` | ConvNeXt-base | det · seg · key | *in training* |
| `mayaku-xxl` | ConvNeXt-base (6-stage decoder) | det · seg · key | *in training* |

List available names:

```bash
mayaku download --list
```

Machine-readable index: [`manifest.json`](https://dtmfiles.com/mayaku/v1/models/manifest.json)
(size + SHA256 per file). Cached under `<project>/cache/mayaku/` (override with `MAYAKU_CACHE_DIR`).

## Why Mayaku

**Query-based, without DETR's slow convergence.** UniQuery keeps the clean query-based design
— no anchors, no NMS — but reaches its accuracy in a fraction of the training time DETR-style
detectors need. An image-conditioned **query generator (QGN)** seeds queries from FPN
features instead of learning them from scratch, so the model starts from meaningful proposals
on epoch one. Train with N refinement stages, deploy with fewer — a speed/accuracy dial with
no retraining.

**Detection, segmentation, and keypoints from one family.** Detection and instance
segmentation are driven by a single shared query representation (the mask head is conditioned
on the same per-object query features); keypoints run on the same detector. One architecture,
one training path, three tasks.

**Portability by design.** No deformable conv, no custom CUDA/C++ ops, RGB-native end-to-end
— the same code path runs on every backend and survives the trip through ONNX → CoreML /
OpenVINO / TensorRT.

## Deploy anywhere

```bash
mayaku export onnx     mayaku-n-det --output model.onnx
mayaku export coreml   mayaku-n-det --output model.mlpackage
mayaku export openvino mayaku-n-det --output model.xml      # .bin alongside
mayaku export tensorrt mayaku-n-det --output model.engine   # CUDA host
```

All four are parity-tested. On Intel CPU targets OpenVINO measurably beats PyTorch eager; on
GPU targets the export *artifact* is the value.

## Built on

UniQuery stands on a line of query-based detection work: **Sparse R-CNN** (iterative dynamic
refinement), **QueryInst** (query-conditioned dynamic mask heads), **Featurized Query R-CNN**
(image-conditioned query generation), and **DN-DETR** (denoising for stable early box
regression). The backbone is **ConvNeXt**, with several sizes built on torchvision's
implementation. What Mayaku adds is the unified head family, the Objects365 pretraining
recipe, and the fine-tuning defaults that make them converge quickly on small datasets.

## Roadmap

- **`mayaku-xl` / `mayaku-xxl`** — ConvNeXt-base models (2- and 6-stage decoders) for the
  high-accuracy end of the range.
- **Full RF100-VL results** — all 100 datasets across every size tier.
- **Curated custom-class models** — ready-to-use weights on a hand-picked set of common
  real-world classes (people, vehicles, and more), for projects that don't want to start from
  the Objects365 base.
- **Documentation** — a proper docs site, coming soon.

## License

Apache 2.0 — see [`LICENSE`](https://github.com/datamarkin/mayaku/blob/main/LICENSE). Applies to the full library and every published
model weight.
