Darknet/YOLO object detection framework
848
stars
3,072
commits
C++
primary language
Aug 30, 2026
updated

Darknet is an open source neural network framework written in C, C++, and CUDA.
YOLO (You Only Look Once) is a state-of-the-art, real-time, object detection system, which runs in the Darknet framework.
The Darknet/YOLO framework continues to be both faster and more accurate than other frameworks and versions of YOLO.
This framework is both completely free and open source. You can incorporate Darknet/YOLO into existing projects and products -- including commercial ones -- without a license or paying a fee.
Darknet V3 ("Jazz") released in October 2024 can accurately run the LEGO dataset videos at up to 1000 FPS when using a NVIDIA RTX 3090 GPU, meaning each video frame is read, resized, and processed by Darknet/YOLO in 1 millisecond or less. Additional performance improvements have been implemented in Darknet V4 and the upcoming Darknet V5, without compromising the quality of detections.
Please join the Darknet/YOLO Discord server if you need help or you want to discuss Darknet/YOLO and related tools: https://discord.gg/MQw32W9Cqr
The CPU version of Darknet/YOLO can run on simple devices such as Raspberry Pi, cloud & colab servers, desktops, laptops, and high-end training rigs. The GPU version of Darknet/YOLO requires either a CUDA-capable GPU from NVIDIA, or a ROCm-capable GPU from AMD.
Darknet/YOLO is known to work on Linux, Windows, and Mac. See the building instructions below.
version command. From 2023 until late 2024, it returned version 2.x "OAK".
v2 branch.version command now returns 3.x "JAZZ".
v2 branch if you need to run one of these commands. Let us know so we can investigate adding back any missing commands.src-examples: https://www.ccoderun.ca/darknet/files.htmlversion command now returns 4.x "SLATE".
printf() and std::cout calls have all been replaced so Darknet/YOLO logging messages can easily be redirected.version command now returns 5.x "Moonlit".
People are generally expected to train their own network. But pre-trained weights are also popular. These are weights which someone else has trained and made available for free on the internet. This is sometimes convenient when first installing Darknet/YOLO, since the software can be quickly tested without having to train a new neural network.
person and head)person, backpack, chair, clock, ...)The People-R-People pre-trained weights are used to find people. This dataset only has 2 classes: person and head.

