Skip to content

crh/yolov5-docker

 
 

Repository files navigation

Yolov5 Docker (Python 3.8 build - CPU default) with Web File Server to view Results

  • Simple BASH commands to Build, or Run.
  • Jetty File Server to use Web Browsers for view the results.
  • MongoDB server to support post processing of outputs from Yolov5
  • MongoDB Express (Web UI) to view/manage the MongoDB data documents (JSON)

Run (demo)

It will download 'yolov5s.pt' on-the-fly to use if not existing.

./run.sh

Images (Input folders)

Input images folders following the sequence of checking (for not empty)

  1. '.env' file:
SOURCE_IMAGES=./images

You can change to whatever images folder:

SOURCE_IMAGES=./my_images
(make sure you also change the volume mapping line as below)
(note: you need to use #VOLUMES_LIST as it is to work)
#VOLUMES_LIST="./my_images:/usr/src/my_images ... (remaining setup)"
  1. If 'empty' in step 1, then it will use alternatives folders:
  • "./my_images" (if you create your own 'my_images' folder in the Host computer)
  • "./images"
  • "./data/images" (the default demo images - other folder failed to provide)
  1. If none of above has images files found, it will abort. Exit 1

Run (if you want to go into the Container)

./run.sh bash

The output will be your Host computer directory, "./runs"

Build

If you like to build your local image, simply run the build.sh command as below:

./build.sh

Start Web-based (Jetty) File Server to view the Results

make up-fileserver
or
sudo docker-compose up -d yolov5-fileserver

You can use any Web-browsers to view the results folders, "./runs":

http:https://0.0.0.0:18881/jetty_base/

You can see the sample Web page in

./doc/yolov5-fileserver.png

Start MongoDB and MongoDB Express (Web-based GUI)

MongoDB can be used to store the results of 'detect.py' for large batch process when providing web services, e.g., REST API or Web UI.

make up-mongo

Then, open URL using Web browsers, e.g, Firefox, Chrome, etc.

http:https://0.0.0.0:28082/

Customized (Detect/Test)

1. Create a folder, "./customized" with whatever files and Shell script (detect.py or detect.sh) you want
├── images
│   ├── bus.jpg
│   └── zidane.jpg
├── requirements.txt
├── run-detect.sh
└── (Whatever_Your_Own_Model_v5.pt)

2. From the Host Shell Xterm: ./run.sh
It will first call ./run-detect.sh (default) which, in turns, it will run your ./customized/run-detect.sh to do whatever you coded your logic in it and it will generate results in the HOST computer directory, ./runs folder.

3. Results outside the Container (in Host computer's currect yolov5-docker/runs directory) as below:
./runs
└── detect
    ├── exp
    │   ├── bus.jpg
    │   ├── labels
    │   └── zidane.jpg

Proxy & Certificate Setup

Corporate Proxy Root and Intemediate Certificates setup for System and Web Browsers (FireFox, Chrome, etc)

  1. Save your corporate's Certificates in the currnet GIT directory, ./certificates First, you need to get your corporate's proxy certificates. You may want to get from your Network/IT department to download the certificate(s), e..g, my_company.crt and then put it in the ./certificates. The automation script in Dockefile will detect the existence of such certificate files and then automatically load them into the Container images being built in progress.
  2. During Docker run command,
   -v `pwd`/certificates:/certificates ... (the rest parameters)

If you want to map to different directory for certificates, e.g., /home/developer/certificates, then

   -v `pwd`/certificates:/home/developer/certificates -e SOURCE_CERTIFICATES_DIR=/home/developer/certificates ... (the rest parameters)
  1. And, inside the Docker startup script to invoke the ~/scripts/setup_system_certificates.sh. Note that the script assumes the certficates are in /certificates directory.
  2. The script ~/scripts/setup_system_certificates.sh will automatic copy to target directory and setup certificates for both System commands (wget, curl, etc) to use and Web Browsers'.

 

CI CPU testing

This repository represents Ultralytics open-source research into future object detection methods, and incorporates lessons learned and best practices evolved over thousands of hours of training and evolution on anonymized client datasets. All code and models are under active development, and are subject to modification or deletion without notice. Use at your own risk.

YOLOv5-P5 640 Figure (click to expand)

Figure Notes (click to expand)
  • GPU Speed measures end-to-end time per image averaged over 5000 COCO val2017 images using a V100 GPU with batch size 32, and includes image preprocessing, PyTorch FP16 inference, postprocessing and NMS.
  • EfficientDet data from google/automl at batch size 8.
  • Reproduce by python test.py --task study --data coco.yaml --iou 0.7 --weights yolov5s6.pt yolov5m6.pt yolov5l6.pt yolov5x6.pt

Pretrained Checkpoints

Model size
(pixels)
mAPval
0.5:0.95
mAPtest
0.5:0.95
mAPval
0.5
Speed
V100 (ms)
params
(M)
FLOPS
640 (B)
YOLOv5s 640 36.7 36.7 55.4 2.0 7.3 17.0
YOLOv5m 640 44.5 44.5 63.1 2.7 21.4 51.3
YOLOv5l 640 48.2 48.2 66.9 3.8 47.0 115.4
YOLOv5x 640 50.4 50.4 68.8 6.1 87.7 218.8
YOLOv5s6 1280 43.3 43.3 61.9 4.3 12.7 17.4
YOLOv5m6 1280 50.5 50.5 68.7 8.4 35.9 52.4
YOLOv5l6 1280 53.4 53.4 71.1 12.3 77.2 117.7
YOLOv5x6 1280 54.4 54.4 72.0 22.4 141.8 222.9
YOLOv5x6 TTA 1280 55.0 55.0 72.0 70.8 - -
Table Notes (click to expand)
  • APtest denotes COCO test-dev2017 server results, all other AP results denote val2017 accuracy.
  • AP values are for single-model single-scale unless otherwise noted. Reproduce mAP by python test.py --data coco.yaml --img 640 --conf 0.001 --iou 0.65
  • SpeedGPU averaged over 5000 COCO val2017 images using a GCP n1-standard-16 V100 instance, and includes FP16 inference, postprocessing and NMS. Reproduce speed by python test.py --data coco.yaml --img 640 --conf 0.25 --iou 0.45
  • All checkpoints are trained to 300 epochs with default settings and hyperparameters (no autoaugmentation).
  • Test Time Augmentation (TTA) includes reflection and scale augmentation. Reproduce TTA by python test.py --data coco.yaml --img 1536 --iou 0.7 --augment

Requirements

Python 3.8 or later with all requirements.txt dependencies installed, including torch>=1.7. To install run:

$ pip install -r requirements.txt

Tutorials

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Inference

detect.py runs inference on a variety of sources, downloading models automatically from the latest YOLOv5 release and saving results to runs/detect.

$ python detect.py --source 0  # webcam
                            file.jpg  # image 
                            file.mp4  # video
                            path/  # directory
                            path/*.jpg  # glob
                            'https://youtu.be/NUsoVlDFqZg'  # YouTube video
                            'rtsp:https://example.com/media.mp4'  # RTSP, RTMP, HTTP stream

To run inference on example images in data/images:

$ python detect.py --source data/images --weights yolov5s.pt --conf 0.25

Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.25, device='', exist_ok=False, img_size=640, iou_thres=0.45, name='exp', project='runs/detect', save_conf=False, save_txt=False, source='data/images/', update=False, view_img=False, weights=['yolov5s.pt'])
YOLOv5 v4.0-96-g83dc1b4 torch 1.7.0+cu101 CUDA:0 (Tesla V100-SXM2-16GB, 16160.5MB)

Fusing layers... 
Model Summary: 224 layers, 7266973 parameters, 0 gradients, 17.0 GFLOPS
image 1/2 /content/yolov5/data/images/bus.jpg: 640x480 4 persons, 1 bus, Done. (0.010s)
image 2/2 /content/yolov5/data/images/zidane.jpg: 384x640 2 persons, 1 tie, Done. (0.011s)
Results saved to runs/detect/exp2
Done. (0.103s)

PyTorch Hub

To run batched inference with YOLOv5 and PyTorch Hub:

import torch

# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')

# Images
dir = 'https://github.com/ultralytics/yolov5/raw/master/data/images/'
imgs = [dir + f for f in ('zidane.jpg', 'bus.jpg')]  # batch of images

# Inference
results = model(imgs)
results.print()  # or .show(), .save()

Training

Run commands below to reproduce results on COCO dataset (dataset auto-downloads on first use). Training times for YOLOv5s/m/l/x are 2/4/6/8 days on a single V100 (multi-GPU times faster). Use the largest --batch-size your GPU allows (batch sizes shown for 16 GB devices).

$ python train.py --data coco.yaml --cfg yolov5s.yaml --weights '' --batch-size 64
                                         yolov5m                                40
                                         yolov5l                                24
                                         yolov5x                                16

Citation

DOI

About Us

Ultralytics is a U.S.-based particle physics and AI startup with over 6 years of expertise supporting government, academic and business clients. We offer a wide range of vision AI services, spanning from simple expert advice up to delivery of fully customized, end-to-end production solutions, including:

  • Cloud-based AI systems operating on hundreds of HD video streams in realtime.
  • Edge AI integrated into custom iOS and Android apps for realtime 30 FPS video inference.
  • Custom data training, hyperparameter evolution, and model exportation to any destination.

For business inquiries and professional support requests please visit us at https://www.ultralytics.com.

Contact

Issues should be raised directly in the repository. For business inquiries or professional support requests please visit https://www.ultralytics.com or email Glenn Jocher at [email protected].

About

YOLOv5 in PyTorch > ONNX > CoreML > TFLite

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 74.0%
  • Shell 24.0%
  • Other 2.0%