YOLO (You Only Look Once) is an algorithm for object detection, image segmentation and classification. YOLOv8 is 8th version of YOLO which introduced by Ultralytics in January 2023.
This tutorial explains how to install YOLOv8 inside a Docker container in the Linux. Commands have been tested on Ubuntu.
Prepare environment
Make sure you have installed Docker in your system. If you are using Ubuntu, installation instructions can be found in the post.
Create Docker image
Create Dockerfile
and add the following content:
FROM nvidia/cuda:12.0.0-runtime-ubuntu22.04
WORKDIR /yolov8
ADD https://ultralytics.com/assets/Arial.ttf /root/.config/Ultralytics/
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
libgl1-mesa-glx libglib2.0-0 python3 python3-pip \
&& pip3 install ultralytics \
&& rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["yolo"]
The nvidia/cuda
is used as a base image. So, make sure you have NVIDIA graphics card on the system.
Run command to create Docker image:
docker build -t yolov8 .
Testing YOLOv8
Create directory to store input images:
mkdir -p ~/yolov8/inputs
Download sample image:
curl -o ~/yolov8/inputs/test.jpg https://raw.githubusercontent.com/rdcolema/tensorflow-image-classification/master/cat.jpg
Run the following commands in YOLOv8 container to perform required task:
- Object detection:
docker run -it --rm \
-v ~/yolov8:/yolov8 \
yolov8 detect predict save model=yolov8s.pt source=inputs/test.jpg
Output directory: ~/yolov8/runs/detect
.
- Image segmentation:
docker run -it --rm \
-v ~/yolov8:/yolov8 \
yolov8 segment predict save model=yolov8s-seg.pt source=inputs/test.jpg
Output directory: ~/yolov8/runs/segment
.
- Image classification:
docker run -it --rm \
-v ~/yolov8:/yolov8 \
yolov8 classify predict save model=yolov8s-cls.pt source=inputs/test.jpg
Output directory: ~/yolov8/runs/classify
.
Few results:
Remove Docker image
To remove YOLOv8 image, run the following command:
docker rmi yolov8
The 2 Comments Found
Is there any way to get it to save the output? You show
Output directory: ~/yolov8/runs/detect
I manually created the runs directory, but nothing is saved in it.Hi,
YOLOv8 CLI has been changed. Now, output images are not saved by default. Use
save
argument to do that. I updated the post regarding this. In your case, images will be saved to the/file/data/yolov8/runs/detect
directory. Also, make sure permissions are correct.Leave a Comment
Cancel reply