Darknet on Macos with GPU and OpenCV by

Darknet on Macos with GPU and OpenCV

Last update: 11 months ago Tag : darknet, ml, dl, macos, hackintosh

Darknet here is not the dark web which requires you to open it with onion browser. It is an open source neural network framework written in C and CUDA. It is fast, easy to install, and supports CPU and GPU computation.

Well, not so easy to install actually, because you need to install opencv and cuda/cudnn first, which is very frustrating, and the google-fu says so, alot of problems when you compile it with opencv.

So, also from Google-Fu, I finally managed to compile the darknet with cuda and opencv supports, and here is the steps:

  1. Make sure to install the cuda and cudnn with CLT 8.3.2,and python3 using brew
  2. Compile and install opencv version 3.4.0, using:
    • git clone
    • git clone
  3. Fetch the version 3.4.0 from above both opencv:
    • cd opencv && git checkout 3.4.0
    • cd ../opencv_contrib && git checkout 3.4.0 && cd ../opencv
  4. Generate config and then compile:
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \              
-DPYTHON_LIBRARY=/usr/local/lib/libpython3.6.dylib \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D BUILD_EXAMPLES=ON -DBUILD_opencv_python3=ON ..
make -j8
make install
  1. Get darknet: git clone
  2. Edit Makefile and change GPU=1, CUDNN=1 and OPENCV=1
  3. Run make -j8 and wait til finish, maybe 1 or 2 hours later.
  4. Once finished, you can see an executable file ./darknet so you can continue to copy/paste the sample command to try.

Here is the sample: detection

It is also able to detect some objects in realtime using the webcam, although the framerate is just around 7-10 fps, it's still awesome!

Share this post: