14
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

YOLOv3/4 の Docker イメージの作成方法

Last updated at Posted at 2019-04-13

環境

OS: Ubuntu 18.04.4 LTS
GPU: Geforce GTX1080Ti
NVIDIA ドライバ: 440.100

NVIDIA Container Toolkit のインストール

下記の記事を参考に NVIDIA Container Toolkit をインストール
https://blog.amedama.jp/entry/docker-nvidia-container-toolkit

下記の記事を参考に nvidia-container-runtime をインストール
https://github.com/NVIDIA/nvidia-container-runtime

デフォルトランタイムを変更

$ sudo tee /etc/docker/daemon.json <<EOF
{
    "default-runtime": "nvidia",
    "runtimes": {
        "nvidia": {
            "path": "/usr/bin/nvidia-container-runtime",
            "runtimeArgs": []
        }
    }
}
EOF

Docker イメージのビルド

下記の Dockerfile を使ってイメージをビルドする

Dockerfile
FROM nvidia/cuda:10.2-cudnn8-devel-ubuntu18.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt update && \
    apt install -y --no-install-recommends \
    libopencv-dev \
    build-essential \
    sudo \
    wget \
    git

RUN cd /opt && \
    git clone https://github.com/AlexeyAB/darknet.git && \
    cd darknet && \
    sed -i -e "/GPU=/s/0/1/" Makefile && \
    sed -i -e "/CUDNN=/s/0/1/" Makefile && \
    sed -i -e "/CUDNN_HALF=/s/0/1/" Makefile && \
    sed -i -e "/OPENCV=/s/0/1/" Makefile && \
    make -j$(nproc)

RUN cd /opt/darknet && \
    wget https://pjreddie.com/media/files/yolov3.weights && \
    wget https://pjreddie.com/media/files/yolov3-spp.weights && \
    curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=1cewMfusmPjYWbrnuJRuKhPMwRe_b9PaT" > /dev/null && \
    CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"   && \
    curl -Lb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=1cewMfusmPjYWbrnuJRuKhPMwRe_b9PaT" -o yolov4.weights

WORKDIR /opt/darknet

CMD echo "Finished!"

ビルドを実行する

docker build . -t yolo

YOLOv3 の実行

USBカメラを接続して下記のコマンドを実行する

docker run --rm \
  --net host \
  -e DISPLAY=$DISPLAY \
  -v $HOME/.Xauthority:/root/.Xauthority \
  --privileged \
  yolov ./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights
14
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?