Inference Providers documentation

Object detection

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Object detection

Object Detection models allow users to identify objects of certain defined classes. These models receive an image as input and output the images with bounding boxes and labels on detected objects.

For more details about the object-detection task, check out its dedicated page! You will find examples and related materials.

Recommended models

Explore all available models and find the one that suits you best here.

Using the API

import os
from huggingface_hub import InferenceClient

client = InferenceClient(
    provider="hf-inference",
    api_key=os.environ["HF_TOKEN"],
)

output = client.object_detection("cats.jpg", model="facebook/detr-resnet-50")

API specification

Request

Headers
authorizationstringAuthentication header in the form 'Bearer: hf_****' when hf_**** is a personal user access token with “Inference Providers” permission. You can generate one from your settings page.
Payload
inputs*stringThe input image data as a base64-encoded string. If no parameters are provided, you can also provide the image data as a raw bytes payload.
parametersobject
        thresholdnumberThe probability necessary to make a prediction.

Response

Body
(array)object[]Output is an array of objects.
        labelstringThe predicted label for the bounding box.
        scorenumberThe associated score / probability.
        boxobject
                xminintegerThe x-coordinate of the top-left corner of the bounding box.
                xmaxintegerThe x-coordinate of the bottom-right corner of the bounding box.
                yminintegerThe y-coordinate of the top-left corner of the bounding box.
                ymaxintegerThe y-coordinate of the bottom-right corner of the bounding box.
Update on GitHub