# pjreddie/darknet architecture

> Architecture diagram of the GitHub repository pjreddie/darknet, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pjreddie/darknet
- Repository: https://github.com/pjreddie/darknet

## Overview

Darknet is a C/CUDA neural-network framework. A typical detection workflow configures a network, loads image data, runs network inference, and produces detections or a visual demo; the framework also supports training and other network tasks. The graph retains major network, data, image, and layer-computation subsystems. Relationships are limited to calls or references visible in excerpts, the source index, or README; unsampled implementation details are not asserted.

Main entry points: [`src/network.c`](https://github.com/pjreddie/darknet/blob/master/src/network.c) (Network runtime), [`src/parser.c`](https://github.com/pjreddie/darknet/blob/master/src/parser.c) (Config parser), [`src/convolutional_layer.c`](https://github.com/pjreddie/darknet/blob/master/src/convolutional_layer.c) (Convolution), [`src/demo.c`](https://github.com/pjreddie/darknet/blob/master/src/demo.c) (Detection demo)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_configuration["Configuration and API"]
  node_api["Public API<br/>[darknet.h]"]
  node_parser["Config parser<br/>[parser.c]"]
  node_python_binding["Python interface<br/>[darknet.py]"]
end

subgraph group_data["Data and Images"]
  node_data_loading["Data loading<br/>[data.c]"]
  node_image_ops["Image operations<br/>[image.c]"]
end

subgraph group_compute["Network Computation"]
  node_network["Network runtime<br/>[network.c]"]
  node_layer_types["Layer registry<br/>[layer.c]"]
  node_convolution["Convolution"]
  node_connected["Connected layers<br/>[connected_layer.c]"]
  node_batchnorm["Batch normalization<br/>[batchnorm_layer.c]"]
  node_detection_layers["Detection layers<br/>[detection_layer.c]"]
  node_region_yolo["Region and YOLO<br/>[region_layer.c]"]
  node_recurrent["Recurrent layers<br/>[rnn_layer.c]"]
  node_activations["Activations<br/>[activations.c]"]
  node_blas["Tensor operations<br/>[blas.c]"]
  node_cuda["CUDA support<br/>[cuda.c]"]
end

subgraph group_results["Inference and Results"]
  node_box_geometry["Box geometry<br/>[box.c]"]
  node_demo["Detection demo<br/>[demo.c]"]
end

node_client(("Framework user"))

node_client -->|"uses"| node_api
node_parser -->|"constructs layers"| node_layer_types
node_parser -->|"creates layer"| node_convolution
node_parser -->|"creates layer"| node_recurrent
node_network -.->|"loads configuration"| node_parser
node_network -->|"uses data"| node_data_loading
node_network -->|"dispatches layers"| node_convolution
node_network -->|"dispatches layers"| node_connected
node_network -->|"dispatches layers"| node_detection_layers
node_network -->|"dispatches layers"| node_region_yolo
node_convolution -->|"uses"| node_batchnorm
node_convolution -->|"uses operations"| node_blas
node_connected -->|"uses operations"| node_blas
node_detection_layers -->|"uses operations"| node_blas
node_region_yolo -->|"uses geometry"| node_box_geometry
node_data_loading -->|"uses images"| node_image_ops
node_demo -->|"uses runtime"| node_network
node_demo -->|"uses detections"| node_detection_layers
node_demo -->|"renders results"| node_image_ops
node_python_binding -.->|"wraps API"| node_api
node_network -.->|"GPU execution"| node_cuda

click node_api "https://github.com/pjreddie/darknet/blob/master/include/darknet.h"
click node_parser "https://github.com/pjreddie/darknet/blob/master/src/parser.c"
click node_network "https://github.com/pjreddie/darknet/blob/master/src/network.c"
click node_layer_types "https://github.com/pjreddie/darknet/blob/master/src/layer.c"
click node_convolution "https://github.com/pjreddie/darknet/blob/master/src/convolutional_layer.c"
click node_connected "https://github.com/pjreddie/darknet/blob/master/src/connected_layer.c"
click node_batchnorm "https://github.com/pjreddie/darknet/blob/master/src/batchnorm_layer.c"
click node_detection_layers "https://github.com/pjreddie/darknet/blob/master/src/detection_layer.c"
click node_region_yolo "https://github.com/pjreddie/darknet/blob/master/src/region_layer.c"
click node_recurrent "https://github.com/pjreddie/darknet/blob/master/src/rnn_layer.c"
click node_activations "https://github.com/pjreddie/darknet/blob/master/src/activations.c"
click node_blas "https://github.com/pjreddie/darknet/blob/master/src/blas.c"
click node_cuda "https://github.com/pjreddie/darknet/blob/master/src/cuda.c"
click node_data_loading "https://github.com/pjreddie/darknet/blob/master/src/data.c"
click node_image_ops "https://github.com/pjreddie/darknet/blob/master/src/image.c"
click node_box_geometry "https://github.com/pjreddie/darknet/blob/master/src/box.c"
click node_demo "https://github.com/pjreddie/darknet/blob/master/src/demo.c"
click node_python_binding "https://github.com/pjreddie/darknet/blob/master/python/darknet.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api,node_parser,node_python_binding,node_client toneBlue
class node_data_loading,node_image_ops toneAmber
class node_network,node_layer_types,node_convolution,node_connected,node_batchnorm,node_detection_layers,node_region_yolo,node_recurrent,node_activations,node_blas,node_cuda toneMint
class node_box_geometry,node_demo toneRose
```

## Components

### Configuration and API

- [Public API](https://github.com/pjreddie/darknet/blob/master/include/darknet.h): `include/darknet.h`
- [Config parser](https://github.com/pjreddie/darknet/blob/master/src/parser.c): `src/parser.c`
- [Python interface](https://github.com/pjreddie/darknet/blob/master/python/darknet.py): `python/darknet.py`

### Data and Images

- [Data loading](https://github.com/pjreddie/darknet/blob/master/src/data.c): `src/data.c`
- [Image operations](https://github.com/pjreddie/darknet/blob/master/src/image.c): `src/image.c`

### Network Computation

- [Network runtime](https://github.com/pjreddie/darknet/blob/master/src/network.c): `src/network.c`
- [Layer registry](https://github.com/pjreddie/darknet/blob/master/src/layer.c): `src/layer.c`
- [Convolution](https://github.com/pjreddie/darknet/blob/master/src/convolutional_layer.c): `src/convolutional_layer.c`
- [Connected layers](https://github.com/pjreddie/darknet/blob/master/src/connected_layer.c): `src/connected_layer.c`
- [Batch normalization](https://github.com/pjreddie/darknet/blob/master/src/batchnorm_layer.c): `src/batchnorm_layer.c`
- [Detection layers](https://github.com/pjreddie/darknet/blob/master/src/detection_layer.c): `src/detection_layer.c`
- [Region and YOLO](https://github.com/pjreddie/darknet/blob/master/src/region_layer.c): `src/region_layer.c`
- [Recurrent layers](https://github.com/pjreddie/darknet/blob/master/src/rnn_layer.c): `src/rnn_layer.c`
- [Activations](https://github.com/pjreddie/darknet/blob/master/src/activations.c): `src/activations.c`
- [Tensor operations](https://github.com/pjreddie/darknet/blob/master/src/blas.c): `src/blas.c`
- [CUDA support](https://github.com/pjreddie/darknet/blob/master/src/cuda.c): `src/cuda.c`

### Inference and Results

- [Box geometry](https://github.com/pjreddie/darknet/blob/master/src/box.c): `src/box.c`
- [Detection demo](https://github.com/pjreddie/darknet/blob/master/src/demo.c): `src/demo.c`

### Other components

- **Framework user**

## Connections

- Framework user → Public API: uses (evidence: `include/darknet.h`)
- Config parser → Layer registry: constructs layers (evidence: `src/parser.c`)
- Config parser → Convolution: creates layer (evidence: `src/parser.c`)
- Config parser → Recurrent layers: creates layer (evidence: `src/parser.c`)
- Network runtime → Config parser: loads configuration
- Network runtime → Data loading: uses data (evidence: `src/network.c`)
- Network runtime → Convolution: dispatches layers (evidence: `src/network.c`)
- Network runtime → Connected layers: dispatches layers (evidence: `src/network.c`)
- Network runtime → Detection layers: dispatches layers (evidence: `src/network.c`)
- Network runtime → Region and YOLO: dispatches layers (evidence: `src/network.c`)
- Convolution → Batch normalization: uses (evidence: `src/convolutional_layer.c`)
- Convolution → Tensor operations: uses operations (evidence: `src/convolutional_layer.c`)
- Connected layers → Tensor operations: uses operations (evidence: `src/connected_layer.c`)
- Detection layers → Tensor operations: uses operations (evidence: `src/detection_layer.c`)
- Region and YOLO → Box geometry: uses geometry (evidence: `src/region_layer.c`)
- Data loading → Image operations: uses images (evidence: `src/data.c`)
- Detection demo → Network runtime: uses runtime (evidence: `src/demo.c`)
- Detection demo → Detection layers: uses detections (evidence: `src/demo.c`)
- Detection demo → Image operations: renders results (evidence: `src/demo.c`)
- Python interface → Public API: wraps API
- Network runtime → CUDA support: GPU execution
