Skip to main content

How to install and compile YOLO v4 with GPU enable settings in Windows 10?


Another post starts with you beautiful people!
Last year I had shared a post about installing and compiling Darknet YOLOv3 in your Windows machine and also how to detect an object using YOLOv3 with Keras. This year on April' 2020 the fourth generation of YOLO has arrived and since then I was curious to use this as soon as possible. Due to my project (built on YOLOv3 :)) work I could not find a chance to check this latest release. Today I got some relief and successfully able to install and compile YOLOv4 in my machine. In this post I am going to share a single shot way to do the same in your Windows 10 machine. If your machine does not have GPU then you can follow my previous post by just replacing YOLOv3 related files with YOLOv4 files. For GPU having Windows machine, follow my steps to avoid any issue while building the Darknet repository.

My machine has following configurations:
Windows 10 64 bit Intel Core i7
16 GB RAM
NVIDIA GeForce GTX 1660 Ti Version 445.87
CUDA 10.1, cuDNN 7.6
Visual Studio 2017

Before proceeding please make sure that you have installed CUDA, cuDNN as per your GPU drivers and Visual Studio 2017 is installed with C++ distributions. An invalid CUDA/cuDNN version will show unnecessary errors while installing. Once you check and assure all setup is up to date; disable your antivirus settings till the end of this process. For building the Darknet code I am here using Vcpkg instead of Darknet repo's build.ps1 file since with this build.ps1 file I was not able to build the code with GPU settings. Let's start the process-

1. Download Vcpkg from this link. It is a C++ library manager and will be used to install and compile the Darknet code.

2. Open Windows PowerShell with admin rights and go to the root directory of the Vcpkg folder you have downloaded from step 1 and run following two commands one by one:

  1. .\bootstrap-vcpkg.bat
  2. .\vcpkg integrate install


Please note if you are using Windows PowerShell first time, run Set-ExecutionPolicy RemoteSigned and press A when asked and then press Enter.
3. Next, run following command: .\vcpkg install darknet[full]:x64-windows

Above command will download the opencv with cuda, other required libraries and Darknet code. After downloading it will install the all libraries and then it will compile the Darknet code with GPU enable settings automatically. This process will take some time so have patience and wait to complete. Once this process is completed, you will see logs in your PowerShell and some green lines with done status. Make sure all green lines have done status. Once you see done status in all it means Darknet code is successfully compiled with GPU enable settings in your Windows machine. You can check it by going into the darknet directory: <Your_System_dir>\vcpkg-master\installed\x64-windows\tools\darknet

4. Download the yolov4.weights file from this link and put it into the darknet directory
5. Download a sample mp4 video file and put into the same darknet directory
6. In the same PowerShell window go to the path of your darknet directory and run the following command-
.\darknet.exe detector demo cfg/coco.data cfg/yolov4.cfg yolov4.weights Car_Racing.mp4 -dont_show -out_filename carRacing_result.mp4

Once you run the above command, in the starting of the running command you will see following like line-

You can see my CUDA, cuDNN and GPU count are showing in the console which confirms that my GPU is used while using the pre-trained YOLOv4 weights on a sample video file. Once this run is completed you can go to your darknet directory and found a output file carRacing_result.mp4 or your sample video output file. Open that file in a media player and you will see bounding boxes around the detected object names like person, car, truck on them. Inspite of fast moving objects in my video file, YOLOv4 is able to detect objects accurate. You can see my output video from this link . In my machine the average FPS with GPU was 6.7 for this video and with CPU it was 0.4. True power of using a real time object detector like YOLO is with GPU only :)

You can also test the detector with an image by running the same command but replacing video file with image file like below-
.\darknet.exe detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights <IMAGE_FiLE> -dont_show -out_filename

Once you open the saved image (predictions.jpg), the image will show the detection result as below-

You can see pre-trained weights of YOLOv4 is able to detect person, cup, spoon, wine glass, fork, bowl, chair, backpack and knife in the above picture.

That's it for today. With this installation we have a real time object detector. Using it's pre-trained weights only we are able to detect many objects. I am using 2 custom YOLOv3 based models in my project and both are successfully running in production. Soon I will replace both models with the 4th generation YOLO. In my next post I will share you how I prepared my custom objects and trained them with YOLOv4. Till then Go chase your dreams, have an awesome day, make every second count and see you later in my next post.





