YOLO (You Only Look Once) is a popular object detection algorithm well-documented by Ultralytics. For more comprehensive details, visit the Ultralytics YOLO documentation.
To perform object detection using YOLO in a Docker environment, you can run the following commands:
# Install
docker pull ultralytics/ultralytics
# Run YOLO prediction on a remote image
docker run -v ./runs:/usr/src/ultralytics/runs ultralytics/ultralytics yolo predict model=yolov8n.pt source=https://ultralytics.com/images/bus.jpg
# View result
open runs/detect/predict/bus.jpg
# Run YOLO prediction on a locally saved image
docker run -v ./runs:/usr/src/ultralytics/runs ultralytics/ultralytics yolo predict model=yolov8n.pt source=./runs/detect/predict/bus.jpg
# View result
open runs/detect/predict2/bus.jpg
Follow these steps to quickly install and use YOLO for object detection:
- Create a Python Virtual Environment:
python3 -m venv venv
source venv/bin/activate
- Install Required Dependencies:
# Option 1: Specific Torch and Torchaudio versions
pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2
# Option 2: Alternative versions
pip install torch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2
- Install Ultralytics:
pip install ultralytics
- Verify Torch Installation:
pip show torch
- Run YOLO Prediction:
yolo predict model=yolov8n.pt source='https://ultralytics.com/images/bus.jpg'
- Open the Resulting Image:
open runs/detect/predict/bus.jpg
You can find the Python code to perform YOLO predictions in the Ultralytics documentation.
from ultralytics import YOLO
# Load a model
model = YOLO("yolov8n.pt") # load an official model
#### model = YOLO("path/to/best.pt") # load a custom model
# Predict with the model
results = model("https://ultralytics.com/images/bus.jpg") # predict on an image
Detectron2, another object detection tool, has a lot of promise. However it's not been kept up to date. For more information, visit Meta's AI Detectron2 page.
Here is the YouTube comments thread around the topic https://www.youtube.com/watch?v=1qWxkFhhv2s&lc=Ugw3-v9v-HrF5KJvvTZ4AaABAg
Use this guide to quickly set up and run YOLO object detection, either using Docker or a Python virtual environment. Happy coding!