Smorodov / Multitarget-tracker

Multiple Object Tracker, Based on Hungarian algorithm + Kalman filter.
Apache License 2.0
2.2k stars 652 forks source link

Yolo detector #116

Open gentle-li opened 5 years ago

gentle-li commented 5 years ago

I encountered an error when I used the Yolo detector. OpenCV(4.0.0) Error: Parsing error (Failed to parse NetParameter file: ../data/tiny-yolo.cfg) in cv::dnn::dnn4_v20180917::readNetFromDarknet, file E:\opencv-4.0.0\modules\dnn\src\darknet\darknet_importer.cpp, line 207

I use opencv4.0 How can I solve it?

Nuzhny007 commented 5 years ago

Hi! I'm working on Linux systems and set default path to the models in this two lines: https://github.com/Smorodov/Multitarget-tracker/blob/master/example/VideoExample.h#L480 But on Windows it not works. You can:

  1. Set a full path to the models in folder data: https://github.com/Smorodov/Multitarget-tracker/tree/master/data
  2. Copy this folder to the build directory.

I will fix this bug in the near time.

gentle-li commented 5 years ago

嗨! 我正在研究Linux系统并在这两行中设置模型的默认路径:https//github.com/Smorodov/Multitarget-tracker/blob/master/example/VideoExample.h#L480 但在Windows上它不起作用。您可以:

  1. 设置文件夹数据中模型的完整路径:https//github.com/Smorodov/Multitarget-tracker/tree/master/data
  2. 将此文件夹复制到生成目录。

我会在近期修复这个bug。

It works fine,thanks^_^ But the speed is very slow, what is the reason?

Frame 248: tracks = 5, time = 744 Frame 249: tracks = 5, time = 746 Frame 250: tracks = 4, time = 748 Frame 251: tracks = 4, time = 807 Frame 252: tracks = 4, time = 802 Frame 253: tracks = 4, time = 724 Frame 254: tracks = 4, time = 693 Frame 255: tracks = 4, time = 781 Frame 256: tracks = 4, time = 865 Frame 257: tracks = 4, time = 750 Frame 258: tracks = 4, time = 812 Frame 259: tracks = 4, time = 829 Frame 260: tracks = 4, time = 796 Frame 261: tracks = 4, time = 1071 Frame 262: tracks = 4, time = 1186 Frame 263: tracks = 4, time = 833 Frame 264: tracks = 4, time = 802 Frame 265: tracks = 4, time = 829 Frame 266: tracks = 3, time = 736 Frame 267: tracks = 2, time = 666 Frame 268: tracks = 2, time = 709 Frame 269: tracks = 2, time = 667 Frame 270: tracks = 2, time = 732 Frame 271: tracks = 3, time = 723 Frame 272: tracks = 3, time = 771 Frame 273: tracks = 3, time = 685

I tried TrackKCF to TrackNone, It has no effect

Nuzhny007 commented 5 years ago

All DNNs work on opencv_dnn module. You can set two options:

  1. Target: https://github.com/Smorodov/Multitarget-tracker/blob/master/src/Detector/YoloDetector.cpp#L53
  2. Backend: https://github.com/Smorodov/Multitarget-tracker/blob/master/src/Detector/YoloDetector.cpp#L71

