Detect Objects in Images with Ultralytics YOLO
Job to be done: Perform various computer vision tasks like object detection and image classification
🇳🇬 Ways to use this in Nigeria
Ideas to get you started, adapt to your situation.
- Student
For your CSC400 final year project, use YOLO to count vehicles (cars, okadas, kekes) in traffic camera footage to analyze congestion patterns in Lagos.
- Entrepreneur
Develop a prototype for an e-commerce app that automatically identifies and tags clothing items (e.g., 'shirt', 'trousers', 'shoe') in user-uploaded photos for easier cataloging.
- 9-5 employee
As an IT staff in a logistics company, build a script to automatically detect and count specific package types in warehouse surveillance images for inventory reconciliation.
What you’ll get
The ability to point an AI at an image and have it find and label the objects in it (a bus, people, a car), drawing boxes around each. This is “object detection”, a kind of “computer vision” (AI that understands images). YOLO is a fast, popular model for it, and Ultralytics packages it so you can run it in a couple of commands. It is intermediate: you use Python and a terminal, but the model is already trained, so you are using it, not building it.
Tools you need
- Python (free): the language you run YOLO with (version 3.8 or newer).
- PyTorch (free): the AI framework YOLO is built on; it gets installed alongside.
- Ultralytics YOLO (freemium): the library with ready-to-use YOLO models. Free for most uses; commercial use may need a licence.
Steps
-
Install Python and PyTorch: get Python from python.org if you do not have it. Then install PyTorch following the picker at pytorch.org/get-started/locally/ (it gives you the exact command for your system). Check with
python --version. -
Install Ultralytics: this one command pulls in YOLO and what it needs:
pip install ultralyticsYou should see packages install and finish with a success message.
-
Detect objects from the command line: run a pre-trained model on a sample image straight from your terminal. (
yolo26n.ptis a small, fast model;sourceis the image to analyze.)yolo predict model=yolo26n.pt source='https://ultralytics.com/images/bus.jpg'It downloads the model if needed, processes the image, and saves a copy with boxes drawn around the detected objects, telling you where it saved it. Open that image to see the results.
-
Detect objects from Python (more control): for use in your own program, save this as
detect_objects.pyand runpython detect_objects.py:from ultralytics import YOLO # Load a pre-trained model model = YOLO("yolo26n.pt") # Run detection on an image (swap the URL for a local file path if you like) results = model("https://ultralytics.com/images/bus.jpg") # Open a window showing the image with the detected objects boxed results[0].show()A window should pop up showing the image with labelled boxes around each detected object.
Original source
Adapted from the official Ultralytics YOLO GitHub repository, which documents and provides examples for their computer-vision models.
Notes & variations
- Free-tier alternative: no powerful computer? Run the same Python in a free cloud notebook like Google Colab, which does the heavy lifting on Google’s machines (mind the session limits).
- Common pitfall: too little memory or no compatible GPU makes large models slow or causes errors. Start small and make sure your setup meets PyTorch’s basic requirements.
- Tip for better results: start with the small
yolo26n.ptfor quick tests, then try larger models (likeyolo26s.ptoryolo26m.pt) for more accuracy at the cost of speed and memory. For your own images, setsourceto the file path, for examplesource='my_image.jpg'.