Darknet-Java v0.2
Java bindings for Darknet/YOLO
 
Loading...
Searching...
No Matches
Darknet.Darknet Class Reference

This class allows you to work with Darknet/YOLO neural networks. More...

Public Member Functions

 Darknet ()
 Constructor.
 
void fix_out_of_bound_values (boolean toggle) throws Throwable
 Fix out-of-bound values, meaning coordinates, widths, or heights that extend past the edges of images will be cropped or adjusted.
 
void free_image (MemorySegment image) throws Throwable
 Free an image that was loaded with Darknet.Darknet.load_image().
 
void free_neural_network () throws Throwable
 Free the Darknet/YOLO neural network loaded by Darknet.Darknet.load_neural_network().
 
MemorySegment load_image (String filename) throws Throwable
 Load the given image and convert it to a "DarknetImage" type.
 
MemorySegment load_neural_network (String config, String names, String weights) throws Throwable
 Load the Darknet/YOLO neural network.
 
Map< String, Integer > network_dimensions () throws Throwable
 Get the network dimensions.
 
void set_detection_threshold (float threshold) throws Throwable
 Set the detection threshold.
 
void set_gpu_index (int idx) throws Throwable
 Set the zero-based GPU index Darknet should use.
 
void set_non_maximal_suppression_threshold (float threshold) throws Throwable
 Set the NMS threshold.
 
void set_output_stream (String output_filename) throws Throwable
 Set the filename into which Darknet will write console output.
 
void set_trace (boolean flag) throws Throwable
 Toggle trace output.
 
void set_verbose (boolean flag) throws Throwable
 Toggle verbose output.
 
void show_version_info () throws Throwable
 Display version information on STDOUT.
 
void testing () throws Throwable
 
String version_short () throws Throwable
 Get the short version string.
 
String version_string () throws Throwable
 Get the full version string.
 

Detailed Description

This class allows you to work with Darknet/YOLO neural networks.

Since
2025-09-09

Constructor & Destructor Documentation

◆ Darknet()

Darknet.Darknet.Darknet ( )

Constructor.

See also
Darknet.Darknet.load_neural_network()
Since
2025-09-09

Member Function Documentation

◆ fix_out_of_bound_values()

void Darknet.Darknet.fix_out_of_bound_values ( boolean  toggle) throws Throwable

Fix out-of-bound values, meaning coordinates, widths, or heights that extend past the edges of images will be cropped or adjusted.

Default setting is true.

Since
2025-09-09

◆ free_image()

void Darknet.Darknet.free_image ( MemorySegment  image) throws Throwable

Free an image that was loaded with Darknet.Darknet.load_image().

Since
2025-09-09

◆ free_neural_network()

void Darknet.Darknet.free_neural_network ( ) throws Throwable

Free the Darknet/YOLO neural network loaded by Darknet.Darknet.load_neural_network().

It is safe to call this multiple times.

Note
Every neural network loaded with Darknet.Darknet.load_neural_network() must be freed with Darknet.Darknet.free_neural_network().
Since
2025-09-09

◆ load_image()

MemorySegment Darknet.Darknet.load_image ( String  filename) throws Throwable

Load the given image and convert it to a "DarknetImage" type.

Note
Remember to call Darknet.Darknet.free_image() when done with the image.
Since
2025-09-09

◆ load_neural_network()

MemorySegment Darknet.Darknet.load_neural_network ( String  config,
String  names,
String  weights 
) throws Throwable

Load the Darknet/YOLO neural network.

Many Darknet calls require this to have been called, since this sets the neural network pointer. Remember to call Darknet.Darknet.free_neural_network() when done.

Note
Every neural network loaded with Darknet.Darknet.load_neural_network() must be freed with Darknet.Darknet.free_neural_network().
Since
2025-09-09

◆ network_dimensions()

Map< String, Integer > Darknet.Darknet.network_dimensions ( ) throws Throwable

