Object detection identifies objects in images or video, classifies them, and locates them with bounding boxes. section 4.2
Hugging Face makes pretrained detection models available through browser-based Hosted Inference API requests, confidence scores, and Python integrations. section 1.2 section 4.2
A detection result commonly provides:
- Object labels identifying detected categories. section 6.2.1
- Confidence scores indicating the model's probabilities. section 4.2
- Bounding-box coordinates locating each object in the image. section 6.2.1
Detecting objects with DETR
Load facebook/detr-resnet-50 with DetrImageProcessor and DetrForObjectDetection, process an image, run inference, then post-process detections with a confidence threshold. Draw each returned box and label using PIL. section 6.2.1
Listing 6.10 Using the facebook/detr-resnet-50 model to detect objects in images
from transformers import DetrImageProcessor, DetrForObjectDetection
import torch
image_processor = DetrImageProcessor.from_pretrained(
"facebook/detr-resnet-50")
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
inputs = image_processor(images = image, #1
return_tensors = "pt")
model.eval()
with torch.no_grad():
outputs = model(**inputs) #2
target_sizes = torch.tensor([image.size[::-1]]) #3
results = image_processor.post_process_object_detection( #4
outputs,
target_sizes = target_sizes,
threshold = 0.9)[0]
print(results)
Use the complete Transformers listing to connect image preprocessing, model inference, target-size conversion, and thresholded object-detection results. section 6.2.1




