Skip to content

feat(models): add RT-DETRv2 object detection model #79

Closed

Description

@inureyes

mlxcel supports language and vision-language models that emit token streams, but it has no object detection model. RT-DETRv2 is a real-time detection transformer that emits bounding boxes rather than tokens, so it needs a task path outside the generate flow.

Goal

Add RT-DETRv2 to mlxcel and expose it through a new top-level mlxcel detect subcommand that takes an image and emits detections as (left, top, right, bottom, label, confidence), in text or JSON format.

Architecture

  • ResNet-50-vd / ResNet-101-vd backbone (3-conv stem, stride-2 maxpool, AvgPool-based downsampling shortcuts), with depth read from the backbone config so both variants share one module.
  • Hybrid encoder: an AIFI transformer on the deepest level (2D sine position embedding), a top-down FPN, and a bottom-up PAN with RepVGG/CSPRep blocks.
  • Encoder query selection (top-K over the flattened position-by-label score space) feeding a six-layer deformable-attention decoder with iterative bounding-box refinement.
  • Multi-scale deformable attention implemented via a pure-MLX bilinear grid_sample (padding zeros, align_corners false).

Scope

  • New src/vision/detection/rt_detr_v2/ module: config, sanitize, shared layers, backbone, hybrid encoder, transformer, model, processor, predictor.
  • A weight-rename pipeline that runs only when raw HF layout is detected, so pre-converted checkpoints load as-is.
  • The forward path runs in float32 for box-coordinate precision; weights stay in their stored dtype so float32-input by stored-weight promotion matches the reference.
  • New mlxcel detect subcommand (--model, --image, --threshold, --format text|json). Detection is a separate subcommand rather than an overload of generate or serve because the output is boxes, not tokens.
  • Leave the existing model-type classification module untouched; this model registers no new generate-flow model type.

Acceptance criteria

  • mlxcel detect loads a ResNet-50-vd RT-DETRv2 checkpoint and prints detections for an image, in both text and JSON.
  • Detections match a reference predictor on the same checkpoint and image within bf16 rounding and bilinear-resize differences.
  • Unit tests cover grid_sample, max and average pool, nearest upsample, anchor generation, inverse-sigmoid round-trip, the rename pipeline, and config parsing.

Activity

  1. added
    type:enhancement
    area:models
    area:cli
    priority:medium
    status:ready
    on May 24, 2026
  2. self-assigned this
    on May 29, 2026
  3. added this to the 0.1 milestone on Jun 5, 2026
  4. added
    status:done
    and removed
    status:ready
    on Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:cliarea:modelspriority:mediumstatus:donetype:enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions