📢
Admissions Open for August 2026 Batch | Free Career Counselling | Limited Scholarships
Register Now →

Learning Guides

Object Detection Using ImageAI in Python

Quick answer: Learn how to perform object detection in images using the ImageAI library in Python with a pretrained model, including complete setup and code.

What is ImageAI?

ImageAI is a Python library that simplifies applying pretrained computer vision models, such as object detection, to your own images, without needing to build or train a deep learning model from scratch.

What is Object Detection?

Object detection identifies what objects are present in an image and draws a bounding box around each one, going further than simple image classification, which only labels the entire image with a single category.

Installation

pip install imageai
pip install tensorflow

A pretrained model file, such as a RetinaNet or YOLO model, also needs to be downloaded separately before running detection.

Running Object Detection

from imageai.Detection import ObjectDetection

detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath("retinanet.pth")
detector.loadModel()

detections = detector.detectObjectsFromImage(
    input_image="street.jpg",
    output_image_path="street_detected.jpg"
)

for detection in detections:
    print(detection["name"], ":", detection["percentage_probability"])

This loads a pretrained model, runs detection on the input image, and saves a new image with bounding boxes drawn around every detected object, printing each object's name and confidence score.

Speed vs Accuracy Trade-Off

detector.detectObjectsFromImage(
    input_image="street.jpg",
    output_image_path="street_detected.jpg",
    minimum_percentage_probability=50
)

Raising minimum_percentage_probability filters out lower confidence detections, trading recall for precision, useful when false positive detections are more costly than missed ones.

Detecting Only Specific Object Types

custom_objects = detector.CustomObjects(person=True, car=True)

detections = detector.detectCustomObjectsFromImage(
    custom_objects=custom_objects,
    input_image="street.jpg",
    output_image_path="street_filtered.jpg"
)

What's Actually Happening Under the Hood

The pretrained models ImageAI uses, such as RetinaNet and YOLO variants, are Convolutional Neural Networks trained on large, publicly labelled datasets like COCO, which cover common everyday object categories such as person, car and dog. Detecting an object type outside that trained vocabulary requires training a custom model on your own labelled data instead.

Practical Applications

  • Counting vehicles or pedestrians in traffic camera footage

  • Automated retail shelf monitoring for stock levels

  • Security systems detecting specific object categories

Common Interview Questions

What is the difference between image classification and object detection?

Classification assigns a single label to an entire image. Object detection identifies multiple individual objects within the image and draws a bounding box around each one.

Can a pretrained object detection model detect any object type out of the box?

No, only the object categories it was originally trained on, such as the common categories in the COCO dataset. Detecting a genuinely new object type requires training a custom model on your own labelled examples.

FAQ

Frequently Asked Questions

What is ImageAI used for?

It is a Python library that simplifies applying pretrained computer vision models, such as object detection, to your own images without training a model from scratch.

What is the difference between image classification and object detection?

Classification assigns a single label to an entire image. Object detection identifies multiple individual objects within the image and draws a bounding box around each one.

Can a pretrained model detect object types it was never trained on?

No. It can only detect the categories present in its original training data, such as the common categories in the COCO dataset. New object types need a custom trained model.

Want This Mapped to Your Own Background?

A free counselling session will tell you which path fits, and will tell you honestly if none of ours does.

Book Free Career Counselling

Keep Reading

Related Articles