Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Neuml Txtai Object Detection

From Leeroopedia


Knowledge Sources
Domains Machine Learning, Computer Vision, Object Detection, Image Classification, Transformers
Last Updated 2026-02-10 01:00 GMT

Overview

Concrete tool for applying object detection and image classification models to images provided by txtai.

Description

Objects extends HFPipeline and wraps either the Hugging Face object-detection or image-classification pipeline depending on the classification flag. It detects objects in images and returns (label, score) tuples sorted by descending confidence score. Results are filtered by a configurable confidence threshold (default 0.9) and deduplicated by label (keeping the highest-scoring instance of each label). The flatten parameter returns just label strings instead of tuples. The pipeline requires the PIL (Pillow) library.

Usage

Use Objects when you need to detect and label objects in images or classify images into categories. Object detection mode returns labeled bounding box results, while classification mode returns image-level labels. This is useful for content tagging, visual search, and image understanding workflows.

Code Reference

Source Location

  • Repository: Neuml_Txtai
  • File: src/python/txtai/pipeline/image/objects.py

Signature

class Objects(HFPipeline):
    def __init__(self, path=None, quantize=False, gpu=True, model=None, classification=False, threshold=0.9, **kwargs)
    def __call__(self, images, flatten=False, workers=0)

Import

from txtai.pipeline.image.objects import Objects

I/O Contract

Inputs

Name Type Required Description
path str No Model path; accepts Hugging Face model hub id or local path. Uses default model for task if not provided.
quantize bool No If True, quantizes the model to int8 (CPU only). Defaults to False.
gpu bool or int No True/False to enable GPU, or a specific GPU device id. Defaults to True.
classification bool No If True, uses image classification instead of object detection. Defaults to False.
threshold float No Minimum confidence score for including results. Defaults to 0.9.
images str, PIL.Image, or list Yes (call) A single image (file path string or PIL Image) or a list of images.
flatten bool No (call) If True, returns just label strings instead of (label, score) tuples. Defaults to False.
workers int No (call) Number of concurrent workers for data processing. Defaults to 0.

Outputs

Name Type Description
result list List of (label, score) tuples sorted by descending score and deduplicated by label. If flatten=True, returns a list of label strings. For single image input, returns a 1D list; for list input, returns a 2D list.

Usage Examples

from txtai.pipeline.image.objects import Objects

# Create an object detection pipeline
detector = Objects("facebook/detr-resnet-50", gpu=True)

# Detect objects in a single image
results = detector("street_scene.jpg")
# Returns: [("car", 0.98), ("person", 0.95), ("traffic light", 0.92)]

# Flatten to just labels
results = detector("street_scene.jpg", flatten=True)
# Returns: ["car", "person", "traffic light"]

# Detect objects in multiple images
results = detector(["image1.jpg", "image2.jpg"])

# Use image classification mode
classifier = Objects(classification=True, threshold=0.5)
results = classifier("cat.jpg")
# Returns: [("tabby cat", 0.95), ("domestic cat", 0.88)]

# Lower the threshold for more results
detector = Objects(threshold=0.5)
results = detector("scene.jpg")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment