Commit bf38ee5
feat: add CompactMask for memory-efficient crop-RLE mask storage
Dense (N, H, W) bool masks cause OOM for aerial imagery (1000 objects x
4K image ~ 8.3 GB). CompactMask encodes each mask as a run-length
sequence of its bounding-box crop, reducing typical usage to ~2 MB.
- New `CompactMask` class with full duck-typed ndarray interface:
`__getitem__`, `__array__`, `shape`, `dtype`, `area`, `sum`, `merge`,
`with_offset` — drop-in compatible with existing `np.ndarray` masks.
- Private row-major RLE helpers: `_rle_encode`, `_rle_decode`, `_rle_area`.
- Phase 2 integration: `Detections` accepts CompactMask for `mask` field;
`validate_mask`, `area` property, and `Detections.merge` all handle it.
- Phase 3 optimised paths: `calculate_masks_centroids` uses crop-space
arithmetic; `MaskAnnotator` paints crop regions directly; `move_detections`
uses `with_offset` instead of materialising dense masks; `get_mask_size_category`
uses `mask.area`.
- 54 new tests (41 unit + 13 integration); all 17 doctests pass.
- All 1190 existing tests pass; pre-commit hooks clean.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent d70bc4f commit bf38ee5
10 files changed
Lines changed: 1443 additions & 17 deletions
File tree
- src/supervision
- annotators
- detection
- tools
- utils
- metrics/utils
- validators
- tests/detection
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
434 | 434 | | |
435 | 435 | | |
436 | 436 | | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
437 | 444 | | |
438 | 445 | | |
439 | 446 | | |
| |||
443 | 450 | | |
444 | 451 | | |
445 | 452 | | |
446 | | - | |
447 | | - | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
448 | 469 | | |
449 | 470 | | |
450 | 471 | | |
| |||
0 commit comments