Darknet
Darknet is a state-of-the-art object detector that uses the YOLO (You Only Look Once) framework. It is built on a singel-stage algorithm to achieve both speed and accuracy.
YOLOv7 is currently the most accurate and fastest model and has hardware acceleration support on both GPUs and CPUs.
If CUDA is available on your system, darknet
will run on your GPU.
darknet
component uses the official Darknet implementation when running on a GPU.
When running on a CPU, it uses OpenCV's implementation of Darknet.
YOLOv7 is the default model used by darknet
in all images.
Configuration
Configuration example
darknet:
object_detector:
cameras:
viseron_camera1:
fps: 1
scan_on_motion_only: true
log_all_objects: false
labels:
- label: dog
confidence: 0.7
trigger_recorder: false
- label: cat
confidence: 0.8
zones:
- name: zone1
coordinates:
- x: 0
y: 500
- x: 1920
y: 500
- x: 1920
y: 1080
- x: 0
y: 1080
labels:
- label: person
confidence: 0.8
trigger_recorder: true
mask:
- coordinates:
- x: 400
y: 200
- x: 1000
y: 200
- x: 1000
y: 750
- x: 400
y: 750
Object detector
An object detector scans an image to identify multiple objects and their position.
Object detectors can be taxing on the system, so it is wise to combine it with a motion detector
Labels
Labels are used to tell Viseron what objects to look for and keep recordings of. The available labels depends on what detection model you are using.
The max/min width/height is used to filter out any unreasonably large/small objects to reduce false positives.
Objects can also be filtered out with the use of an optional mask.
label_path
file.docker exec -it viseron cat /detectors/models/darknet/coco.names
Zones
Zones are used to define areas in the cameras field of view where you want to
look for certain objects (labels).
Say you have a camera facing the sidewalk and have labels
setup to
record the label person
.
This would cause Viseron to start recording people who are walking past the
camera on the sidewalk. Not ideal.
To remedy this you define a zone which covers only the area that you are
actually interested in, excluding the sidewalk.
darknet:
object_detector:
cameras:
camera_one:
...
zones:
- name: sidewalk
coordinates:
- x: 522
y: 11
- x: 729
y: 275
- x: 333
y: 603
- x: 171
y: 97
labels:
- label: person
confidence: 0.8
trigger_recorder: true
See Mask for how to get the coordinates for a zone.
Mask
Masks are used to exclude certain areas in the image from object detection. If a detected object has its lower portion inside of the mask it will be discarded.
The coordinates
form a polygon around the masked area.
To easily generate coordinates
you can use a tool like image-map.net.
Just upload an image from your camera, choose the Poly
shape and start drawing your mask.
Then click Show me the code! and adapt it to the config format.
Coordinates coords="522,11,729,275,333,603,171,97"
should be turned into this:
darknet:
object_detector:
cameras:
camera_one:
...
mask:
- coordinates:
- x: 522
y: 11
- x: 729
y: 275
- x: 333
y: 603
- x: 171
y: 97
Paste your coordinates here and press Get config
to generate a config example
Pre-trained models
The included models are placed inside the /detectors/models/darknet
folder.
Included models:
yolov3-tiny.weights
yolov3.weights
yolov4-tiny.weights
yolov4.weights
yolov7-tiny.weights
yolov7.weights
yolov7x.weights
This GitHub issue explains the models quite well.
To make an educated guess of what model to use, you can reference this image.
It will help you find the perfect trade-off between accuracy and latency.
The image roflcoopter/rpi3-viseron
only includes the yolov7-tiny.weights
model.
*-tiny.weights
model included in the image. The tiny-models can be used to reduce CPU and RAM usage. If you want to swap to a tiny-model you can change these configuration options:- YOLOv7
- YOLOv4
- YOLOv3
darknet:
object_detector:
model_path: /detectors/models/darknet/yolov7-tiny.weights
model_config: /detectors/models/darknet/yolov7-tiny.cfg
darknet:
object_detector:
model_path: /detectors/models/darknet/yolov4-tiny.weights
model_config: /detectors/models/darknet/yolov4-tiny.cfg
darknet:
object_detector:
model_path: /detectors/models/darknet/yolov3-tiny.weights
model_config: /detectors/models/darknet/yolov3-tiny.cfg
Hardware acceleration
Hardware accelerated object detection is supported on NVIDIA GPUs and Intel CPUs with integrated GPUs.
If you dont have a GPU available, darknet
will run on the CPU.
NVIDIA GPUs
If your system supports CUDA it is recommended to use the roflcoopter/amd64-cuda-viseron
image.
It will automatically use CUDA for object detection.
When running on CUDA, native Darknet is used.
If you want to force darknet
to run on OpenCL even if you have an NVIDIA GPU you can set these config options:
darknet:
object_detector:
dnn_backend: openvino
dnn_target: opencl
Intel CPUs with integrated GPUs
If you are running on an Intel CPU with integrated GPU, you can use the roflcoopter/amd64-viseron
image.
It will automatically use OpenCV with OpenVINO and OpenCL for object detection.
The dnn_backend
and dnn_target
controls how the model runs.
When not running on CUDA, OpenCVs implementation of Darknet is used.