Skip to content

Docker Quickstart

Glenn Jocher edited this page May 6, 2022 · 54 revisions

To get started with YOLOv5 πŸš€ in a Docker image follow the instructions below. Other quickstart options for YOLOv5 include our Colab Notebook Open In Colab Open In Kaggle and a GCP Deep Learning VM. UPDATED 6 May 2022.

1. Install Docker and Nvidia-Docker

Docker images come with all dependencies preinstalled, however Docker itself requires installation, and relies of nvidia driver installations in order to interact properly with local GPU resources. The requirements are:

2. Pull Image

The Ultralytics YOLOv5 DockerHub is https://hub.docker.com/r/ultralytics/yolov5 Docker Pulls. Docker Autobuild is used to automatically build images from the latest repository commits, so the ultralytics/yolov5:latest image hosted on the DockerHub will always be in sync with the most recent repository commit. To pull this image:

sudo docker pull ultralytics/yolov5:latest

3. Run Container

Run an interactive instance of this image (called a "container") using -it:

sudo docker run --ipc=host -it ultralytics/yolov5:latest

Run a container with local file access (like COCO training data in /datasets) using -v:

sudo docker run --ipc=host -it -v "$(pwd)"/datasets:/usr/src/datasets ultralytics/yolov5:latest

Run a container with GPU access using --gpus all:

sudo docker run --ipc=host -it --gpus all ultralytics/yolov5:latest

4. Run YOLOv5 πŸš€

Start training, testing, detecting and exporting YOLOv5 models within the running Docker container!

python train.py  # train a model
python val.py --weights yolov5s.pt  # validate a model for Precision, Recall and mAP
python detect.py --weights yolov5s.pt --source path/to/images  # run inference on images and videos
python export.py --weights yolov5s.pt --include onnx coreml tflite  # export models to other formats

ultralytics/yolov5:latest-cpu Image

# YOLOv5 πŸš€ by Ultralytics, GPL-3.0 license

# Start FROM Ubuntu image https://hub.docker.com/_/ubuntu
FROM ubuntu:latest

# Install linux packages
RUN apt update
RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt install -y tzdata
RUN apt install -y python3-pip git zip curl htop screen libgl1-mesa-glx libglib2.0-0
RUN alias python=python3

# Install python dependencies
COPY requirements.txt .
RUN python3 -m pip install --upgrade pip
RUN pip install --no-cache -r requirements.txt albumentations gsutil notebook \
    coremltools onnx onnx-simplifier onnxruntime openvino-dev tensorflow-cpu tensorflowjs \
    torch==1.11.0+cpu torchvision==0.12.0+cpu -f https://download.pytorch.org/whl/cpu/torch_stable.html

# Create working directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Copy contents
COPY . /usr/src/app
RUN git clone https://github.com/ultralytics/yolov5 /usr/src/yolov5

# Downloads to user config dir
ADD https://ultralytics.com/assets/Arial.ttf https://ultralytics.com/assets/Arial.Unicode.ttf /root/.config/Ultralytics/


# Usage Examples -------------------------------------------------------------------------------------------------------

# Build and Push
# t=ultralytics/yolov5:latest-cpu && sudo docker build -f utils/docker/Dockerfile-cpu -t $t . && sudo docker push $t

# Pull and Run
# t=ultralytics/yolov5:latest-cpu && sudo docker pull $t && sudo docker run -it --ipc=host -v "$(pwd)"/datasets:/usr/src/datasets $t

Clone this wiki locally