You can download these pre-trained weights directly from C Code Run's web site.
Several popular versions of YOLO were pre-trained for convenience on the MSCOCO dataset. This dataset has 80 classes, which can be seen in the text file cfg/coco.names.
The MSCOCO pre-trained weights can be downloaded from several different locations, and are also available for download from this repo:
The MSCOCO pre-trained weights are provided for demo-purpose only. The corresponding .cfg and .names files for MSCOCO are in the cfg directory. Example commands:
wget --no-clobber https://github.com/hank-ai/darknet/releases/download/v2.0/yolov4-tiny.weights
darknet_02_display_annotated_images coco.names yolov4-tiny.cfg yolov4-tiny.weights image1.jpg
darknet_03_display_videos coco.names yolov4-tiny.cfg yolov4-tiny.weights video1.avi
DarkHelp coco.names yolov4-tiny.cfg yolov4-tiny.weights image1.jpg
DarkHelp coco.names yolov4-tiny.cfg yolov4-tiny.weights video1.avi
The various build methods available in the past (pre-2023) have been merged together into a single unified solution. Darknet requires C++17 or newer, OpenCV, and uses CMake to generate the necessary project files.
[!NOTE] You do not need to know CMake, C++, C, Python, or any other programmaing language to build, install, nor run Darknet/YOLO. Some advanced topics -- such as using the Darknet/YOLO API -- does require programming experience.
Select one of the following build types:
[!CAUTION] Beware if you are following old tutorials with more complicated build steps, or build steps that don't seem to match what is in this readme. The new build steps started in August 2023.
Software developers are encouraged to visit https://www.ccoderun.ca/darknet/ to get information on the internals of the Darknet/YOLO object detection framework.
[!IMPORTANT] An important change was made in Darknet v5.1 to one of the prediction structures. If you have software that includes
darknet.hordarknet.hppyou'll want to recompile your application to prevent segfaults.
The Google Colab instructions are the same as the Linux instructions. Several Jupyter notebooks are available showing how to do certain tasks, such as training a new network.
See the notebooks in the colab subdirectory for details, and/or follow the Linux instructions below.
If you have a modern version of Windows and a decent computer, then the use of WSL (Windows Subsystem for Linux) and Ubuntu 24.04 LTS is highly recommended.
WSL is a feature in Windows which allows people to run Linux-based applications from within their Windows desktop. This is similar to a virtual machine with host/guest extensions. Linux apps running in WSL have access to the GPU if you install the Linux NVIDIA driver for WSL, and you can train a new network with Darknet/YOLO running within WSL.
[!TIP] Once WSL is installed, please remember to run
sudo apt-get updateat least once from your Ubuntu command prompt to get the updated list of packages, and then follow the usual Linux instructions.
If you don't want to use Darknet/YOLO from within WSL, then skip ahead to the Windows instructions.
[!IMPORTANT] Darknet can run without access to a GPU, but if you want to train a custom network or you need higher performance, then a modern NVIDIA GPU or AMD GPU is strongly recommended.
- Depending on which GPU you have, please read the NVIDIA GPU Readme or the AMD GPU Readme.
[!TIP] If you are building a CPU-only version of Darknet, you may want to install OpenBLAS to increase performance. These libraries are only used on CPU-only builds:
sudo apt-get install libopenblas64-0 libopenblas64-0-openmp libopenblas64-openmp-dev
The following instructions assume (but do not require!) a system running Ubuntu 22.04. Adapt as necessary if you're using a different Linux distribution.
sudo apt-get install build-essential git libopencv-dev cmake libprotobuf-dev protobuf-compiler
mkdir ~/src
cd ~/src
git clone https://codeberg.org/CCodeRun/darknet.git
cd darknet
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j4 package
sudo dpkg -i darknet-<INSERT-VERSION-YOU-BUILT-HERE>.deb
[!WARNING] If you are using an older version of CMake then you'll need to upgrade CMake before you can run the
cmakecommand above. Upgrading CMake on Ubuntu can be done with the following commands:
sudo apt-get purge cmake
sudo snap install cmake --classic
[!WARNING] If using
bashas your command shell you'll want to re-start your shell at this point. If usingfish, it should immediately pick up the new path.
[!TIP] Advanced users:
See the readme for PGO (Profile-Guided Optimization) if you want to run an optimized Darknet/YOLO.
[!TIP] Advanced users:
If you want to build a RPM installation file instead of a DEB file, see the relevant lines inCM_package.cmake. Prior to runningmake -j4 packageyou'll need to edit these two lines:
SET (CPACK_GENERATOR "DEB")
# SET (CPACK_GENERATOR "RPM")
For distros such as Centos and OpenSUSE, you'll need to switch those two lines in
CM_package.cmaketo be:
# SET (CPACK_GENERATOR "DEB")
SET (CPACK_GENERATOR "RPM")
To install the installation package once it has finished building, use the usual package manager for your distribution. For example, on Debian-based systems such as Ubuntu:
sudo dpkg -i darknet-2.0.1-Linux.deb
Installing the .deb (or .rpm) package will install the following files:
/usr/bin/darknet*... are the usual Darknet executables. Run darknet version from the CLI to confirm it is installed correctly./usr/include/darknet*... are the Darknet API header files for C, C++, and Python developers./usr/lib/libdarknet.so is the library to link against for C, C++, and Python developers./opt/darknet/cfg/... is where all the .cfg templates are stored.You are now done! Darknet has been built and installed into /usr/bin/. Run this to test: darknet version.
[!CAUTION] If you don't have
/usr/bin/darknetthen this means you did not install it, you only built it! Make sure you install the.debor.rpmfile as described above.
[!IMPORTANT] Before building Darknet/YOLO for Windows please see the note about using WSL. (Spoiler ... Darknet/YOLO works great in WSL!)
Open a normal cmd.exe command prompt window and run the following commands:
winget install Git.Git
winget install Kitware.CMake
winget install nsis.nsis
winget install Microsoft.VisualStudio.2022.Community
At this point we need to modify the Visual Studio installation to include support for C++ applications:
ModifyDesktop Development With C++Modify in the bottom-right corner, and then click on Yes[!IMPORTANT] Once everything is downloaded and installed, click on the "Windows Start" menu again and select
Developer Command Prompt for VS 2022. Do not use PowerShell for these steps, you will run into problems!
[!TIP] Instead of running the
Developer Command Prompt, you can use a normal command prompt or ssh into the device and manually run"\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat".
[!WARNING] Please don't skip this step! Re-read the "important" description above to see what kind of window you must be using. Anytime you want to use Visual Studio from the command prompt to compile C++ code you must use the Visual Studio developer command prompt as described above.
Once you have the Developer Command Prompt, run the following commands to install Microsoft VCPKG, which will then be used to build OpenBlas and OpenCV:
cd c:\
mkdir c:\src
cd c:\src
git clone https://github.com/microsoft/vcpkg
cd vcpkg
bootstrap-vcpkg.bat
.\vcpkg.exe integrate install
.\vcpkg.exe integrate powershell
.\vcpkg.exe install opencv[contrib,dnn,freetype,jpeg,openmp,png,webp,world]:x64-windows protobuf:x64-windows
Be patient at this last step as it can take a long time to run. It needs to download and build many things.
[!TIP] Note there are many other optional modules you may want to add when building OpenCV. Run
.\vcpkg.exe search opencvto see the full list.
[!IMPORTANT] Darknet can run without access to a GPU, but if you want to train a custom network or you need higher performance, then a modern NVIDIA GPU or AMD GPU is strongly recommended.
- Depending on which GPU you have, please read the NVIDIA GPU Readme or the AMD GPU Readme.
[!TIP] Adding the vcpkg
bindirectory to the environment variablePATHwill prevent later problems. The directory you'll want to add isC:/src/vcpkg/installed/x64-windows/bin/.
[!TIP] If you are building a CPU-only version of Darknet, you may want to install OpenBLAS to increase performance. These libraries are only used on CPU-only builds:
.\vcpkg.exe install openblas[core,threads]:x64-windows
Once all of the previous steps have finished successfully, you need to clone Darknet and build it. During this step we also need to tell CMake where vcpkg is located so it can find OpenCV and other dependencies. Make sure you continue to use the Developer Command Prompt as described above when you run these commands:
cd c:\src
git clone https://codeberg.org/CCodeRun/darknet.git
cd darknet
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=C:/src/vcpkg/scripts/buildsystems/vcpkg.cmake ..
msbuild.exe /property:Platform=x64;Configuration=Release /target:Build -maxCpuCount -verbosity:normal -detailedSummary darknet.sln
msbuild.exe /property:Platform=x64;Configuration=Release PACKAGE.vcxproj
[!TIP] Note that the output of the
cmakecommand is a normal Visual Studio solution file,darknet.sln. If you are a software developer who regularly uses the Visual Studio GUI instead ofmsbuild.exeto build projects, you can ignore the command-line and load the Darknet project in Visual Studio.
You should now have this file you can run: C:\src\Darknet\build\src-cli\Release\darknet.exe. Run this to test: C:\src\Darknet\build\src-cli\Release\darknet.exe --version.
To correctly install Darknet, the libraries, the include files, and the necessary DLLs, run the NSIS installation wizard that was built in the last step. See the file darknet-<INSERT-VERSION-YOU-BUILT-HERE>-win64.exe in the build directory. For example:
darknet-<INSERT-VERSION-YOU-BUILT-HERE>-win64.exe
Installing the NSIS installation package will:
Darknet, such as C:\Program Files\Darknet\.darknet.exe and other sample apps..dll files, such as those from OpenCV and Darknet..dll, .lib and header files to use darknet.dll from another application..cfg files.[!IMPORTANT] Make sure to update your
PATHto includeC:/Program Files/Darknet/bin(or wherever you chose to install it). Once you updatePATHyou'll need to restart your command prompt.
[!TIP] If you encounter an error about some missing Protocol Buffer DLL files such as
libprotobuf.dllandabseil_dll.dllwhen running the ONNX export tool, it probably means you forgot to update yourPATHor restart the command prompt. The missing DLLs can be found inC:/src/vcpkg/installed/x64-windows/bin/.
You are now done! Once the installation wizard has finished and PATH has been updated, run this command to test: darknet.exe version.
[!CAUTION] If you don't have
C:/Program Files/darknet/bin/darknet.exethen this means you did not install it, you only built it! Make sure you go through each panel of the NSIS installation wizard in the previous step.
To build Darknet via Docker with GPU support, nvidia-container-toolkit must be installed on your system, and the build process must be executed in docker run.
Below is an example Dockerfile built with the following command:
docker build -t darknet-hankai . && docker run -it --gpus all darknet-hankai
FROM nvidia/cuda:12.8.0-cudnn-devel-ubuntu24.04
# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV PATH="/usr/local/cuda/bin:${PATH}"
ENV LD_LIBRARY_PATH="/usr/local/cuda/lib64:${LD_LIBRARY_PATH}"
# Install dependencies
RUN apt-get update
RUN apt-get install -y build-essential git libopenblas64-openmp-dev libopencv-dev wget file cmake
# Set working directory for Darknet
WORKDIR /workspace
# Clone Darknet
RUN git clone https://codeberg.org/CCodeRun/darknet.git
# Defer building the Darknet package to runtime (GPU visible)
CMD ["/bin/bash", "-c", "\
cd /workspace/darknet && \
# initialize cmake
mkdir build && cd build && cmake ..; \
# build darknet
make -j$(nproc) package && \
# package darknet
dpkg -i /workspace/darknet/build/darknet-*.deb && \
# run darknet version to verify build & enter terminal
darknet version && \
exec /bin/bash"]
The following is not the full list of all commands supported by Darknet.
[!IMPORTANT] In addition to the Darknet CLI, also note the DarkHelp project CLI which provides an additional CLI to Darknet/YOLO. The DarkHelp CLI also has several advanced features that are not available directly in Darknet. You can use both the Darknet CLI and the DarkHelp CLI together, they are not mutually exclusive.
[!TIP] For most of the commands shown below, you'll need the
.weightsfile with the corresponding.namesand.cfgfiles. You can either train your own network (highly recommended!) or download a neural network that someone has already trained and made available for free on the internet. Examples of pre-trained datasets include:
- LEGO Gears (finding ojects in an image)
- Rolodex (finding text in an image)
- People-R-People (finding people in an image)
- MSCOCO (standard 80-class object detection)
Commands to run include:
List some possible commands and options to run:
darknet helpCheck the version:
darknet versionPredict using an image:
darknet detector test cars.data cars.cfg cars_best.weights image1.jpgdarknet_02_display_annotated_images cars.cfg image1.jpgDarkHelp cars.cfg cars.cfg cars_best.weights image1.jpgOutput coordinates:
darknet detector test animals.data animals.cfg animals_best.weights -ext_output dog.jpgdarknet_01_inference_images animals dog.jpgDarkHelp --json animals.cfg animals.names animals_best.weights dog.jpgWorking with videos:
darknet detector demo animals.data animals.cfg animals_best.weights -ext_output test.mp4darknet_03_display_videos animals.cfg test.mp4DarkHelp animals.cfg animals.names animals_best.weights test.mp4Reading from a webcam:
darknet detector demo animals.data animals.cfg animals_best.weights -c 0darknet_08_display_webcam animalsSave results to a video:
darknet detector demo animals.data animals.cfg animals_best.weights test.mp4 -out_filename res.avidarknet_05_process_videos_multithreaded animals.cfg animals.names animals_best.weights test.mp4DarkHelp animals.cfg animals.names animals_best.weights test.mp4JSON:
darknet detector demo animals.data animals.cfg animals_best.weights test50.mp4 -json_port 8070 -mjpeg_port 8090 -ext_outputdarknet_06_images_to_json animals image1.jpgDarkHelp --json animals.names animals.cfg animals_best.weights image1.jpgRunning on a specific GPU:
darknet detector demo animals.data animals.cfg animals_best.weights -i 1 test.mp4To check the accuracy of the neural network:
darknet detector map driving.data driving.cfg driving_best.weights
...
Id Name AvgPrecision TP FN FP TN Accuracy ErrorRate Precision Recall Specificity FalsePosRate
-- ---- ------------ ------ ------ ------ ------ -------- --------- --------- ------ ----------- ------------
0 vehicle 91.2495 32648 3903 5826 65129 0.9095 0.0905 0.8486 0.8932 0.9179 0.0821
1 motorcycle 80.4499 2936 513 569 5393 0.8850 0.1150 0.8377 0.8513 0.9046 0.0954
2 bicycle 89.0912 570 124 104 3548 0.9475 0.0525 0.8457 0.8213 0.9715 0.0285
3 person 76.7937 7072 1727 2574 27523 0.8894 0.1106 0.7332 0.8037 0.9145 0.0855
4 many vehicles 64.3089 1068 509 733 11288 0.9087 0.0913 0.5930 0.6772 0.9390 0.0610
5 green light 86.8118 1969 239 510 4116 0.8904 0.1096 0.7943 0.8918 0.8898 0.1102
6 yellow light 82.0390 126 38 30 1239 0.9525 0.0475 0.8077 0.7683 0.9764 0.0236
7 red light 94.1033 3449 217 451 4643 0.9237 0.0763 0.8844 0.9408 0.9115 0.0885
To check accuracy mAP@IoU=75:
darknet detector map animals.data animals.cfg animals_best.weights -iou_thresh 0.75Recalculating anchors is best done in DarkMark, since it will run 100 consecutive times and select the best anchors from all the ones that were calculated. But if you want to run the old version in Darknet:
darknet detector calc_anchors animals.data -num_of_clusters 6 -width 320 -height 256
Train a new network:
darknet detector -map -dont_show train animals.data animals.cfg (also see the training section below)Display YOLO heatmaps:
darknet_02_display_annotated_images --heatmaps cars images/*.jpgdarknet_03_display_videos --heatmaps cars videos/*.m4vONNX export:
darknet_onnx_export cars.cfgQuick links to relevant sections of the Darknet/YOLO FAQ:
[!TIP] The simplest way to annotate and train is with the use of DarkMark to create all of the necessary Darknet files. This is definitely the recommended way to train a new neural network.
If you'd rather manually setup the various files to train a custom network:
~/nn/animals/.cfg/yolov4-tiny.cfg. Place this in the folder you created. For this example, we now have ~/nn/animals/animals.cfg.animals.names text file in the same folder where you placed the configuration file. For this example, we now have ~/nn/animals/animals.names.animals.names file with your text editor. List the classes you want to use. You need to have exactly 1 entry per line, with no blank lines and no comments. For this example, the .names file will contain exactly 4 lines:dog
cat
bird
horse
animals.data text file in the same folder. For this example, the .data file will contain:classes = 4
train = /home/username/nn/animals/animals_train.txt
valid = /home/username/nn/animals/animals_valid.txt
names = /home/username/nn/animals/animals.names
backup = /home/username/nn/animals
~/nn/animals/dataset. Each image will need a coresponding .txt file which describes the annotations for that image. The format of the .txt annotation files is very specific. You cannot create these files by hand since each annotation needs to contain the exact coordinates for the annotation. See DarkMark or other similar software to annotate your images. The YOLO annotation format is described in the Darknet/YOLO FAQ..data file. These two text files need to individually list all of the images which Darknet must use to train and for validation when calculating the mAP%. Exactly one image per line. The path and filenames may be relative or absolute..cfg file with a text editor.
batch=64.1 so start with that. See the Darknet/YOLO FAQ if 1 doesn't work for you.max_batches=.... A good value to use when starting out is 2000 x the number of classes. For this example, we have 4 animals, so 4 * 2000 = 8000. Meaning we'll use max_batches=8000.steps=.... This should be set to 80% and 90% of max_batches. For this example we'd use steps=6400,7200 since max_batches was set to 8000.width=... and height=.... These are the network dimensions. The Darknet/YOLO FAQ explains how to calculate the best size to use.classes=... and modify it with the number of classes in your .names file. For this example, we'd use classes=4.filters=... in the [convolutional] section prior to each [yolo] section. The value to use is (number_of_classes + 5) * 3. Meaning for this example, (4 + 5) * 3 = 27. So we'd use filters=27 on the appropriate lines.cd ~/nn/animals/
darknet detector -map -dont_show train animals.data animals.cfg
-gpus ... flag like this example with 4 GPUs:cd ~/nn/animals/
darknet detector -gpus 0,1,2,3 -map -dont_show train animals.data animals.cfg
Be patient. The best weights will be saved as animals_best.weights. And the progress of training can be observed by viewing the chart.png file. See the Darknet/YOLO FAQ for additional parameters you may want to use when training a new network.
If you want to see more details during training, add the -verbose parameter. For example:
cd ~/nn/animals/
darknet detector -map -dont_show -verbose train animals.data animals.cfg
The -log ... flag can be used to send all of the console output to a file. For example:
cd ~/nn/animals/
darknet detector -gpus 0 -verbose -log output.log -map -dont_show train animals.data animals.cfg
Thank you to both individual and corporate sponsors. A special thanks to past corporate sponsors who helped fund the continued development of Darknet/YOLO.
In alphabetical order, this includes:
Last updated 2026-06-27:
cv::Mat to void* but use it as a proper C++ objectimage structure gets usedchar* code and replace with std::stringcv::Mat instead of the custom image structure in C (in progress)list functionality with std::vector or std::list (in progress)(top 30 of 103)
C++
86.0%
Cuda
8.4%
Python
2.3%
C
1.3%
CMake
1.2%
Darknet/YOLO object detection framework
848
stars
3,072
commits
C++
primary language
Aug 30, 2026
updated

Darknet is an open source neural network framework written in C, C++, and CUDA.
YOLO (You Only Look Once) is a state-of-the-art, real-time, object detection system, which runs in the Darknet framework.
The Darknet/YOLO framework continues to be both faster and more accurate than other frameworks and versions of YOLO.
This framework is both completely free and open source. You can incorporate Darknet/YOLO into existing projects and products -- including commercial ones -- without a license or paying a fee.
Darknet V3 ("Jazz") released in October 2024 can accurately run the LEGO dataset videos at up to 1000 FPS when using a NVIDIA RTX 3090 GPU, meaning each video frame is read, resized, and processed by Darknet/YOLO in 1 millisecond or less. Additional performance improvements have been implemented in Darknet V4 and the upcoming Darknet V5, without compromising the quality of detections.
Please join the Darknet/YOLO Discord server if you need help or you want to discuss Darknet/YOLO and related tools: https://discord.gg/MQw32W9Cqr
The CPU version of Darknet/YOLO can run on simple devices such as Raspberry Pi, cloud & colab servers, desktops, laptops, and high-end training rigs. The GPU version of Darknet/YOLO requires either a CUDA-capable GPU from NVIDIA, or a ROCm-capable GPU from AMD.
Darknet/YOLO is known to work on Linux, Windows, and Mac. See the building instructions below.
version command. From 2023 until late 2024, it returned version 2.x "OAK".
v2 branch.version command now returns 3.x "JAZZ".
v2 branch if you need to run one of these commands. Let us know so we can investigate adding back any missing commands.src-examples: https://www.ccoderun.ca/darknet/files.htmlversion command now returns 4.x "SLATE".
printf() and std::cout calls have all been replaced so Darknet/YOLO logging messages can easily be redirected.version command now returns 5.x "Moonlit".
People are generally expected to train their own network. But pre-trained weights are also popular. These are weights which someone else has trained and made available for free on the internet. This is sometimes convenient when first installing Darknet/YOLO, since the software can be quickly tested without having to train a new neural network.
person and head)person, backpack, chair, clock, ...)The People-R-People pre-trained weights are used to find people. This dataset only has 2 classes: person and head.

You can download these pre-trained weights directly from C Code Run's web site.
Several popular versions of YOLO were pre-trained for convenience on the MSCOCO dataset. This dataset has 80 classes, which can be seen in the text file cfg/coco.names.
The MSCOCO pre-trained weights can be downloaded from several different locations, and are also available for download from this repo:
The MSCOCO pre-trained weights are provided for demo-purpose only. The corresponding .cfg and .names files for MSCOCO are in the cfg directory. Example commands:
wget --no-clobber https://github.com/hank-ai/darknet/releases/download/v2.0/yolov4-tiny.weights
darknet_02_display_annotated_images coco.names yolov4-tiny.cfg yolov4-tiny.weights image1.jpg
darknet_03_display_videos coco.names yolov4-tiny.cfg yolov4-tiny.weights video1.avi
DarkHelp coco.names yolov4-tiny.cfg yolov4-tiny.weights image1.jpg
DarkHelp coco.names yolov4-tiny.cfg yolov4-tiny.weights video1.avi
The various build methods available in the past (pre-2023) have been merged together into a single unified solution. Darknet requires C++17 or newer, OpenCV, and uses CMake to generate the necessary project files.
[!NOTE] You do not need to know CMake, C++, C, Python, or any other programmaing language to build, install, nor run Darknet/YOLO. Some advanced topics -- such as using the Darknet/YOLO API -- does require programming experience.
Select one of the following build types:
[!CAUTION] Beware if you are following old tutorials with more complicated build steps, or build steps that don't seem to match what is in this readme. The new build steps started in August 2023.
Software developers are encouraged to visit https://www.ccoderun.ca/darknet/ to get information on the internals of the Darknet/YOLO object detection framework.
[!IMPORTANT] An important change was made in Darknet v5.1 to one of the prediction structures. If you have software that includes
darknet.hordarknet.hppyou'll want to recompile your application to prevent segfaults.
The Google Colab instructions are the same as the Linux instructions. Several Jupyter notebooks are available showing how to do certain tasks, such as training a new network.
See the notebooks in the colab subdirectory for details, and/or follow the Linux instructions below.
If you have a modern version of Windows and a decent computer, then the use of WSL (Windows Subsystem for Linux) and Ubuntu 24.04 LTS is highly recommended.
WSL is a feature in Windows which allows people to run Linux-based applications from within their Windows desktop. This is similar to a virtual machine with host/guest extensions. Linux apps running in WSL have access to the GPU if you install the Linux NVIDIA driver for WSL, and you can train a new network with Darknet/YOLO running within WSL.
[!TIP] Once WSL is installed, please remember to run
sudo apt-get updateat least once from your Ubuntu command prompt to get the updated list of packages, and then follow the usual Linux instructions.
If you don't want to use Darknet/YOLO from within WSL, then skip ahead to the Windows instructions.
[!IMPORTANT] Darknet can run without access to a GPU, but if you want to train a custom network or you need higher performance, then a modern NVIDIA GPU or AMD GPU is strongly recommended.
- Depending on which GPU you have, please read the NVIDIA GPU Readme or the AMD GPU Readme.
[!TIP] If you are building a CPU-only version of Darknet, you may want to install OpenBLAS to increase performance. These libraries are only used on CPU-only builds:
sudo apt-get install libopenblas64-0 libopenblas64-0-openmp libopenblas64-openmp-dev
The following instructions assume (but do not require!) a system running Ubuntu 22.04. Adapt as necessary if you're using a different Linux distribution.
sudo apt-get install build-essential git libopencv-dev cmake libprotobuf-dev protobuf-compiler
mkdir ~/src
cd ~/src
git clone https://codeberg.org/CCodeRun/darknet.git
cd darknet
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j4 package
sudo dpkg -i darknet-<INSERT-VERSION-YOU-BUILT-HERE>.deb
[!WARNING] If you are using an older version of CMake then you'll need to upgrade CMake before you can run the
cmakecommand above. Upgrading CMake on Ubuntu can be done with the following commands:
sudo apt-get purge cmake
sudo snap install cmake --classic
[!WARNING] If using
bashas your command shell you'll want to re-start your shell at this point. If usingfish, it should immediately pick up the new path.
[!TIP] Advanced users:
See the readme for PGO (Profile-Guided Optimization) if you want to run an optimized Darknet/YOLO.
[!TIP] Advanced users:
If you want to build a RPM installation file instead of a DEB file, see the relevant lines inCM_package.cmake. Prior to runningmake -j4 packageyou'll need to edit these two lines:
SET (CPACK_GENERATOR "DEB")
# SET (CPACK_GENERATOR "RPM")
For distros such as Centos and OpenSUSE, you'll need to switch those two lines in
CM_package.cmaketo be:
# SET (CPACK_GENERATOR "DEB")
SET (CPACK_GENERATOR "RPM")
To install the installation package once it has finished building, use the usual package manager for your distribution. For example, on Debian-based systems such as Ubuntu:
sudo dpkg -i darknet-2.0.1-Linux.deb
Installing the .deb (or .rpm) package will install the following files:
/usr/bin/darknet*... are the usual Darknet executables. Run darknet version from the CLI to confirm it is installed correctly./usr/include/darknet*... are the Darknet API header files for C, C++, and Python developers./usr/lib/libdarknet.so is the library to link against for C, C++, and Python developers./opt/darknet/cfg/... is where all the .cfg templates are stored.You are now done! Darknet has been built and installed into /usr/bin/. Run this to test: darknet version.
[!CAUTION] If you don't have
/usr/bin/darknetthen this means you did not install it, you only built it! Make sure you install the.debor.rpmfile as described above.
[!IMPORTANT] Before building Darknet/YOLO for Windows please see the note about using WSL. (Spoiler ... Darknet/YOLO works great in WSL!)
Open a normal cmd.exe command prompt window and run the following commands:
winget install Git.Git
winget install Kitware.CMake
winget install nsis.nsis
winget install Microsoft.VisualStudio.2022.Community
At this point we need to modify the Visual Studio installation to include support for C++ applications:
ModifyDesktop Development With C++Modify in the bottom-right corner, and then click on Yes[!IMPORTANT] Once everything is downloaded and installed, click on the "Windows Start" menu again and select
Developer Command Prompt for VS 2022. Do not use PowerShell for these steps, you will run into problems!
[!TIP] Instead of running the
Developer Command Prompt, you can use a normal command prompt or ssh into the device and manually run"\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat".
[!WARNING] Please don't skip this step! Re-read the "important" description above to see what kind of window you must be using. Anytime you want to use Visual Studio from the command prompt to compile C++ code you must use the Visual Studio developer command prompt as described above.
Once you have the Developer Command Prompt, run the following commands to install Microsoft VCPKG, which will then be used to build OpenBlas and OpenCV:
cd c:\
mkdir c:\src
cd c:\src
git clone https://github.com/microsoft/vcpkg
cd vcpkg
bootstrap-vcpkg.bat
.\vcpkg.exe integrate install
.\vcpkg.exe integrate powershell
.\vcpkg.exe install opencv[contrib,dnn,freetype,jpeg,openmp,png,webp,world]:x64-windows protobuf:x64-windows
Be patient at this last step as it can take a long time to run. It needs to download and build many things.
[!TIP] Note there are many other optional modules you may want to add when building OpenCV. Run
.\vcpkg.exe search opencvto see the full list.
[!IMPORTANT] Darknet can run without access to a GPU, but if you want to train a custom network or you need higher performance, then a modern NVIDIA GPU or AMD GPU is strongly recommended.
- Depending on which GPU you have, please read the NVIDIA GPU Readme or the AMD GPU Readme.
[!TIP] Adding the vcpkg
bindirectory to the environment variablePATHwill prevent later problems. The directory you'll want to add isC:/src/vcpkg/installed/x64-windows/bin/.
[!TIP] If you are building a CPU-only version of Darknet, you may want to install OpenBLAS to increase performance. These libraries are only used on CPU-only builds:
.\vcpkg.exe install openblas[core,threads]:x64-windows
Once all of the previous steps have finished successfully, you need to clone Darknet and build it. During this step we also need to tell CMake where vcpkg is located so it can find OpenCV and other dependencies. Make sure you continue to use the Developer Command Prompt as described above when you run these commands:
cd c:\src
git clone https://codeberg.org/CCodeRun/darknet.git
cd darknet
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=C:/src/vcpkg/scripts/buildsystems/vcpkg.cmake ..
msbuild.exe /property:Platform=x64;Configuration=Release /target:Build -maxCpuCount -verbosity:normal -detailedSummary darknet.sln
msbuild.exe /property:Platform=x64;Configuration=Release PACKAGE.vcxproj
[!TIP] Note that the output of the
cmakecommand is a normal Visual Studio solution file,darknet.sln. If you are a software developer who regularly uses the Visual Studio GUI instead ofmsbuild.exeto build projects, you can ignore the command-line and load the Darknet project in Visual Studio.
You should now have this file you can run: C:\src\Darknet\build\src-cli\Release\darknet.exe. Run this to test: C:\src\Darknet\build\src-cli\Release\darknet.exe --version.
To correctly install Darknet, the libraries, the include files, and the necessary DLLs, run the NSIS installation wizard that was built in the last step. See the file darknet-<INSERT-VERSION-YOU-BUILT-HERE>-win64.exe in the build directory. For example:
darknet-<INSERT-VERSION-YOU-BUILT-HERE>-win64.exe
Installing the NSIS installation package will:
Darknet, such as C:\Program Files\Darknet\.darknet.exe and other sample apps..dll files, such as those from OpenCV and Darknet..dll, .lib and header files to use darknet.dll from another application..cfg files.[!IMPORTANT] Make sure to update your
PATHto includeC:/Program Files/Darknet/bin(or wherever you chose to install it). Once you updatePATHyou'll need to restart your command prompt.
[!TIP] If you encounter an error about some missing Protocol Buffer DLL files such as
libprotobuf.dllandabseil_dll.dllwhen running the ONNX export tool, it probably means you forgot to update yourPATHor restart the command prompt. The missing DLLs can be found inC:/src/vcpkg/installed/x64-windows/bin/.
You are now done! Once the installation wizard has finished and PATH has been updated, run this command to test: darknet.exe version.
[!CAUTION] If you don't have
C:/Program Files/darknet/bin/darknet.exethen this means you did not install it, you only built it! Make sure you go through each panel of the NSIS installation wizard in the previous step.
To build Darknet via Docker with GPU support, nvidia-container-toolkit must be installed on your system, and the build process must be executed in docker run.
Below is an example Dockerfile built with the following command:
docker build -t darknet-hankai . && docker run -it --gpus all darknet-hankai
FROM nvidia/cuda:12.8.0-cudnn-devel-ubuntu24.04
# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV PATH="/usr/local/cuda/bin:${PATH}"
ENV LD_LIBRARY_PATH="/usr/local/cuda/lib64:${LD_LIBRARY_PATH}"
# Install dependencies
RUN apt-get update
RUN apt-get install -y build-essential git libopenblas64-openmp-dev libopencv-dev wget file cmake
# Set working directory for Darknet
WORKDIR /workspace
# Clone Darknet
RUN git clone https://codeberg.org/CCodeRun/darknet.git
# Defer building the Darknet package to runtime (GPU visible)
CMD ["/bin/bash", "-c", "\
cd /workspace/darknet && \
# initialize cmake
mkdir build && cd build && cmake ..; \
# build darknet
make -j$(nproc) package && \
# package darknet
dpkg -i /workspace/darknet/build/darknet-*.deb && \
# run darknet version to verify build & enter terminal
darknet version && \
exec /bin/bash"]
The following is not the full list of all commands supported by Darknet.
[!IMPORTANT] In addition to the Darknet CLI, also note the DarkHelp project CLI which provides an additional CLI to Darknet/YOLO. The DarkHelp CLI also has several advanced features that are not available directly in Darknet. You can use both the Darknet CLI and the DarkHelp CLI together, they are not mutually exclusive.
[!TIP] For most of the commands shown below, you'll need the
.weightsfile with the corresponding.namesand.cfgfiles. You can either train your own network (highly recommended!) or download a neural network that someone has already trained and made available for free on the internet. Examples of pre-trained datasets include:
- LEGO Gears (finding ojects in an image)
- Rolodex (finding text in an image)
- People-R-People (finding people in an image)
- MSCOCO (standard 80-class object detection)
Commands to run include:
List some possible commands and options to run:
darknet helpCheck the version:
darknet versionPredict using an image:
darknet detector test cars.data cars.cfg cars_best.weights image1.jpgdarknet_02_display_annotated_images cars.cfg image1.jpgDarkHelp cars.cfg cars.cfg cars_best.weights image1.jpgOutput coordinates:
darknet detector test animals.data animals.cfg animals_best.weights -ext_output dog.jpgdarknet_01_inference_images animals dog.jpgDarkHelp --json animals.cfg animals.names animals_best.weights dog.jpgWorking with videos:
darknet detector demo animals.data animals.cfg animals_best.weights -ext_output test.mp4darknet_03_display_videos animals.cfg test.mp4DarkHelp animals.cfg animals.names animals_best.weights test.mp4Reading from a webcam:
darknet detector demo animals.data animals.cfg animals_best.weights -c 0darknet_08_display_webcam animalsSave results to a video:
darknet detector demo animals.data animals.cfg animals_best.weights test.mp4 -out_filename res.avidarknet_05_process_videos_multithreaded animals.cfg animals.names animals_best.weights test.mp4DarkHelp animals.cfg animals.names animals_best.weights test.mp4JSON:
darknet detector demo animals.data animals.cfg animals_best.weights test50.mp4 -json_port 8070 -mjpeg_port 8090 -ext_outputdarknet_06_images_to_json animals image1.jpgDarkHelp --json animals.names animals.cfg animals_best.weights image1.jpgRunning on a specific GPU:
darknet detector demo animals.data animals.cfg animals_best.weights -i 1 test.mp4To check the accuracy of the neural network:
darknet detector map driving.data driving.cfg driving_best.weights
...
Id Name AvgPrecision TP FN FP TN Accuracy ErrorRate Precision Recall Specificity FalsePosRate
-- ---- ------------ ------ ------ ------ ------ -------- --------- --------- ------ ----------- ------------
0 vehicle 91.2495 32648 3903 5826 65129 0.9095 0.0905 0.8486 0.8932 0.9179 0.0821
1 motorcycle 80.4499 2936 513 569 5393 0.8850 0.1150 0.8377 0.8513 0.9046 0.0954
2 bicycle 89.0912 570 124 104 3548 0.9475 0.0525 0.8457 0.8213 0.9715 0.0285
3 person 76.7937 7072 1727 2574 27523 0.8894 0.1106 0.7332 0.8037 0.9145 0.0855
4 many vehicles 64.3089 1068 509 733 11288 0.9087 0.0913 0.5930 0.6772 0.9390 0.0610
5 green light 86.8118 1969 239 510 4116 0.8904 0.1096 0.7943 0.8918 0.8898 0.1102
6 yellow light 82.0390 126 38 30 1239 0.9525 0.0475 0.8077 0.7683 0.9764 0.0236
7 red light 94.1033 3449 217 451 4643 0.9237 0.0763 0.8844 0.9408 0.9115 0.0885
To check accuracy mAP@IoU=75:
darknet detector map animals.data animals.cfg animals_best.weights -iou_thresh 0.75Recalculating anchors is best done in DarkMark, since it will run 100 consecutive times and select the best anchors from all the ones that were calculated. But if you want to run the old version in Darknet:
darknet detector calc_anchors animals.data -num_of_clusters 6 -width 320 -height 256
Train a new network:
darknet detector -map -dont_show train animals.data animals.cfg (also see the training section below)Display YOLO heatmaps:
darknet_02_display_annotated_images --heatmaps cars images/*.jpgdarknet_03_display_videos --heatmaps cars videos/*.m4vONNX export:
darknet_onnx_export cars.cfgQuick links to relevant sections of the Darknet/YOLO FAQ:
[!TIP] The simplest way to annotate and train is with the use of DarkMark to create all of the necessary Darknet files. This is definitely the recommended way to train a new neural network.
If you'd rather manually setup the various files to train a custom network:
~/nn/animals/.cfg/yolov4-tiny.cfg. Place this in the folder you created. For this example, we now have ~/nn/animals/animals.cfg.animals.names text file in the same folder where you placed the configuration file. For this example, we now have ~/nn/animals/animals.names.animals.names file with your text editor. List the classes you want to use. You need to have exactly 1 entry per line, with no blank lines and no comments. For this example, the .names file will contain exactly 4 lines:dog
cat
bird
horse
animals.data text file in the same folder. For this example, the .data file will contain:classes = 4
train = /home/username/nn/animals/animals_train.txt
valid = /home/username/nn/animals/animals_valid.txt
names = /home/username/nn/animals/animals.names
backup = /home/username/nn/animals
~/nn/animals/dataset. Each image will need a coresponding .txt file which describes the annotations for that image. The format of the .txt annotation files is very specific. You cannot create these files by hand since each annotation needs to contain the exact coordinates for the annotation. See DarkMark or other similar software to annotate your images. The YOLO annotation format is described in the Darknet/YOLO FAQ..data file. These two text files need to individually list all of the images which Darknet must use to train and for validation when calculating the mAP%. Exactly one image per line. The path and filenames may be relative or absolute..cfg file with a text editor.
batch=64.1 so start with that. See the Darknet/YOLO FAQ if 1 doesn't work for you.max_batches=.... A good value to use when starting out is 2000 x the number of classes. For this example, we have 4 animals, so 4 * 2000 = 8000. Meaning we'll use max_batches=8000.steps=.... This should be set to 80% and 90% of max_batches. For this example we'd use steps=6400,7200 since max_batches was set to 8000.width=... and height=.... These are the network dimensions. The Darknet/YOLO FAQ explains how to calculate the best size to use.classes=... and modify it with the number of classes in your .names file. For this example, we'd use classes=4.filters=... in the [convolutional] section prior to each [yolo] section. The value to use is (number_of_classes + 5) * 3. Meaning for this example, (4 + 5) * 3 = 27. So we'd use filters=27 on the appropriate lines.cd ~/nn/animals/
darknet detector -map -dont_show train animals.data animals.cfg
-gpus ... flag like this example with 4 GPUs:cd ~/nn/animals/
darknet detector -gpus 0,1,2,3 -map -dont_show train animals.data animals.cfg
Be patient. The best weights will be saved as animals_best.weights. And the progress of training can be observed by viewing the chart.png file. See the Darknet/YOLO FAQ for additional parameters you may want to use when training a new network.
If you want to see more details during training, add the -verbose parameter. For example:
cd ~/nn/animals/
darknet detector -map -dont_show -verbose train animals.data animals.cfg
The -log ... flag can be used to send all of the console output to a file. For example:
cd ~/nn/animals/
darknet detector -gpus 0 -verbose -log output.log -map -dont_show train animals.data animals.cfg
Thank you to both individual and corporate sponsors. A special thanks to past corporate sponsors who helped fund the continued development of Darknet/YOLO.
In alphabetical order, this includes:
Last updated 2026-06-27:
cv::Mat to void* but use it as a proper C++ objectimage structure gets usedchar* code and replace with std::stringcv::Mat instead of the custom image structure in C (in progress)list functionality with std::vector or std::list (in progress)(top 30 of 103)
C++
86.0%
Cuda
8.4%
Python
2.3%
C
1.3%
CMake
1.2%