Skip to content

Commit

Permalink
Merge branch 'master' into dev/cenit/include
Browse files Browse the repository at this point in the history
  • Loading branch information
cenit authored May 25, 2019
2 parents 578d1c0 + 3aca0b7 commit a3d5cc4
Show file tree
Hide file tree
Showing 42 changed files with 2,420 additions and 629 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ LDFLAGS+= -L/usr/local/zed/lib -lsl_core -lsl_input -lsl_zed
#-lstdc++ -D_GLIBCXX_USE_CXX11_ABI=0
endif

OBJ=image_opencv.o http_stream.o gemm.o utils.o dark_cuda.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o darknet.o detection_layer.o captcha.o route_layer.o writing.o box.o nightmare.o normalization_layer.o avgpool_layer.o coco.o dice.o yolo.o detector.o layer.o compare.o classifier.o local_layer.o swag.o shortcut_layer.o activation_layer.o rnn_layer.o gru_layer.o rnn.o rnn_vid.o crnn_layer.o demo.o tag.o cifar.o go.o batchnorm_layer.o art.o region_layer.o reorg_layer.o reorg_old_layer.o super.o voxel.o tree.o yolo_layer.o upsample_layer.o lstm_layer.o
OBJ=image_opencv.o http_stream.o gemm.o utils.o dark_cuda.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o darknet.o detection_layer.o captcha.o route_layer.o writing.o box.o nightmare.o normalization_layer.o avgpool_layer.o coco.o dice.o yolo.o detector.o layer.o compare.o classifier.o local_layer.o swag.o shortcut_layer.o activation_layer.o rnn_layer.o gru_layer.o rnn.o rnn_vid.o crnn_layer.o demo.o tag.o cifar.o go.o batchnorm_layer.o art.o region_layer.o reorg_layer.o reorg_old_layer.o super.o voxel.o tree.o yolo_layer.o upsample_layer.o lstm_layer.o conv_lstm_layer.o
ifeq ($(GPU), 1)
LDFLAGS+= -lstdc++
OBJ+=convolutional_kernels.o activation_kernels.o im2col_kernels.o col2im_kernels.o blas_kernels.o crop_layer_kernels.o dropout_layer_kernels.o maxpool_layer_kernels.o network_kernels.o avgpool_layer_kernels.o
Expand Down
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# Yolo-v3 and Yolo-v2 for Windows and Linux
### (neural network for object detection) - Tensor Cores can be used on [Linux](https://github.com/AlexeyAB/darknet#how-to-compile-on-linux) and [Windows](https://github.com/AlexeyAB/darknet#how-to-compile-on-windows-using-vcpkg)

Contributors: https://github.com/AlexeyAB/darknet/graphs/contributors
More details: http://pjreddie.com/darknet/yolo/


