Running YOLOv9 with Docker on Windows 11/WSL2 (using GPGPU)

This is a note on object detection with YOLOv9 using Docker on Windows 11/WSL2 and trained weight data. The program was executed with GPGPU.

1. Download YOLOv9

The following command cloned the YOLOv9 source code into the directory /repos/yolov9.

fukagai@ESPRIMOWD2H2:~$ sudo mkdir /repos
fukagai@ESPRIMOWD2H2:~$ sudo chown fukagai.fukagai /repos/
fukagai@ESPRIMOWD2H2:~$ cd /repos/
fukagai@ESPRIMOWD2H2:/repos$ git clone https://github.com/WongKinYiu/yolov9.git

2. Download Learned Weights

I downloaded the trained weights data yolov9-c-converted.pt linked from the following page and saved it as /repos/yolov9/weights/yolov9-c-converted.pt.

https://github.com/WongKinYiu/yolov9

fukagai@ESPRIMOWD2H2:/repos/yolov9$ mkdir weights
fukagai@ESPRIMOWD2H2:/repos/yolov9$ cd weights/
fukagai@ESPRIMOWD2H2:/repos/yolov9/weights$ wget https://github.com/WongKinYiu/yolov9/releases/download/v0.1/yolov9-c-converted.pt

3. Prepare YOLOv9 execution environment with Docker (using GPGPU)

3.1. I executed the following command, which is a slightly modified version of the docker command listed in the Installation section of the following page.

https://github.com/WongKinYiu/yolov9

fukagai@ESPRIMOWD2H2:/repos/yolov9/weights$ sudo docker run --runtime=nvidia --gpus all --name yolov9-gpu -it -v /mnt/c/dev/data/yolov9:/detections -v /repos/yolov9:/yolov9 --shm-size=64g nvcr.io/nvidia/pytorch:21.11-py3

=============
== PyTorch ==
=============

NVIDIA Release 21.11 (build 29224839)
PyTorch Version 1.11.0a0+b6df043

Container image Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
...
NOTE: MOFED driver for multi-node communication was not detected.
      Multi-node communication performance may be reduced.

The directory /mnt/c/dev/data/yolov9 is specified as the directory to store images for object detection and output images. From Windows 11, it is referred to as folder C:\dev\data\yolov9. This directory is /detections in the Docker container.

The directory /repos/yolov9 is specified as the directory where the YOLOv9 source code and trained weight data are located. This directory is /yolov9 in the Docker container.

–gpus all is specified as an option to use GPGPU.

The container name is specified as –name yolov9-gpu.

3.2. The following commands listed in the Installation section of the following page were executed within the Docker container.

https://github.com/WongKinYiu/yolov9

Before executing the command, I checked the existence of the downloaded YOLOv9 source code and weight data.

root@d8077311720e:/workspace# cd /yolov9/
root@d8077311720e:/yolov9# ls
LICENSE.md     classify   detect_dual.py  hubconf.py  requirements.txt  tools          train_triple.py  val_dual.py
README.md      data       export.py       models      scripts           train.py       utils            val_triple.py
benchmarks.py  detect.py  figure          panoptic    segment           train_dual.py  val.py           weights
root@d8077311720e:/yolov9# ls weights/
yolov9-c-converted.pt
root@d8077311720e:/yolov9# apt update
root@d8077311720e:/yolov9# apt install -y zip htop screen libgl1-mesa-glx
root@d8077311720e:/yolov9# pip install seaborn thop

4. Running object detection on a Docker container

The following command was executed to detect objects in the input image /detections/inputs/Birds-Tobagawa-2023-02-19.JPG.

–weights ‘. /weights/yolov9-c-converted.pt’ specifies the downloaded weights data.

root@d8077311720e:/yolov9# python detect.py --source '/detections/inputs/Birds-Tobagawa-2023-02-19.JPG' --device 0 --weights './weights/yolov9-c-converted.pt' --name yolov9_c_c_640_detect
detect: weights=['./weights/yolov9-c-converted.pt'], source=/detections/inputs/Birds-Tobagawa-2023-02-19.JPG, data=data/coco128.yaml, imgsz=[640, 640], conf_thres=0.25, iou_thres=0.45, max_det=1000, device=0, view_img=False, save_txt=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs/detect, name=yolov9_c_c_640_detect, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False, vid_stride=1
YOLO 🚀 v0.1-89-g93f1a28 Python-3.8.12 torch-1.11.0a0+b6df043 CUDA:0 (NVIDIA GeForce GTX 1650, 4096MiB)

Fusing layers...
gelan-c summary: 387 layers, 25288768 parameters, 64944 gradients, 102.1 GFLOPs
image 1/1 /detections/inputs/Birds-Tobagawa-2023-02-19.JPG: 448x640 17 birds, 44.2ms
Speed: 0.6ms pre-process, 44.2ms inference, 7.1ms NMS per image at shape (1, 3, 640, 640)
Results saved to runs/detect/yolov9_c_c_640_detect

Name of the GPGPU, NVIDIA GeForce GTX 1650 was included in the console output.

5. Input and object detection result images

The following command copies the images of object detection results from the directory runs/detect/yolov9_c_c_640_detect/ to /detections/outputs/ so that they can be read from Windows 11.

root@d8077311720e:/yolov9# cp runs/detect/yolov9_c_c_640_detect/Birds-Tobagawa-2023-02-19.JPG /detections/outputs/

The object detection results are shown in the image below. They do not seem to have estimated the bird species. The input image was taken in February 2023 and is an image taken from this page.

The image below is another example. This is an image taken when I climbed Mt. Genta-Mine, taken from this page.

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA