darknet module

Python 3 wrapper for identifying objects in images

Requires DLL compilation

Both the GPU and no-GPU version should be compiled; the no-GPU version should be renamed “yolo_cpp_dll_nogpu.dll”.

On a GPU system, you can force CPU evaluation by any of:

  • Set global variable DARKNET_FORCE_CPU to True

  • Set environment variable CUDA_VISIBLE_DEVICES to -1

  • Set environment variable “FORCE_CPU” to “true”

  • Set environment variable “DARKNET_PATH” to path darknet lib .so (for Linux)

Directly viewing or returning bounding-boxed images requires scikit-image to be installed (pip install scikit-image)

Original *nix 2.7: https://github.com/pjreddie/darknet/blob/0f110834f4e18b30d5f101bf8f1724c34b7b83db/python/darknet.py Windows Python 2.7 version: https://github.com/AlexeyAB/darknet/blob/fc496d52bf22a0bb257300d3c79be9cd80e722cb/build/darknet/x64/darknet.py

@author: Philip Kahn @date: 20180503

class darknet.BOX[source]

Bases: _ctypes.Structure

h

Structure/Union member

w

Structure/Union member

x

Structure/Union member

y

Structure/Union member

class darknet.DETECTION[source]

Bases: _ctypes.Structure

bbox

Structure/Union member

classes

Structure/Union member

embedding_size

Structure/Union member

embeddings

Structure/Union member

mask

Structure/Union member

objectness

Structure/Union member

points

Structure/Union member

prob

Structure/Union member

sim

Structure/Union member

sort_class

Structure/Union member

track_id

Structure/Union member

uc

Structure/Union member

class darknet.DETNUMPAIR[source]

Bases: _ctypes.Structure

dets

Structure/Union member

num

Structure/Union member

class darknet.IMAGE[source]

Bases: _ctypes.Structure

c

Structure/Union member

data

Structure/Union member

h

Structure/Union member

w

Structure/Union member

class darknet.METADATA[source]

Bases: _ctypes.Structure

classes

Structure/Union member

names

Structure/Union member

darknet.bbox2points(bbox)[source]

From bounding box yolo format to corner points cv2 rectangle

darknet.class_colors(names)[source]

Create a dict with one random BGR color for each class name

darknet.decode_detection(detections)[source]
darknet.detect_image(network, class_names, image, thresh=0.5, hier_thresh=0.5, nms=0.45)[source]

Returns a list with highest confidence class and their bbox

darknet.draw_boxes(detections, image, colors)[source]
darknet.load_network(config_file, data_file, weights, batch_size=1)[source]

load model description and weights from config files args:

config_file (str): path to .cfg model file data_file (str): path to .data model file weights (str): path to weights

returns:

network: trained model class_names class_colors

darknet.network_height(net)[source]
darknet.network_width(net)[source]
darknet.print_detections(detections, coordinates=False)[source]
darknet.remove_negatives(detections, class_names, num)[source]

Remove all classes with 0% confidence within the detection