Get the network dimensions.

The map will contain 3 entries: width, height, and channel.

Since
2025-09-09

◆ set_detection_threshold()

void Darknet.Darknet.set_detection_threshold ( float  threshold) throws Throwable

Set the detection threshold.

Default threshold setting is 0.25.

Since
2025-09-09

◆ set_gpu_index()

void Darknet.Darknet.set_gpu_index ( int  idx) throws Throwable

Set the zero-based GPU index Darknet should use.

  • If you have a single GPU and Darknet/YOLO was built with support for your GPU, then the only valid value for the index will be 0 (zero) which is the default.
  • If you have multiple GPUs and Darknet/YOLO was built with support for your GPUs, then you may want to select a specific GPU to use. If unspecified, then Darknet/YOLO will default to GPU index #0 (zero), meaning the first GPU.
  • If Darknet/YOLO was built for CPU-only, then you should not call this API, or call it with -1.
Note
If called, this must be prior to Darknet.Darknet.load_neural_network().
Since
2025-09-09

◆ set_non_maximal_suppression_threshold()

void Darknet.Darknet.set_non_maximal_suppression_threshold ( float  threshold) throws Throwable

Set the NMS threshold.

Default NMS setting is 0.45.

Since
2025-09-09

◆ set_output_stream()

void Darknet.Darknet.set_output_stream ( String  output_filename) throws Throwable

Set the filename into which Darknet will write console output.

Default is STDOUT. This may be called prior to Darknet.Darknet.load_neural_network(). Use a blank filename ("") to reset it to the default STDOUT.

Since
2025-09-09

◆ set_trace()

void Darknet.Darknet.set_trace ( boolean  flag) throws Throwable

Toggle trace output.

This is only intended for debugging. Default trace setting is false. This may be called prior to Darknet.Darknet.load_neural_network().

Note
Turning on trace output will also turn on verbose. (You canot have trace without also having verbose.)
See also
Darknet.Darknet.set_verbose()
Darknet.Darknet.set_output_stream()
Since
2025-09-09

◆ set_verbose()

void Darknet.Darknet.set_verbose ( boolean  flag) throws Throwable

Toggle verbose output.

Default verbose setting is false. This may be called prior to Darknet.Darknet.load_neural_network().

Note
Turning off verbose output will also turn off trace (if it had been enabled).
See also
Darknet.Darknet.set_trace()
Darknet.Darknet.set_output_stream()
Since
2025-09-09

◆ show_version_info()

void Darknet.Darknet.show_version_info ( ) throws Throwable

Display version information on STDOUT.

This may be called prior to Darknet.Darknet.load_neural_network().

Example:

Darknet V5 "Moonlit" v5.0-138-ga061d2f0 [v5]
CUDA runtime version 12000 (v12.0), driver version 12060 (v12.6)
cuDNN version 12020 (v8.9.7), use of half-size floats is ENABLED
=> 0: NVIDIA GeForce RTX 3090 [#8.6], 23.6 GiB
Protobuf 3.21.12, OpenCV 4.6.0, Ubuntu 24.04
Definition Darknet.java:1
See also
Darknet.Darknet.version_string()
Darknet.Darknet.version_short()
Since
2025-09-09

◆ testing()

void Darknet.Darknet.testing ( ) throws Throwable

◆ version_short()

String Darknet.Darknet.version_short ( ) throws Throwable

Get the short version string.

For example, "5.0.138". This may be called prior to Darknet.Darknet.load_neural_network().

See also
Darknet.Darknet.version_string()
Since
2025-09-09

◆ version_string()

String Darknet.Darknet.version_string ( ) throws Throwable

Get the full version string.

For example, "v5.0-138-ga061d2f0". This may be called prior to Darknet.Darknet.load_neural_network().

See also
Darknet.Darknet.version_short()
Since
2025-09-09

The documentation for this class was generated from the following file: