Home

Awesome

Alturos.Yolo

Alturos.Yolo

A state of the art real-time object detection system for C# (Visual Studio). This project has CPU and GPU support, with GPU the detection works much faster. The primary goal of this project is an easy use of yolo, this package is available on nuget and you must only install two packages to start detection. In the background we are use the Windows Yolo version of AlexeyAB/darknet. Send an image path or the byte array to yolo and receive the position of the detected objects. Our project is meant to return the object-type and -position as processable data. This library supports YoloV3 and YoloV2 Pre-Trained Datasets

NuGet

Quick install Alturos.Yolo over NuGet

PM> install-package Alturos.Yolo (C# wrapper and C++ dlls 28MB)
PM> install-package Alturos.YoloV2TinyVocData (YOLOv2-tiny Pre-Trained Dataset 56MB)

Object Detection

object detection result

Example code

Detect the type and the position of an image (Automatic configuration)

var configurationDetector = new ConfigurationDetector();
var config = configurationDetector.Detect();
using (var yoloWrapper = new YoloWrapper(config))
{
	var items = yoloWrapper.Detect(@"image.jpg");
	//items[0].Type -> "Person, Car, ..."
	//items[0].Confidence -> 0.0 (low) -> 1.0 (high)
	//items[0].X -> bounding box
	//items[0].Y -> bounding box
	//items[0].Width -> bounding box
	//items[0].Height -> bounding box
}

Detect the type and the position of an image (Manual configuration)

using (var yoloWrapper = new YoloWrapper("yolov2-tiny-voc.cfg", "yolov2-tiny-voc.weights", "voc.names"))
{
	var items = yoloWrapper.Detect(@"image.jpg");
	//items[0].Type -> "Person, Car, ..."
	//items[0].Confidence -> 0.0 (low) -> 1.0 (high)
	//items[0].X -> bounding box
	//items[0].Y -> bounding box
	//items[0].Width -> bounding box
	//items[0].Height -> bounding box
}

Performance

It is important to use GPU mode for fast object detection. It is also important not to instantiate the wrapper over and over again. A further optimization is to transfer the images as byte stream instead of passing a file path. GPU detection is usually 10 times faster!

System requirements

GPU requirements (optional)

It is important to use the mentioned version 10.2

  1. Install the latest Nvidia driver for your graphic device
  2. Install Nvidia CUDA Toolkit 10.2 (must be installed add a hardware driver for cuda support)
  3. Download Nvidia cuDNN v7.6.5 for CUDA 10.2
  4. Copy the cudnn64_7.dll from the output directory of point 2. into the project folder.

Build requirements

Benchmark / Performance

Average processing speed of test images bird1.png, bird2.png, car1.png, motorbike1.png

CPU

ProcessorYOLOv2-tinyYOLOv3yolo9000
Intel i7 3770260 ms2200 ms-
Intel Xeon E5-1620 v3207 ms4327 ms-
Intel Xeon E3-1240 v6182 ms3213 ms-

GPU

Graphic cardSingle precisionMemorySlotYOLOv2-tinyYOLOv3yolo9000
NVIDIA Quadro K420300 GFLOPS2 GBSingle---
NVIDIA Quadro K620768 GFLOPS2 GBSingle---
NVIDIA Quadro K12001151 GFLOPS4 GBSingle---
NVIDIA Quadro P400599 GFLOPS2 GBSingle---
NVIDIA Quadro P6001117 GFLOPS2 GBSingle---
NVIDIA Quadro P6201386 GFLOPS2 GBSingle---
NVIDIA Quadro P10001862 GFLOPS4 GBSingle---
NVIDIA Quadro P20003011 GFLOPS5 GBSingle---
NVIDIA Quadro P40005304 GFLOPS8 GBSingle---
NVIDIA Quadro P50008873 GFLOPS16 GBDual---
NVIDIA GeForce GT 710366 GFLOPS2 GBSingle---
NVIDIA GeForce GT 730693 GFLOPS2-4 GBSingle---
NVIDIA GeForce GT 10301098 GFLOPS2 GBSingle40 ms160 ms-
NVIDIA GeForce GTX 10604372 GFLOPS6 GBDual25 ms100 ms-

Pre-Trained Dataset

A Pre-Trained Dataset contains the Informations about the recognizable objects. A higher Processing Resolution detects object also if they are smaller but this increases the processing time. The Alturos.YoloV2TinyVocData package is the same as YOLOv2-tiny. You can download the datasets manually or integrate them automatically into the code.

//The download takes some time depending on the internet connection.
var repository = new YoloPreTrainedDatasetRepository();
await repository.DownloadDatasetAsync("YOLOv3", ".");
ModelProcessing ResolutionCfgWeightsNames
YOLOv3608x608yolov3.cfgyolov3.weightscoco.names
YOLOv3-tiny416x416yolov3-tiny.cfgyolov3-tiny.weightscoco.names
YOLOv2608x608yolov2.cfgyolov2.weightscoco.names
YOLOv2-tiny416x416yolov2-tiny.cfgyolov2-tiny.weightsvoc.names
yolo9000448x448yolo9000.cfgyolo9000.weights9k.names

yolo9000 require a data directory with this two files coco9k.map and 9k.tree. Merge files with this command type xaa xab > yolo9000.weights

Troubleshooting

If you have some error like DllNotFoundException use Dependencies to check all references are available for yolo_cpp_dll_gpu.dll

If you have some error like NotSupportedException check if you use the latest Nvidia driver

Debugging Tool for Nvidia Gpu

Check graphic device usage "%PROGRAMFILES%\NVIDIA Corporation\NVSMI\nvidia-smi.exe"

Directory Structure

You should have this files in your program directory.

.
├── Alturos.Yolo.dll              # C# yolo wrapper
├── yolo_cpp_dll_cpu.dll      # yolo runtime for cpu
├── yolo_cpp_dll_gpu.dll      # yolo runtime for gpu
├── cudnn64_7.dll             # required by yolo_cpp_dll_gpu (optional only required for gpu processig)
├── opencv_world340.dll       # required by yolo_cpp_dll_xxx (process image as byte data detect_mat)
├── pthreadGC2.dll            # required by yolo_cpp_dll_xxx (POSIX Threads)
├── pthreadVC2.dll            # required by yolo_cpp_dll_xxx (POSIX Threads)
├── msvcr100.dll              # required by pthread (POSIX Threads)

Annotation Tool

To marking bounded boxes of objects in images for training neural network you can use

Dataset of tagged images