Running Darknet YOLOV4 from my Laptop only with CPU
If you are working on object detection using the Darknet framework from AlexeyAB you probably need to know how things work around in a host machine having only CPU computing resource. Google Colab is a life save but these days it becomes more restrictive and that is annoying if you don't have a reliable internet connection. If you have GPU that is great. However most of the time Darknet works using CUDA and cuDNN tools which means they need GPU from NIVIDIA. Most of the time those two tools are not compatible with GPU from other manufacturers. My laptop has 8GB GPU from Intel but I cannot run darknet using this GPU type.
Okay let’s come to business as he said!
So did you want to install Darknet YOLOV4 in your laptop which has only CPU. Follow the following simple steps but be careful do not jump over the steps. do it step by step.
First thing first, install the following
Step 1. Install MVS
install Microsoft visual studio from this link https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community.
Step 2. Install CMAKE GUI
Install CMAKE GUI software which is necessary to build the YOLO darknet makefile. from this link https://cmake.org/download/ you can download the one that is compatible for your windows version. do not forget to put the directory path of CMAKE in your system variables.
Step 3. STEP 4) Install CUDA and cuDNN on your system.
you can jump this step if you want. It will not help you if you don’t own Nividia GPU in your laptop. if you have one download those two tools from the link here https://techzizou.com/install-cuda-and-cudnn-on-windows-and-linux/
Step 4. Install OpenCV
OpenCV is a must to have tool when you work with Darknet YOLOV4. if you do not install OpenCV the webcam demo will not even start without it. so go to this link and install the OPenCV version compatible to your windows Version. https://opencv.org/releases/ . do not forget to put the following directory paths to your system variable depending on where you extracted your opencv installation.
C:\opencv\build\include
- C:\opencv\build\x64\vc14\bin
- C:\opencv\build\x64\vc14\lib
- C:\opencv\build\x64\vc15\bin
- C:\opencv\build\x64\vc15\lib
- C:\opencv\build\bin
Now your are almost done if you installed the above tools successfully.
Step 5. Get vcpkg library manager
download the vcpkg library manager from this github link and put the extracted directory to somewhere in your C:\ directory, https://github.com/Microsoft/vcpkg
now go to the extracted cvpkg directory and open windows powershell in that director and run the following command.
bootstrap-vcpkg.bat
After this bat file is finished its execution, run the command below:
vcpkg integrate install
After running these commands successfully, please open your Environment variables and Click “New” in the System Variables section.
Name the new variable, VCPKG_ROOT and make it point the location of the vcpkg folder.
Also, define another system variable named VCPKG_DEFAULT_TRIPLET and set its value to x64-windows.
Open a Powershell window and type the commands below to prepare vcpkg for the darknet installation.
PS \> cd $env:VCPKG_ROOT
PS Code\vcpkg> .\vcpkg install pthreads opencv[ffmpeg]
Final Step. Download Darknet framework from AlexeyAB repository
navigate to this github link of Alexey https://github.com/AlexeyAB/darknet. Thank you so much Alexey for such so so much helpful repository. extract the zip file to somewhere in your C:\ drive. then go to the darknet directory and open windows powershell on this directory where there is a file called build.ps1. lastly run this command from your powershell
.\build.ps1
when you run this command it will ask you the following questions at the beginning.
Enable vcpkg to install darknet dependencies (yes/no): y
Enable CUDA integration (yes/no): n
Enable OpenCV optional dependency (yes/no): y
if you are going to use CPU only and you did not install CUDA and cuDNN in step 2 above say no for Enable CUDA integration (yes/no): n. Say yes for the other two cases.
One thing before running the above command is that you should have to go darknet directory and open Makefile with any editor of yours and change the first few lines as shown below
GPU=0
CUDNN=0
CUDNN_HALF=0
OPENCV=1
AVX=0
OPENMP=0
LIBSO=1
ZED_CAMERA=0
ZED_CAMERA_v2_8=0
now you can run the previous command which is .\build.ps1,
Cheers after the command finish its execution successfully it will generate build _release folder and other files including darknet.exe inside darknet folder. Now you are good to go!!!
in the darknet folder where you have already darknet.exe file open the power shell and run the following command to see some interesting stuff
use the following to see realtime detection using your webcam. The other thing which You should have to do before running the next command is download the yolov4.weights file from AlexeyAB github repo and put it in darknet folder.
darknet.exe detector demo cfg/coco.data cfg/yolov4.cfg yolov4.weights
use the following command to detect objects from a single image
darknet.exe detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -thresh 0.25
HOLA, have fun, that is it!!!!