The fastest DNN detector on Intel CPU or iGPU uses cv::dnn::DNN_BACKEND_INFERENCE_ENGINE. If you want to use it than you need download Intel OpenVINO toolkint ( https://software.intel.com/en-us/openvino-toolkit ). OpenCV now can't use Nvidia GPU with CUDA or cuDNN library. For using original YOLO detector on Nvidia GPU it need to compile darknet: https://github.com/pjreddie/darknet (or here: https://github.com/AlexeyAB/darknet )

gentle-li commented 5 years ago

All DNNs work on opencv_dnn module. You can set two options:

  1. Target: https://github.com/Smorodov/Multitarget-tracker/blob/master/src/Detector/YoloDetector.cpp#L53
  2. Backend: https://github.com/Smorodov/Multitarget-tracker/blob/master/src/Detector/YoloDetector.cpp#L71

The fastest DNN detector on Intel CPU or iGPU uses cv::dnn::DNN_BACKEND_INFERENCE_ENGINE. If you want to use it than you need download Intel OpenVINO toolkint ( https://software.intel.com/en-us/openvino-toolkit ). OpenCV now can't use Nvidia GPU with CUDA or cuDNN library. For using original YOLO detector on Nvidia GPU it need to compile darknet: https://github.com/pjreddie/darknet (or here: https://github.com/AlexeyAB/darknet )

I always thought that you added the weight and cfg files and it was already detected with yolo. It seems that my thoughts are wrong. I have generated the yolo dll file and can perform video detection, but I don't know how to add your code. What should I do?

Nuzhny007 commented 5 years ago

YOLO - it is DNN architecture from Joseph Redmon ( https://pjreddie.com/darknet/ ). And Joseph Redmon is author of the darknet library (written on C with CUDA). And original YOLO works on darknet.

opencv_dnn is an inference library (not train!) for neural networks. It can work with TensorFlow models, with ONNX models, with darknet models - YOLO etc. But opencv_dnn don't use darknet library for inference. opencv_dnn uses code written by intel's engineers. If you want to use fastest inference on GPU than it need to compile yolo dll and make custom detector based on this code:

  1. From darknet: https://github.com/AlexeyAB/darknet/blob/master/src/yolo_console_dll.cpp
  2. From Multitarget-tracker: https://github.com/Smorodov/Multitarget-tracker/blob/master/src/Detector/YoloDetector.h

On Christmas holidays, I can try to do an automatic build and use the official darknet as a detector in Multitarget-tracker.

gentle-li commented 5 years ago

YOLO - it is DNN architecture from Joseph Redmon ( https://pjreddie.com/darknet/ ). And Joseph Redmon is author of the darknet library (written on C with CUDA). And original YOLO works on darknet.

opencv_dnn is an inference library (not train!) for neural networks. It can work with TensorFlow models, with ONNX models, with darknet models - YOLO etc. But opencv_dnn don't use darknet library for inference. opencv_dnn uses code written by intel's engineers. If you want to use fastest inference on GPU than it need to compile yolo dll and make custom detector based on this code:

  1. From darknet: https://github.com/AlexeyAB/darknet/blob/master/src/yolo_console_dll.cpp
  2. From Multitarget-tracker: https://github.com/Smorodov/Multitarget-tracker/blob/master/src/Detector/YoloDetector.h

On Christmas holidays, I can try to do an automatic build and use the official darknet as a detector in Multitarget-tracker.

Thanks,I am very looking forward to your code.^_^

iraadit commented 5 years ago

I would be really interested too by the inclusion of Darknet YOLO in Multitarget-tracker

gentle-li commented 5 years ago

Hi, would you like to try YOLOv3 as the detector code? I tried to merge the code but it didn't work.

Nuzhny007 commented 5 years ago

Hi! Waiting PL merge: https://github.com/Smorodov/Multitarget-tracker/pull/117 It was not simple but on my laptop Yolo v3 + cudnn based darknet inference works with 2.5x speedup

gentle-li commented 5 years ago

Hi! Waiting PL merge: #117 It was not simple but on my laptop Yolo v3 + cudnn based darknet inference works with 2.5x speedup

OK,thanks, but the version has not been updated yet.Is this my problem?

Nuzhny007 commented 5 years ago

No, waiting for Smorodov. But temporary you can to get version from my fork: https://github.com/Nuzhny007/Multitarget-tracker

gentle-li commented 5 years ago

No, waiting for Smorodov. But temporary you can to get version from my fork: https://github.com/Nuzhny007/Multitarget-tracker

When I am in CMake, it prompts ‘Could NOT find CUDNN’, my cuda8.0, cuDNN7.1, do I need to switch to the same version as you?

Nuzhny007 commented 5 years ago

No, you can set all manual. cmake_cudnn

gentle-li commented 5 years ago

I have encountered this error image But,when the options USE_OCV_BGFG, USE_OCV_KCF and USE_OCV_UKF are not checked image my opencv 3.31, have contrib.

gentle-li commented 5 years ago

The first picture error is unable to open mtracking.lib The second picture error is unable to open yolo_lib.lib

Nuzhny007 commented 5 years ago
  1. About TrackerMOSSE, change please condition CV_VERSION_MINOR strictly greater than 3: #if (((CV_VERSION_MAJOR == 3) && (CV_VERSION_MINOR > 3)) || (CV_VERSION_MAJOR > 3))

  2. About shfl_xor. May be you work on old GPU. Add, plz, a new line in CMakeLists.txt (after that https://github.com/Nuzhny007/Multitarget-tracker/blob/master/src/Detector/darknet/CMakeLists.txt#L34 ): set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -gencode arch=compute_20,code=sm_20")

gentle-li commented 5 years ago

image image This error still occurs.

gentle-li commented 5 years ago

my gpu is TITAN X

Nuzhny007 commented 5 years ago

Hm, TITAN X has compute capability 5.2. It's not cause of error. But Titan X ( GP102 ) has a performance problems with fp16 presicion than used in YOLO ( https://devblogs.nvidia.com/mixed-precision-programming-cuda-8/ ):

The Pascal GPU architecture implements general-purpose, IEEE 754 FP16 arithmetic. High performance FP16 is supported at full speed on Tesla P100 (GP100), and at lower throughput (similar to double precision) on other Pascal GPUs (GP102, GP104, and GP106), as the following table shows.

But in your case it's also not problem.

Try, plz, to set verbose compilation for CUDA ( https://github.com/Nuzhny007/Multitarget-tracker/blob/master/src/Detector/darknet/CMakeLists.txt#L17 ): set(CUDA_NVCC_FLAGS -Xcompiler -v)

And share compiler output with includes paths.

gentle-li commented 5 years ago

I don't quite understand what you mean, can you talk about it in detail,don't understand the principle of cuda and cmake. my cuda is 8.0 set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -gencode arch=compute_20,code=sm_20") Is this sentence correct?

Nuzhny007 commented 5 years ago

Yes, it is correct but your GPU need 5.1 - it is always in CMakeLists. I want to see NVCC compiler options. in CMakeLists this line is commented: https://github.com/Nuzhny007/Multitarget-tracker/blob/master/src/Detector/darknet/CMakeLists.txt#L17 Do you can write instead: set(CUDA_NVCC_FLAGS -Xcompiler -v)

Nuzhny007 commented 5 years ago

And compile. In compiler output (output windows in the MS Visual studio) will be a command line of the NVCC.

gentle-li commented 5 years ago

When I compile 1>E:/Multitarget-tracker-master/src/Detector/darknet/convolutional_kernels.cu(97): error : identifier "__shfl_xor" is undefined 1> 1>E:/Multitarget-tracker-master/src/Detector/darknet/convolutional_kernels.cu(196): warning : variable "status" was declared but never referenced 1> 1>E:/Multitarget-tracker-master/src/Detector/darknet/convolutional_kernels.cu(197): warning : variable "input_size" was declared but never referenced 1> 1>E:/Multitarget-tracker-master/src/Detector/darknet/convolutional_kernels.cu(202): warning : variable "a" was declared but never referenced 1> 1>E:/Multitarget-tracker-master/src/Detector/darknet/convolutional_kernels.cu(207): warning : variable "t_bit_input_size" was declared but never referenced 1> 1>E:/Multitarget-tracker-master/src/Detector/darknet/convolutional_kernels.cu(292): warning : variable "one" was declared but never referenced 1> 1> 1 error detected in the compilation of "C:/Users/ADMINI~1/AppData/Local/Temp/tmpxft_0000311c_00000000-11_convolutional_kernels.cpp1.ii". 1>CUSTOMBUILD : nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning). 1> convolutional_kernels.cu 1> CMake Error at yolo_lib_generated_convolutional_kernels.cu.obj.Release.cmake:279 (message): 1> Error generating file 1> E:/Multitarget-tracker-master/build/src/Detector/darknet/CMakeFiles/yolo_lib.dir//Release/yolo_lib_generated_convolutional_kernels.cu.obj

Nuzhny007 commented 5 years ago

I think that in your case with CUDA 8 missing any includes. But I can't install CUDA 8. Do you can install CUDA 10?

gentle-li commented 5 years ago

ok, I am trying to install cuda 10

gentle-li commented 5 years ago

some regret, still can't open “....\build\Debug\yolo_lib.lib” cuda10, cudnn7.3.0 In addition, I would like to ask you a question, I have compiled AlexeyAB's yolo, can detect a video, similar to yolo_console_dll.cpp, but I don't know how to add the tracker, if I want to merge the code, I need to pay attention to which Interface, can you give me some advice? The code you wrote is very well packaged. I may not understand it in some places, which leads to the unsuccessful merge code.

gentle-li commented 5 years ago

I combined the code according to my detector and your tracker. The effect is very good. Thank you very much for answering my questions patiently. You are the role model for me to learn from. ^_^

Nuzhny007 commented 5 years ago

Good thing you did! But it is a pity that YOLO did not work from this repository. It seems that I did something wrong in CMakeLists.txt. Good luck!

ted8201 commented 5 years ago

Thanks for this awesome rep. on my ubuntu16 + cuda8.0+ cudnn7, gpu 1080ti, the problem

error : identifier "__shfl_xor" is undefined

was caused by https://github.com/Smorodov/Multitarget-tracker/blob/master/src/Detector/darknet/CMakeLists.txt#L30 . nvcc use sm_20/compute20 by default. Cmake does not work to change this. see Using __shfl_xor in my CUDA kernel but getting error when compiling and 源码编译mxnet,使用cudnn选项时发生错误 for more info. I use a cumbersome way by changing this line https://github.com/Nuzhny007/Multitarget-tracker/blob/8f58f494f5d174236983d1c2e568e571fcb939d1/src/Detector/darknet/CMakeLists.txt#L17 to

set(CUDA_NVCC_FLAGS -std=c++11 -g -Xcompiler -fexceptions -Xcompiler -fP IC -gencode arch=compute_61,code=sm_61;)

arch=compute_61,code=sm_61; is for 1080ti

Nuzhny007 commented 5 years ago

Hi! Thanks for your changes. And recently AlexeyAB created CMakeLists for his darknet fork: https://github.com/AlexeyAB/darknet/blob/master/CMakeLists.txt I will update darknet code and this CMakeLists.txt I hope than all compiler errors will disappear.