LocalMode
Transformers

Object Detection

Detect objects in images with bounding boxes using D-FINE.

Detect objects in images with labeled bounding boxes using D-FINE (state-of-the-art DETR refinement) models.

For full API reference (detectObjects(), options, result types, and custom providers), see the Core Vision guide.

See it in action

Try Object Detector for a working demo.

ModelSizeObjectsUse Case
onnx-community/dfine_n_coco-ONNX~4.5MB80 COCO classesState-of-the-art, ultra-small (recommended)
Xenova/detr-resnet-50~160MB80 COCO classesClassic transformer detection
onnx-community/rtdetr_v2_r18vd-ONNX~40MB80 COCO classesReal-time object detection

Drawing Bounding Boxes

Based on the Object Detector showcase app:

import { transformers } from '@localmode/transformers';
import { detectObjects } from '@localmode/core';

const model = transformers.objectDetector('onnx-community/dfine_n_coco-ONNX');

const { objects } = await detectObjects({
  model,
  image: imageDataUrl,
  threshold: 0.5,
});

function drawDetections(
  ctx: CanvasRenderingContext2D,
  objects: DetectedObject[],
  imgWidth: number,
  imgHeight: number
) {
  objects.forEach((obj) => {
    const { x, y, width, height } = obj.box;

    // Draw bounding box
    ctx.strokeStyle = '#00ff00';
    ctx.lineWidth = 2;
    ctx.strokeRect(
      x * imgWidth,
      y * imgHeight,
      width * imgWidth,
      height * imgHeight
    );

    // Draw label
    ctx.fillStyle = '#00ff00';
    ctx.font = '14px sans-serif';
    ctx.fillText(
      `${obj.label} ${(obj.score * 100).toFixed(0)}%`,
      x * imgWidth,
      y * imgHeight - 5
    );
  });
}

Best Practices

Detection Tips

  1. Adjust threshold — Lower threshold (0.3) catches more objects; higher (0.7) reduces false positives
  2. Normalize coordinates — Box coordinates are normalized (0-1); multiply by image dimensions for pixels
  3. COCO classes — D-FINE detects 80 COCO object categories (person, car, dog, etc.)
  4. Image quality matters — Higher resolution images give more accurate detections

Showcase Apps

AppDescriptionLinks
Object DetectorDetect and label objects in uploaded imagesDemo · Source

Next Steps

On this page