Comments

  1. Thanks very much for this guide, it worked for me. For people who are going to use this guide: be sure to have the english language package installed in Visual Studio, otherwise it does not completely install all libraries and compilation won't be complete when executing .\vcpkg install darknet[full]:x64-windows.

    ReplyDelete
  2. When I use the picture detection command, it works. But when it comes to the video command I get the following:
    GPU isn't used
    Used AVX
    Used FMA & AVX2
    OpenCV isn't used - data augmentation will be slow
    Demo needs OpenCV for webcam images.

    Its annoying, I hope someone can help me fix it.

    ReplyDelete
    Replies
    1. When you see GPU isn't used while running darknet command, it means your OpenCV is not compiled with GPU settings. Have you used this command: .\vcpkg install darknet[full]:x64-windows? If yes, there must be some error in red color otherwise you must check also your CUDA related settings.

      Delete
  3. I am really happy with your blog because your article is very unique and powerful for new.
    Data Science
    Selenium
    ETL Testing
    AWS
    Python Classes in Pune
    ETL Testing

    ReplyDelete
  4. I got error using this command
    .\vcpkg install darknet[full]:x64-windows

    ERROR:
    Error: Building package cuda:x64-windows failed with: BUILD_FAILED

    Please help. Thanks in advance

    ReplyDelete
    Replies
    1. It seems you have not installed Cuda properly. Please recheck the cuda and cudnn installation in your system.

      Delete
  5. hey! can I use jupyter notenook instead of google colab here??

    ReplyDelete
    Replies
    1. In this post I have not used colab or jupyter notebook. This post is only about building and compiling the Darknet with GPU settings in Windows 10 system.

      Delete
  6. I have read all the comments and suggestions posted by the visitors for this article are very fine,We will wait for your next article so only.Thanks! data warehouse,

    ReplyDelete
  7. When I run the command all I get is:
    "

    CUDA-version: 10020 (11020), cuDNN: 7.6.5, CUDNN_HALF=1, GPU count: 1
    CUDNN_HALF=1
    OpenCV version: 4.1.0
    Demo
    0 : compute_capability = 860, cudnn_half = 1, GPU: GeForce RTX 3090
    net.optimized_memory = 0
    mini_batch = 1, batch = 8, time_steps = 1, train = 0
    layer filters size/strd(dil) input output
    0"

    Then it just hangs there indefinitely. any ideas?

    ReplyDelete
    Replies
    1. You are using RTX 3090 and till March few people have faced the same issue. Please retry with a fresh start on new folders and I hope you will not face the same issue.

      Delete
  8. its stuck.....and in task manager it dosnt show and cpu usage ar anything by power shell

    ReplyDelete
  9. stuck in building x64 windows-dbg

    ReplyDelete
    Replies
    1. While building and compiling the Darknet with GPU in my system it took 3 hours. If you are facing more time then I suggest please retry on a new folder as a fresh start. Make sure you have opened the cmd/powershell with admin rights and you have internet on during this process.

      Delete
  10. Great Work but i see the same error, i try it twice:


    -- Downloading https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v4_pre/yolov4-tiny.weights -> darknet-cache/yolov4-tiny.weights...
    CMake Error at scripts/cmake/vcpkg_download_distfile.cmake:105 (message):


    File does not have expected hash:

    File path: [ D:/vcpkg-master3/vcpkg-master/downloads/temp/darknet-cache/yolov4-tiny.weights ]
    Expected hash: [ 804ca2ab8e3699d31c95bf773d22f901f186703487c7945f30dc2dbb808094793362cb6f5da5cd0b4b83f820c8565a3cba22fafa069ee6ca2a925677137d95f4 ]
    Actual hash: [ 7d4d9fe150f9fe3ea7d2310f1445fe983b31fbf06d301c70ecfe00e8559e6f1bf940198c2dd55db772238f23ea0092fb6553558e5414f3ee173b8b28e53c5b54 ]

    The file may have been corrupted in transit. This can be caused by
    proxies. If you use a proxy, please set the HTTPS_PROXY and HTTP_PROXY
    environment variables to
    "https://user:password@your-proxy-ip-address:port/".



    Call Stack (most recent call first):
    scripts/cmake/vcpkg_download_distfile.cmake:195 (test_hash)
    ports/darknet/portfile.cmake:28 (vcpkg_download_distfile)
    scripts/ports.cmake:142 (include)


    Error: Building package darknet:x64-windows failed with: BUILD_FAILED

    ReplyDelete
    Replies
    1. To solve this go to ports/darknet/portfile.cmake and change the hash of the line that threw the error. You might have to this multiple times

      Delete
    2. To solve this issue, please follow this link: https://github.com/microsoft/vcpkg/issues/15256

      Delete
  11. Nice Article.Thank you for sharing useful information.

    For Online MBA check below.

    Innomatics Research Labs is collaborated with JAIN (Deemed-to-be University) and offering the Online MBA in Business Intelligence,Business Analytics Program. This two-year program from JAIN (deemed-to-be) University offers foundation courses, core courses, Specialization courses, and a comprehensive master thesis intermediary, apart from an option to pursue a cross-functional and open elective.
    Online MBA in Business Analytics
    Online MBA in Business Intelligence

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. Excellent post with valuable info. Share more updates
    Service Cloud
    Salesforce



    ReplyDelete
  14. Thanks for sharing this amazing post this is the content i really looking for, it's very helpful i hope you will continue your blogging anyway if anyone looking for Advance excel training institute in delhi contact us +91-9311002620 visit-https://www.htsindia.com/Courses/business-analytics/adv-excel-training-course

    ReplyDelete
  15. Great post I would like to thank you for the efforts you have made in writing this interesting and knowledgeable article.
    data scientist training in malaysia

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  17. it’s very helpful useful thanks for your valuable information follow us
    Best Data Science Online Training in Hyderabad

    ReplyDelete
  18. Looking for top-notch MCSE 2012 Training in Delhi? Look no further than APTRON, your premier destination for comprehensive and industry-oriented IT training. With a track record of excellence and a commitment to delivering exceptional results, APTRON Delhi stands out as the go-to institute for aspiring IT professionals.

    ReplyDelete
  19. APTRON Solution takes pride in its hands-on training approach, making us the premier choice for Industrial Automation Training in Noida. Our dedicated faculty comprises experienced professionals who bring real-world insights to the classroom. We combine theoretical knowledge with practical application, ensuring that you gain the skills required for success in the industrial automation field.

    ReplyDelete
  20. Global Degrees, established in 2005, has become a leading provider of overseas education advisory and consulting services, renowned for its performance-driven approach. Specializing in student recruitment for foreign universities, fostering university partnerships, and facilitating business growth in the education sector, the company operates primarily in South India through 8 company-owned branches, prioritizing excellence and consistency. With a strong focus on marketing strategies and industry relations, Global Degrees offers unparalleled support to universities worldwide, aiding in student enrollment and providing access to quality educational opportunities across 8 countries. They eagerly anticipate serving as your trusted consulting partner in the realm of overseas education.

    ReplyDelete

Post a Comment

Popular posts from this blog

How to use opencv-python with Darknet's YOLOv4?

Another post starts with you beautiful people 😊 Thank you all for messaging me your doubts about Darknet's YOLOv4. I am very happy to see in a very short amount of time my lovely aspiring data scientists have learned a state of the art object detection and recognition technique. If you are new to my blog and to computer vision then please check my following blog posts one by one- Setup Darknet's YOLOv4 Train custom dataset with YOLOv4 Create production-ready API of YOLOv4 model Create a web app for your YOLOv4 model Since now we have learned to use YOLOv4 built on Darknet's framework. In this post, I am going to share with you how can you use your trained YOLOv4 model with another awesome computer vision and machine learning software library-  OpenCV  and of course with Python 🐍. Yes, the Python wrapper of OpenCV library has just released it's latest version with support of YOLOv4 which you can install in your system using below command- pip install opencv-python --up

How to convert your YOLOv4 weights to TensorFlow 2.2.0?

Another post starts with you beautiful people! Thank you all for your overwhelming response in my last two posts about the YOLOv4. It is quite clear that my beloved aspiring data scientists are very much curious to learn state of the art computer vision technique but they were not able to achieve that due to the lack of proper guidance. Now they have learnt exact steps to use a state of the art object detection and recognition technique from my last two posts. If you are new to my blog and want to use YOLOv4 in your project then please follow below two links- How to install and compile Darknet code with GPU? How to train your custom data with YOLOv4? In my  last post we have trained our custom dataset to identify eight types of Indian classical dance forms. After the model training we have got the YOLOv4 specific weights file as 'yolo-obj_final.weights'. This YOLOv4 specific weight file cannot be used directly to either with OpenCV or with TensorFlow currently becau