[![CircleCI](https://circleci.com/gh/AlexeyAB/darknet.svg?style=svg)](https://circleci.com/gh/AlexeyAB/darknet)
[![TravisCI](https://travis-ci.org/AlexeyAB/darknet.svg?branch=master)](https://travis-ci.org/AlexeyAB/darknet)
[![AppveyorCI](https://ci.appveyor.com/api/projects/status/594bwb5uoc1fxwiu/branch/master?svg=true)](https://ci.appveyor.com/project/AlexeyAB/darknet/branch/master)
[![Contributors](https://img.shields.io/github/contributors/AlexeyAB/Darknet.svg)](https://github.com/AlexeyAB/darknet/graphs/contributors)
[![License: Unlicense](https://img.shields.io/badge/license-Unlicense-blue.svg)](https://github.com/AlexeyAB/darknet/blob/master/LICENSE)


* [Requirements (and how to install dependecies)](#requirements)
* [Pre-trained models](#pre-trained-models)
* [Explanations in issues](https://github.com/AlexeyAB/darknet/issues?q=is%3Aopen+is%3Aissue+label%3AExplanations)
* [Yolo v3 in other frameworks (TensorFlow, OpenVINO, OpenCV-dnn, ...)](#yolo-v3-in-other-frameworks)
* [Yolo v3 in other frameworks (TensorRT, TensorFlow, PyTorch, OpenVINO, OpenCV-dnn,...)](#yolo-v3-in-other-frameworks)

0. [Improvements in this repository](#improvements-in-this-repository)
1. [How to use](#how-to-use-on-the-command-line)
Expand Down Expand Up @@ -44,7 +45,7 @@ More details: http://pjreddie.com/darknet/yolo/
* Windows or Linux
* **CMake >= 3.8** for modern CUDA support: https://cmake.org/download/
* **CUDA 10.0**: https://developer.nvidia.com/cuda-toolkit-archive (on Linux do [Post-installation Actions](https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#post-installation-actions))
* **OpenCV > 2.4**: use your preferred package manager (brew, apt), build from source using [vcpkg](https://github.com/Microsoft/vcpkg) or download from [OpenCV official site](https://opencv.org/releases.html) (on Windows set system variable `OpenCV_DIR` = `C:\opencv\build` - where are the `include` and `x64` folders [image](https://user-images.githubusercontent.com/4096485/53249516-5130f480-36c9-11e9-8238-a6e82e48c6f2.png))
* **OpenCV >= 2.4**: use your preferred package manager (brew, apt), build from source using [vcpkg](https://github.com/Microsoft/vcpkg) or download from [OpenCV official site](https://opencv.org/releases.html) (on Windows set system variable `OpenCV_DIR` = `C:\opencv\build` - where are the `include` and `x64` folders [image](https://user-images.githubusercontent.com/4096485/53249516-5130f480-36c9-11e9-8238-a6e82e48c6f2.png))
* **cuDNN >= 7.0 for CUDA 10.0** https://developer.nvidia.com/rdp/cudnn-archive (on **Linux** copy `cudnn.h`,`libcudnn.so`... as desribed here https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html#installlinux-tar , on **Windows** copy `cudnn.h`,`cudnn64_7.dll`, `cudnn64_7.lib` as desribed here https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html#installwindows )
* **GPU with CC >= 3.0**: https://en.wikipedia.org/wiki/CUDA#GPUs_supported
* on Linux **GCC or Clang**, on Windows **MSVC 2015/2017/2019** https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community
Expand Down Expand Up @@ -73,9 +74,11 @@ You can get cfg-files by path: `darknet/cfg/`

#### Yolo v3 in other frameworks

* Convert `yolov3.weights`/`cfg` model to **TensorFlow**: by using [mystic123](https://github.com/mystic123/tensorflow-yolo-v3) or [jinyu121](https://github.com/jinyu121/DW2TF) projects, and [TensorFlow-lite](https://www.tensorflow.org/lite/guide/get_started#2_convert_the_model_format)
* To use Yolo v3 model in **Intel OpenVINO** (Myriad X / USB Neural Compute Stick / Arria FPGA): read this [manual](https://software.intel.com/en-us/articles/OpenVINO-Using-TensorFlow#converting-a-darknet-yolo-model)
* **OpenCV-dnn** is very fast DNN implementation on CPU (x86/ARM-Android), use `yolov3.weights`/`cfg` with: [C++ example](https://github.com/opencv/opencv/blob/8c25a8eb7b10fb50cda323ee6bec68aa1a9ce43c/samples/dnn/object_detection.cpp#L192-L221), [Python example](https://github.com/opencv/opencv/blob/8c25a8eb7b10fb50cda323ee6bec68aa1a9ce43c/samples/dnn/object_detection.py#L129-L150)
* **TensorFlow:** convert `yolov3.weights`/`cfg` files to `yolov3.ckpt`/`pb/meta`: by using [mystic123](https://github.com/mystic123/tensorflow-yolo-v3) or [jinyu121](https://github.com/jinyu121/DW2TF) projects, and [TensorFlow-lite](https://www.tensorflow.org/lite/guide/get_started#2_convert_the_model_format)
* **Intel OpenVINO 2019 R1:** (Myriad X / USB Neural Compute Stick / Arria FPGA): read this [manual](https://software.intel.com/en-us/articles/OpenVINO-Using-TensorFlow#converting-a-darknet-yolo-model)
* **OpenCV-dnn** is a very fast DNN implementation on CPU (x86/ARM-Android), use `yolov3.weights`/`cfg` with: [C++ example](https://github.com/opencv/opencv/blob/8c25a8eb7b10fb50cda323ee6bec68aa1a9ce43c/samples/dnn/object_detection.cpp#L192-L221), [Python example](https://github.com/opencv/opencv/blob/8c25a8eb7b10fb50cda323ee6bec68aa1a9ce43c/samples/dnn/object_detection.py#L129-L150)
* **PyTorch > ONNX > CoreML > iOS** how to convert cfg/weights-files to pt-file: [ultralytics/yolov3](https://github.com/ultralytics/yolov3#darknet-conversion) and [iOS App](https://itunes.apple.com/app/id1452689527)
* **TensorRT** for YOLOv3 (-70% faster inference): [TensorRT & DeepStream](https://github.com/NVIDIA-AI-IOT/deepstream_reference_apps)

##### Examples of results

Expand Down Expand Up @@ -164,6 +167,8 @@ Before make, you can set such options in the `Makefile`: [link](https://github.c
* `OPENMP=1` to build with OpenMP support to accelerate Yolo by using multi-core CPU
* `LIBSO=1` to build a library `darknet.so` and binary runable file `uselib` that uses this library. Or you can try to run so `LD_LIBRARY_PATH=./:$LD_LIBRARY_PATH ./uselib test.mp4` How to use this SO-library from your own code - you can look at C++ example: https://github.com/AlexeyAB/darknet/blob/master/src/yolo_console_dll.cpp
or use in such a way: `LD_LIBRARY_PATH=./:$LD_LIBRARY_PATH ./uselib data/coco.names cfg/yolov3.cfg yolov3.weights test.mp4`
* `ZED_CAMERA=1` to build a library with ZED-3D-camera support (should be ZED SDK installed), then run
`LD_LIBRARY_PATH=./:$LD_LIBRARY_PATH ./uselib data/coco.names cfg/yolov3.cfg yolov3.weights zed_camera`

To run Darknet on Linux use examples from this article, just use `./darknet` instead of `darknet.exe`, i.e. use this command: `./darknet detector test ./cfg/coco.data ./cfg/yolov3.cfg ./yolov3.weights`

Expand Down Expand Up @@ -514,9 +519,9 @@ Example of custom object detection: `darknet.exe detector test data/obj.data yol
* increase network resolution in your `.cfg`-file (`height=608`, `width=608` or any value multiple of 32) - it will increase precision


* check that each object is mandatory labeled in your dataset - no one object in your data set should not be without label. In the most training issues - there are wrong labels in your dataset (got labels by using some conversion script, marked with a third-party tool, ...). Always check your dataset by using: https://github.com/AlexeyAB/Yolo_mark
* check that each object that you want to detect is mandatory labeled in your dataset - no one object in your data set should not be without label. In the most training issues - there are wrong labels in your dataset (got labels by using some conversion script, marked with a third-party tool, ...). Always check your dataset by using: https://github.com/AlexeyAB/Yolo_mark

* for each object which you want to detect - there must be at least 1 similar object in the Training dataset with about the same: shape, side of object, relative size, angle of rotation, tilt, illumination. So desirable that your training dataset include images with objects at diffrent: scales, rotations, lightings, from different sides, on different backgrounds - you should preferably have 2000 different images for each class or more, and you should train `2000*classes` iterations or more
* for each object which you want to detect - there must be at least 1 similar object in the Training dataset with about the same: shape, side of object, relative size, angle of rotation, tilt, illumination. So desirable that your training dataset include images with objects at diffrent: scales, rotations, lightings, from different sides, on different backgrounds - you should preferably have 2000 different images for each class or more, and you should train `2000*classes` iterations or more

* desirable that your training dataset include images with non-labeled objects that you do not want to detect - negative samples without bounded box (empty `.txt` files) - use as many images of negative samples as there are images with objects

Expand Down
4 changes: 4 additions & 0 deletions build/darknet/darknet.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@
<CompileAs>Default</CompileAs>
<UndefinePreprocessorDefinitions>NDEBUG</UndefinePreprocessorDefinitions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<AdditionalUsingDirectories>
</AdditionalUsingDirectories>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand Down Expand Up @@ -183,6 +185,7 @@
<ClCompile Include="..\..\src\compare.c" />
<ClCompile Include="..\..\src\connected_layer.c" />
<ClCompile Include="..\..\src\convolutional_layer.c" />
<ClCompile Include="..\..\src\conv_lstm_layer.c" />
<ClCompile Include="..\..\src\cost_layer.c" />
<ClCompile Include="..\..\src\cpu_gemm.c" />
<ClCompile Include="..\..\src\crnn_layer.c" />
Expand Down Expand Up @@ -248,6 +251,7 @@
<ClInclude Include="..\..\src\col2im.h" />
<ClInclude Include="..\..\src\connected_layer.h" />
<ClInclude Include="..\..\src\convolutional_layer.h" />
<ClInclude Include="..\..\src\conv_lstm_layer.h" />
<ClInclude Include="..\..\src\cost_layer.h" />
<ClInclude Include="..\..\src\crnn_layer.h" />
<ClInclude Include="..\..\src\crop_layer.h" />
Expand Down
2 changes: 2 additions & 0 deletions build/darknet/darknet_no_gpu.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
<ClCompile Include="..\..\src\compare.c" />
<ClCompile Include="..\..\src\connected_layer.c" />
<ClCompile Include="..\..\src\convolutional_layer.c" />
<ClCompile Include="..\..\src\conv_lstm_layer.c" />
<ClCompile Include="..\..\src\cost_layer.c" />
<ClCompile Include="..\..\src\cpu_gemm.c" />
<ClCompile Include="..\..\src\crnn_layer.c" />
Expand Down Expand Up @@ -254,6 +255,7 @@
<ClInclude Include="..\..\src\col2im.h" />
<ClInclude Include="..\..\src\connected_layer.h" />
<ClInclude Include="..\..\src\convolutional_layer.h" />
<ClInclude Include="..\..\src\conv_lstm_layer.h" />
<ClInclude Include="..\..\src\cost_layer.h" />
<ClInclude Include="..\..\src\crnn_layer.h" />
<ClInclude Include="..\..\src\crop_layer.h" />
Expand Down
3 changes: 3 additions & 0 deletions build/darknet/x64/partial.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ darknet.exe partial cfg/yolov3-spp.cfg yolov3-spp.weights yolov3-spp.conv.85 85
darknet.exe partial cfg/yolov3-tiny.cfg yolov3-tiny.weights yolov3-tiny.conv.15 15


darknet.exe partial cfg/yolov3-tiny.cfg yolov3-tiny.weights yolov3-tiny.conv.14 14


darknet.exe partial cfg/yolo9000.cfg yolo9000.weights yolo9000.conv.22 22


Expand Down
2 changes: 2 additions & 0 deletions build/darknet/yolo_cpp_dll.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
<ClCompile Include="..\..\src\compare.c" />
<ClCompile Include="..\..\src\connected_layer.c" />
<ClCompile Include="..\..\src\convolutional_layer.c" />
<ClCompile Include="..\..\src\conv_lstm_layer.c" />
<ClCompile Include="..\..\src\cost_layer.c" />
<ClCompile Include="..\..\src\cpu_gemm.c" />
<ClCompile Include="..\..\src\crnn_layer.c" />
Expand Down Expand Up @@ -254,6 +255,7 @@
<ClInclude Include="..\..\src\col2im.h" />
<ClInclude Include="..\..\src\connected_layer.h" />
<ClInclude Include="..\..\src\convolutional_layer.h" />
<ClInclude Include="..\..\src\conv_lstm_layer.h" />
<ClInclude Include="..\..\src\cost_layer.h" />
<ClInclude Include="..\..\src\crnn_layer.h" />
<ClInclude Include="..\..\src\crop_layer.h" />
Expand Down
2 changes: 2 additions & 0 deletions build/darknet/yolo_cpp_dll_no_gpu.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
<ClCompile Include="..\..\src\compare.c" />
<ClCompile Include="..\..\src\connected_layer.c" />
<ClCompile Include="..\..\src\convolutional_layer.c" />
<ClCompile Include="..\..\src\conv_lstm_layer.c" />
<ClCompile Include="..\..\src\cost_layer.c" />
<ClCompile Include="..\..\src\cpu_gemm.c" />
<ClCompile Include="..\..\src\crnn_layer.c" />
Expand Down Expand Up @@ -240,6 +241,7 @@
<ClInclude Include="..\..\src\col2im.h" />
<ClInclude Include="..\..\src\connected_layer.h" />
<ClInclude Include="..\..\src\convolutional_layer.h" />
<ClInclude Include="..\..\src\conv_lstm_layer.h" />
<ClInclude Include="..\..\src\cost_layer.h" />
<ClInclude Include="..\..\src\crnn_layer.h" />
<ClInclude Include="..\..\src\crop_layer.h" />
Expand Down
24 changes: 21 additions & 3 deletions include/darknet.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#endif
#endif

#define NFRAMES 3
#define SECRET_NUM -1234

#ifdef GPU
Expand Down Expand Up @@ -136,6 +135,7 @@ typedef enum {
RNN,
GRU,
LSTM,
CONV_LSTM,
CRNN,
BATCHNORM,
NETWORK,
Expand Down Expand Up @@ -208,8 +208,10 @@ struct layer {
int index;
int binary;
int xnor;
int peephole;
int use_bin_output;
int steps;
int state_constrain;
int hidden;
int truth;
float smooth;
Expand Down Expand Up @@ -354,6 +356,7 @@ struct layer {
float *z_cpu;
float *r_cpu;
float *h_cpu;
float *stored_h_cpu;
float * prev_state_cpu;

float *temp_cpu;
Expand All @@ -369,6 +372,7 @@ struct layer {
float *g_cpu;
float *o_cpu;
float *c_cpu;
float *stored_c_cpu;
float *dc_cpu;

float *binary_input;
Expand Down Expand Up @@ -407,10 +411,13 @@ struct layer {
struct layer *uh;
struct layer *uo;
struct layer *wo;
struct layer *vo;
struct layer *uf;
struct layer *wf;
struct layer *vf;
struct layer *ui;
struct layer *wi;
struct layer *vi;
struct layer *ug;
struct layer *wg;

Expand All @@ -424,6 +431,7 @@ struct layer {
float *z_gpu;
float *r_gpu;
float *h_gpu;
float *stored_h_gpu;

float *temp_gpu;
float *temp2_gpu;
Expand All @@ -432,12 +440,16 @@ struct layer {
float *dh_gpu;
float *hh_gpu;
float *prev_cell_gpu;
float *prev_state_gpu;
float *last_prev_state_gpu;
float *last_prev_cell_gpu;
float *cell_gpu;
float *f_gpu;
float *i_gpu;
float *g_gpu;
float *o_gpu;
float *c_gpu;
float *stored_c_gpu;
float *dc_gpu;

// adam
Expand All @@ -451,7 +463,6 @@ struct layer {
float * combine_gpu;
float * combine_delta_gpu;

float * prev_state_gpu;
float * forgot_state_gpu;
float * forgot_delta_gpu;
float * state_gpu;
Expand Down Expand Up @@ -541,6 +552,7 @@ typedef struct network {
float learning_rate_min;
float learning_rate_max;
int batches_per_cycle;
int batches_cycle_mult;
float momentum;
float decay;
float gamma;
Expand All @@ -549,6 +561,7 @@ typedef struct network {
int time_steps;
int step;
int max_batches;
float *seq_scales;
float *scales;
int *steps;
int num_steps;
Expand All @@ -571,6 +584,7 @@ typedef struct network {
float min_ratio;
int center;
int flip; // horizontal flip 50% probability augmentaiont for classifier training (default = 1)
int blur;
float angle;
float aspect;
float exposure;
Expand All @@ -579,6 +593,9 @@ typedef struct network {
int random;
int track;
int augment_speed;
int sequential_subdivisions;
int init_sequential_subdivisions;
int current_subdivision;
int try_fix_nan;

int gpu_index;
Expand Down Expand Up @@ -713,6 +730,7 @@ typedef struct load_args {
int show_imgs;
float jitter;
int flip;
int blur;
float angle;
float aspect;
float saturation;
Expand Down Expand Up @@ -778,7 +796,7 @@ LIB_API float *network_predict_image(network *net, image im);
LIB_API float validate_detector_map(char *datacfg, char *cfgfile, char *weightfile, float thresh_calc_avg_iou, const float iou_thresh, const int map_points, network *existing_net);
LIB_API void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, int ngpus, int clear, int dont_show, int calc_map, int mjpeg_port, int show_imgs);
LIB_API void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filename, float thresh,
float hier_thresh, int dont_show, int ext_output, int save_labels, char *outfile);
float hier_thresh, int dont_show, int ext_output, int save_labels, char *outfile, int letter_box);
LIB_API int network_width(network *net);
LIB_API int network_height(network *net);
LIB_API void optimize_picture(network *net, image orig, int max_layer, float scale, float rate, float thresh, int norm);
Expand Down
Loading

0 comments on commit a3d5cc4

Please sign in to comment.