• Version: 20261019
  • Source Code Copyright: Public domain (Darknet “YOLO LICENSE” Version 2) — AlexeyAB/darknet
  • Redistribution Restriction: This source code is integrated by LEADERG INC. Please use it privately. Please DO NOT distribute it to internet.

Pure C++ sample: YOLOv7 training and inference with Darknet (AlexeyAB), driven directly by .bat / .sh scripts — no Python, no venv. Data preparation uses tools built into each OS (PowerShell on Windows, bash + awk on Linux). Example datasets with trained weights: plate (steel-plate surface defects, 4 classes) and tumor (tumor detection, 1 class), both Pascal VOC XML. Pass tumor instead of plate to any script to use the tumor example.

Binaries: Linux ships src/darknet/darknet (GPU/CUDA) and src/darknet/darknet_no_GPU (CPU). Windows ships the CPU build darknet_no_gpu.exe under src/darknet/build/darknet/x64/ (DLLs beside the .exe). Scripts default to cpu; pass gpu to use the GPU build.

 

[Files & Folders]

  • CLAUDE.md / AGENTS.md — the program specification. The two files are kept identical.
  • CHANGELOG.md — change log.
  • copyright.txt — copyright notice.
  • Image-Object-Detection-YOLOv7-CPP.html — this usage page.
  • bin/labels/ — Darknet glyph images (auto-copied to data/labels/ on first run so darknet can draw class names).
  • data/{dataset}/ — label.names, yolov7.cfg, voc.data, train/valid/test.txt, and train|val|test/{images,annotations} (YOLO .txt beside the images).
  • model/{dataset}/ — yolov7_best.weights, training backups, predict/ outputs.
  • src/darknet/ — Darknet (AlexeyAB) C++ source + binaries.
  • src/convert_yolo_format.ps1 — PowerShell VOC→YOLO converter used by the .bat.
  • No venv/, no requirements.txt, no .py files.

[Prerequisites]

  • No Python. Windows: built-in PowerShell. Linux: bash/awk (preinstalled on Ubuntu 24.04).
  • Linux GPU build needs CUDA 12 runtime + cuDNN + OpenCV libraries; CPU builds need nothing extra. Execute bits are restored automatically by the .sh scripts.
  • Annotation (step 01) uses the external LEADERG image-annotation-server executable (../../gpu|cpu/bin/annotation/); optional — the pipeline only consumes the XML files.

[Quick Start (Ubuntu 24.04)]

bash src/02_convert_yolo_format.sh plate

bash src/03_prepare.sh plate

bash src/05_train.sh plate gpu

bash src/06_inference.sh data/plate/test/images/inclusion-2.jpg plate gpu

bash src/07_inference_folder.sh data/plate/test/images plate gpu

[Quick Start (Windows 11)]

src\02_convert_yolo_format.bat plate

src\03_prepare.bat plate

src\05_train.bat plate cpu

src\06_inference.bat data\plate\test\images\inclusion-2.jpg plate cpu

src\07_inference_folder.bat data\plate\test\images plate cpu

The shipped Windows build is CPU-only; add a GPU darknet.exe + DLLs to src\darknet\build\darknet\x64\ to use gpu.

[Scripts (positional arguments, all optional)]

1. 01_annotation.bat / 01_annotation.sh

External annotation server. [dataset] [port] (plate 8814).

 

2. 02_convert_yolo_format.bat / 02_convert_yolo_format.sh

VOC XML → YOLO txt beside images. [dataset]. PowerShell / awk.

 

3. 03_prepare.bat / 03_prepare.sh

Write train/valid/test.txt + voc.data. [dataset].

 

4. 04_calculate_anchors.bat / 04_calculate_anchors.sh

Darknet k-means anchors. [dataset] [cpu|gpu] [clusters] [w] [h].

 

5. 05_train.bat / 05_train.sh

Train (-map -clear -dont_show). [dataset] [cpu|gpu] [weights]. Checkpoints → model/{dataset}/.

 

6. 06_inference.bat / 06_inference.sh

Single image → model/{dataset}/predict/{name}_pred.jpg. [image] [dataset] [cpu|gpu] [thresh].

 

7. 07_inference_folder.bat / 07_inference_folder.sh

Per-image darknet over a folder → predict/. [folder] [dataset] [cpu|gpu] [thresh].

[Troubleshooting]

  • Linux libcudart.so.12 not found (gpu): install the CUDA 12 runtime + cuDNN (diagnose with ldd src/darknet/darknet | grep "not found") or use cpu.
  • Missing OpenCV lib (Linux): sudo apt install libopencv-dev.
  • Windows "no darknet executable found": only the CPU darknet_no_gpu.exe ships under src\darknet\build\darknet\x64\ — use cpu or add a GPU darknet.exe.

[References]

 

This SDK is built in AppForAI - AI Dev Tools.