From 5eb552fcfcfc8a43b68cc593d1e0e15ebde40b20 Mon Sep 17 00:00:00 2001
From: AlexeyAB <alexeyab84@gmail.com>
Date: Fri, 30 Jun 2017 16:01:32 +0000
Subject: [PATCH] Un-commented the line to saving output video file.
---
README.md | 95 ++++++++++++++++++++++++++++++++++++++---------
1 files changed, 77 insertions(+), 18 deletions(-)
diff --git a/README.md b/README.md
index d7b1707..43b21b3 100644
--- a/README.md
+++ b/README.md
@@ -5,9 +5,14 @@
3. [How to train (Pascal VOC Data)](#how-to-train-pascal-voc-data)
4. [How to train (to detect your custom objects)](#how-to-train-to-detect-your-custom-objects)
5. [When should I stop training](#when-should-i-stop-training)
-6. [How to mark bounded boxes of objects and create annotation files](#how-to-mark-bounded-boxes-of-objects-and-create-annotation-files)
+6. [How to improve object detection](#how-to-improve-object-detection)
+7. [How to mark bounded boxes of objects and create annotation files](#how-to-mark-bounded-boxes-of-objects-and-create-annotation-files)
+8. [How to use Yolo as DLL](#how-to-use-yolo-as-dll)
-|  |  https://arxiv.org/abs/1612.08242 |
+|  |  https://arxiv.org/abs/1612.08242 |
+|---|---|
+
+|  |  https://arxiv.org/abs/1612.08242 |
|---|---|
@@ -21,7 +26,7 @@
More details: http://pjreddie.com/darknet/yolo/
##### Requires:
-* **MS Visual Studio 2015 (v140)**: https://www.microsoft.com/download/details.aspx?id=48146
+* **MS Visual Studio 2015 (v140)**: https://go.microsoft.com/fwlink/?LinkId=532606&clcid=0x409 (or offline [ISO image](https://go.microsoft.com/fwlink/?LinkId=615448&clcid=0x409))
* **CUDA 8.0 for Windows x64**: https://developer.nvidia.com/cuda-downloads
* **OpenCV 2.4.9**: https://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.9/opencv-2.4.9.exe/download
- To compile without OpenCV - remove define OPENCV from: Visual Studio->Project->Properties->C/C++->Preprocessor
@@ -107,7 +112,7 @@
5. If you want to build with CUDNN to speed up then:
- * download and install CUDNN: https://developer.nvidia.com/cudnn
+ * download and install **cuDNN 5.1 for CUDA 8.0**: https://developer.nvidia.com/cudnn
* add Windows system variable `cudnn` with path to CUDNN: https://hsto.org/files/a49/3dc/fc4/a493dcfc4bd34a1295fd15e0e2e01f26.jpg
@@ -131,19 +136,21 @@
`..\..\3rdparty\lib\x64\pthreadVC2.lib;cublas.lib;curand.lib;cudart.lib;cudnn.lib;%(AdditionalDependencies)`
- (right click on project) -> properties -> C/C++ -> Preprocessor -> Preprocessor Definitions
+`OPENCV;_TIMESPEC_DEFINED;_CRT_SECURE_NO_WARNINGS;GPU;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)`
+
- open file: `\src\yolo.c` and change 3 lines to your OpenCV-version - `249` (for 2.4.9), `2413` (for 2.4.13), ... :
* `#pragma comment(lib, "opencv_core249.lib")`
* `#pragma comment(lib, "opencv_imgproc249.lib")`
* `#pragma comment(lib, "opencv_highgui249.lib")`
-`OPENCV;_TIMESPEC_DEFINED;_CRT_SECURE_NO_WARNINGS;GPU;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)`
- compile to .exe (X64 & Release) and put .dll-s near with .exe:
`pthreadVC2.dll, pthreadGC2.dll` from \3rdparty\dll\x64
`cusolver64_80.dll, curand64_80.dll, cudart64_80.dll, cublas64_80.dll` - 80 for CUDA 8.0 or your version, from C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin
+`opencv_core249.dll`, `opencv_highgui249.dll` and `opencv_ffmpeg249_64.dll` in `C:\opencv_2.4.9\opencv\build\x64\vc12\bin` or `vc14\bin`
## How to train (Pascal VOC Data):
@@ -162,7 +169,9 @@
5. Run command: `type 2007_train.txt 2007_val.txt 2012_*.txt > train.txt`
-6. Start training by using `train_voc.cmd` or by using the command line: `darknet.exe detector train data/voc.data yolo-voc.cfg darknet19_448.conv.23`
+6. Set `batch=64` and `subdivisions=8` in the file `yolo-voc.2.0.cfg`: [link](https://github.com/AlexeyAB/darknet/blob/master/build/darknet/x64/yolo-voc.cfg#L3)
+
+7. Start training by using `train_voc.cmd` or by using the command line: `darknet.exe detector train data/voc.data yolo-voc.2.0.cfg darknet19_448.conv.23`
If required change pathes in the file `build\darknet\x64\data\voc.data`
@@ -170,20 +179,22 @@
## How to train with multi-GPU:
-1. Train it first on 1 GPU for like 1000 iterations: `darknet.exe detector train data/voc.data yolo-voc.cfg darknet19_448.conv.23`
+1. Train it first on 1 GPU for like 1000 iterations: `darknet.exe detector train data/voc.data yolo-voc.2.0.cfg darknet19_448.conv.23`
-2. Then stop and by using partially-trained model `/backup/yolo-voc_1000.weights` run training with multigpu (up to 4 GPUs): `darknet.exe detector train data/voc.data yolo-voc.cfg yolo-voc_1000.weights -gpus 0,1,2,3`
+2. Then stop and by using partially-trained model `/backup/yolo-voc_1000.weights` run training with multigpu (up to 4 GPUs): `darknet.exe detector train data/voc.data yolo-voc.2.0.cfg yolo-voc_1000.weights -gpus 0,1,2,3`
https://groups.google.com/d/msg/darknet/NbJqonJBTSY/Te5PfIpuCAAJ
## How to train (to detect your custom objects):
-1. Create file `yolo-obj.cfg` with the same content as in `yolo-voc.cfg` (or copy `yolo-voc.cfg` to `yolo-obj.cfg)` and:
+1. Create file `yolo-obj.cfg` with the same content as in `yolo-voc.2.0.cfg` (or copy `yolo-voc.2.0.cfg` to `yolo-obj.cfg)` and:
+ * change line batch to [`batch=64`](https://github.com/AlexeyAB/darknet/blob/master/build/darknet/x64/yolo-voc.cfg#L3)
+ * change line subdivisions to [`subdivisions=8`](https://github.com/AlexeyAB/darknet/blob/master/build/darknet/x64/yolo-voc.cfg#L4)
* change line `classes=20` to your number of objects
- * change line #224 from [`filters=125`](https://github.com/AlexeyAB/darknet/blob/master/cfg/yolo-voc.cfg#L224) to `filters=(classes + 5)*5` (generally this depends on the `num` and `coords`, i.e. equal to `(classes + coords + 1)*num`)
+ * change line #237 from [`filters=125`](https://github.com/AlexeyAB/darknet/blob/master/cfg/yolo-voc.cfg#L237) to `filters=(classes + 5)*5` (generally this depends on the `num` and `coords`, i.e. equal to `(classes + coords + 1)*num`)
- For example, for 2 objects, your file `yolo-obj.cfg` should differ from `yolo-voc.cfg` in such lines:
+ For example, for 2 objects, your file `yolo-obj.cfg` should differ from `yolo-voc.2.0.cfg` in such lines:
```
[convolutional]
@@ -199,9 +210,9 @@
```
classes= 2
- train = train.txt
- valid = test.txt
- names = obj.names
+ train = data/train.txt
+ valid = data/test.txt
+ names = data/obj.names
backup = backup/
```
@@ -235,6 +246,8 @@
8. Start training by using the command line: `darknet.exe detector train data/obj.data yolo-obj.cfg darknet19_448.conv.23`
+ (file `yolo-obj_xxx.weights` will be saved to the `build\darknet\x64\backup\` for each 100 iterations until 1000 iterations has been reached, and after for each 1000 iterations)
+
9. After training is complete - get result `yolo-obj_final.weights` from path `build\darknet\x64\backup\`
* After each 1000 iterations you can stop and later start training from this point. For example, after 2000 iterations you can stop training, and later just copy `yolo-obj_2000.weights` from `build\darknet\x64\backup\` to `build\darknet\x64\` and start training using: `darknet.exe detector train data/obj.data yolo-obj.cfg yolo-obj_2000.weights`
@@ -256,7 +269,7 @@
* **9002** - iteration number (number of batch)
* **0.060730 avg** - average loss (error) - **the lower, the better**
- When you see that average loss **0.060730 avg** enough low at many iterations and no longer decreases then you should stop training.
+ When you see that average loss **0.xxxxxx avg** no longer decreases at many iterations then you should stop training.
2. Once training is stopped, you should take some of last `.weights`-files from `darknet\build\darknet\x64\backup` and choose the best of them:
@@ -264,7 +277,9 @@

- 2.1. At first, you should put filenames of validation images to file `data\voc.2007.test` (format as in `train.txt`) or if you haven't validation images - simply copy `data\train.txt` to `data\voc.2007.test`.
+To get weights from Early Stopping Point:
+
+ 2.1. At first, in your file `obj.data` you must specify the path to the validation dataset `valid = valid.txt` (format of `valid.txt` as in `train.txt`), and if you haven't validation images, just copy `data\train.txt` to `data\valid.txt`.
2.2 If training is stopped after 9000 iterations, to validate some of previous weights use this commands:
@@ -277,9 +292,9 @@
> 7586 7612 7689 RPs/Img: 68.23 **IOU: 77.86%** Recall:99.00%
* **IOU** - the bigger, the better (says about accuracy) - **better to use**
-* **Recall** - the bigger, the better (says about accuracy)
+* **Recall** - the bigger, the better (says about accuracy) - actually Yolo calculates true positives, so it shouldn't be used
-For example, **bigger IUO** gives weights `yolo-obj_8000.weights` - then **use this weights for detection**.
+For example, **bigger IOU** gives weights `yolo-obj_8000.weights` - then **use this weights for detection**.

@@ -291,8 +306,52 @@
|  |  |
|---|---|
+## How to improve object detection:
+
+1. Before training:
+ * set flag `random=1` in your `.cfg`-file - it will increase precision by training Yolo for different resolutions: [link](https://github.com/AlexeyAB/darknet/blob/47409529d0eb935fa7bafbe2b3484431117269f5/cfg/yolo-voc.cfg#L244)
+
+ * desirable that your training dataset include images with objects at diffrent: scales, rotations, lightings, from different sides
+
+2. After training - for detection:
+
+ * Increase network-resolution by set in your `.cfg`-file (`height=608` and `width=608`) or (`height=832` and `width=832`) or (any value multiple of 32) - this increases the precision and makes it possible to detect small objects: [link](https://github.com/AlexeyAB/darknet/blob/47409529d0eb935fa7bafbe2b3484431117269f5/cfg/yolo-voc.cfg#L4)
+
+ * you do not need to train the network again, just use `.weights`-file already trained for 416x416 resolution
+ * if error `Out of memory` occurs then in `.cfg`-file you should increase `subdivisions=16`, 32 or 64: [link](https://github.com/AlexeyAB/darknet/blob/47409529d0eb935fa7bafbe2b3484431117269f5/cfg/yolo-voc.cfg#L3)
+
## How to mark bounded boxes of objects and create annotation files:
Here you can find repository with GUI-software for marking bounded boxes of objects and generating annotation files for Yolo v2: https://github.com/AlexeyAB/Yolo_mark
With example of: `train.txt`, `obj.names`, `obj.data`, `yolo-obj.cfg`, `air`1-6`.txt`, `bird`1-4`.txt` for 2 classes of objects (air, bird) and `train_obj.cmd` with example how to train this image-set with Yolo v2
+
+## How to use Yolo as DLL
+
+1. To compile Yolo as C++ DLL-file `yolo_cpp_dll.dll` - open in MSVS2015 file `build\darknet\yolo_cpp_dll.sln`, set **x64** and **Release**, and do the: Build -> Build yolo_cpp_dll
+ * You should have installed **CUDA 8.0**
+ * To use cuDNN do: (right click on project) -> properties -> C/C++ -> Preprocessor -> Preprocessor Definitions, and add at the beginning of line: `CUDNN;`
+
+2. To use Yolo as DLL-file in your C++ console application - open in MSVS2015 file `build\darknet\yolo_console_dll.sln`, set **x64** and **Release**, and do the: Build -> Build yolo_console_dll
+
+ * you can run your console application from Windows Explorer `build\darknet\x64\yolo_console_dll.exe`
+ * or you can run from MSVS2015 (before this - you should copy 2 files `yolo-voc.cfg` and `yolo-voc.weights` to the directory `build\darknet\` )
+ * after launching your console application and entering the image file name - you will see info for each object:
+ `<obj_id> <left_x> <top_y> <width> <height> <probability>`
+ * to use simple OpenCV-GUI you should uncomment line `//#define OPENCV` in `yolo_console_dll.cpp`-file: [link](https://github.com/AlexeyAB/darknet/blob/a6cbaeecde40f91ddc3ea09aa26a03ab5bbf8ba8/src/yolo_console_dll.cpp#L5)
+
+`yolo_cpp_dll.dll`-API: [link](https://github.com/AlexeyAB/darknet/blob/master/src/yolo_v2_class.hpp#L31)
+```
+class Detector {
+public:
+ Detector(std::string cfg_filename, std::string weight_filename, int gpu_id = 0);
+ ~Detector();
+
+ std::vector<bbox_t> detect(std::string image_filename, float thresh = 0.2);
+ std::vector<bbox_t> detect(image_t img, float thresh = 0.2);
+
+#ifdef OPENCV
+ std::vector<bbox_t> detect(cv::Mat mat, float thresh = 0.2);
+#endif
+};
+```
--
Gitblit v1.10.0