lhk / darknet_wrapper

A small wrapper around darknet
12 stars 5 forks source link

What are the modifications required to build yolo for CPU without CUDA #6

Closed abhigoku10 closed 6 years ago

abhigoku10 commented 6 years ago

@lhk HI thanks for an wonderful wrapper , i just wanted to the know what are the modifications or the changes to be in the makefile to build it for CPU and without CUDA. This would be of great help

lhk commented 6 years ago

Hi abhigoku10, did you also post on the darknet group ? In any case, this is what you need to do to make it work on CPU:

  1. At the top of the makefile, set CUDA=0 to switch off compilation of darknet with cuda.

Now you should be able to compile darknet with the Makefile.

  1. remove all references to CUDA from the CMakeLists.txt.
  2. remove the setup_cuda() calls from the C++ code.

After that you should be able to compile the C++ part of the wrapper.

I think this should be enough to make it work. Unfortunately, I can't test it right now.

I'm very happy that my wrapper is helping you. Best of luck with the cpu compilation, keep me posted.

abhigoku10 commented 6 years ago

@lhk thanks for the quick response . I am trying to follow the steps which you had suggested . Having doubt inthe makefile and cmakelist.txt

  1. In the make file should replace CC=gcc with CC=g++
  2. is it mandatory to use opencv320 since i have currently installed prior opencv310
  3. in the cmakelist for this line "target_link_libraries(main ${OpenCV_LIBS} cuda cudart cublas curand darknet)" should i remove all the cuda stuffs and just have "target_link_libraries(main ${OpenCV_LIBS} darknet)" or "target_link_libraries(main ${OpenCV_LIBS} )" one---because this line is giving me error when i am trying to build it ..

Earlier i have build it gpu system and it was working very good . I am testing with changes suggested just reconfirming this is the changes you meant

Thanking you a ton lot

lhk commented 6 years ago

Hm, I'm sorry, it's probably not that easy after all. I just reread our makefiles and scripts. Here's more tips on how to get it to work:

The Makefile is for compiling darknet itself. That is C code and uses the gcc compiler, you don't have to switch it to g++.

You need to set GPU=0 at the top of the Makefile to switch off Cuda compilation. That is here https://github.com/lhk/darknet_wrapper/blob/ede308df0e135da6182b6ccc2040e94899ac3892/darknet/Makefile#L1

And I've reread the Makefile code, we are adding some cuda dependencies in the opencv section. You'll probably have to remove everything that mentions cude, here too: https://github.com/lhk/darknet_wrapper/blob/ede308df0e135da6182b6ccc2040e94899ac3892/darknet/Makefile#L37

In the CMake file, you should remove everything that depends on CUDA. The package, the directories, the libraries.

Unfortunately we also build opencv with CUDA support. You wanted to know if opencv320 is necessary, I honestly don't know. I think it should be fine. We only used opencv320 because other components in the system depended on it. But for this code, I don't think that the difference is critical. That being said you should keep it in mind as a potential source of errors. If you have a working opencv310 installation, you should try to include that in the CMakeLists.txt To do that, you need to set this directory: https://github.com/lhk/darknet_wrapper/blob/ede308df0e135da6182b6ccc2040e94899ac3892/CMakeLists.txt#L6

Building something with opencv can be quite tricky. That opencv installation bash script is meant to do the job for you. If you can't get your opencv310 to work, I would recomment using the bashscript to install 320. You'll have to edit this, too. Since we are compiling opencv with CUDA support. Switch off CUDA support in this line: https://github.com/lhk/darknet_wrapper/blob/ede308df0e135da6182b6ccc2040e94899ac3892/install_opencv320.bash#L30

abhigoku10 commented 6 years ago

@lhk i have played around this steps and i am pretty much successful till the end one i . e in the cmakelist for this line "target_link_libraries(main ${OpenCV_LIBS} cuda cudart cublas curand darknet)" should i remove all the cuda stuffs and just have "target_link_libraries(main ${OpenCV_LIBS} darknet)" or "target_link_libraries(main ${OpenCV_LIBS} )"

can u pls look into the cmakelist.txt and let me knw if i need to make the other changes

Thanking you

lhk commented 6 years ago

You will need to keep darknet.

abhigoku10 commented 6 years ago

@lhk thanks for the tips i was successfully able to build it on the CPU

lhk commented 6 years ago

Nice, thanks for updating me on the successful build.

Could you make a list of the changes that were necessary. I'm sure that would help other people, too

abhigoku10 commented 6 years ago

@lhk ya sure i shall make a doccument which will be able to build it on CPU (over the weekend)

egbertn commented 2 years ago

Hm, I'm sorry, it's probably not that easy after all. I just reread our makefiles and scripts. Here's more tips on how to get it to work:

The Makefile is for compiling darknet itself. That is C code and uses the gcc compiler, you don't have to switch it to g++.

You need to set GPU=0 at the top of the Makefile to switch off Cuda compilation. That is here

Unfortunately, if my system has GPU and CUDA support, and I wilfully do want to use CPU only for compilation, the cmake -D GPU=0 and -D CUDA=0 .. still detects cuda and enables it no matter if I don't want it.

So, the solution is to edit CMakeCache.txt in your build directory after running cmake .. and set these lines as follows //Enable CUDA support ENABLE_CUDA:BOOL=OFF

//Enable CUDNN ENABLE_CUDNN:BOOL=OFF

//Enable CUDNN Half precision ENABLE_CUDNN_HALF:BOOL=FALSE

After that, make will continue to build if you use the known make -j(NPROC) setting