The namespace for the C++ Darknet API. More...
Classes | |
class | ArgsAndParms |
class | CfgAndState |
class | CfgFile |
A class that represents a Darknet/YOLO configuration file. More... | |
class | CfgLine |
Each non-empty line in a .cfg file is stored as a Darknet::CfgLine object. More... | |
class | CfgSection |
A class that represents a specific section in a configuration file. More... | |
class | Keypoints |
The Keypoints class works with Darknet's V3 API. More... | |
struct | Layer |
struct | Network |
Neural network structure. Contains all of the layers. Created by Darknet::CfgFile::create_network(). More... | |
struct | NetworkDetails |
A place to store other details related to the neural network which we cannot easily add to the usual Darknet::Network structure. More... | |
struct | NetworkState |
struct | Output_Object |
This is used to help keep some state between calls to functions fill_network_boxes(), get_yolo_detections(), etc. More... | |
struct | Parm |
Structure returned by Darknet::parse_arguments(). More... | |
struct | Prediction |
A much-simplified version of the old API structure DarknetDetection. More... | |
class | TimingAndTracking |
The timing and tracking functionality is used to find places in the code where optimizations should be made. More... | |
class | TimingRecords |
An object of this type is statically instantiated in Timing.cpp. More... | |
struct | Tree |
Typedefs | |
using | CfgLines = std::map< std::string, CfgLine > |
Lines are not stored in the order in which they are read. | |
using | CfgSections = std::vector< CfgSection > |
using | MArgsAndParms = std::map< std::string, ArgsAndParms > |
The key is the argument name, the value is the details for that argument. | |
using | Output_Object_Cache = std::list< Output_Object > |
using | Parms = std::vector< Parm > |
Structure returned by Darknet::parse_arguments(). | |
using | Predictions = std::vector< Prediction > |
Each image or video frame may contain many predictions. | |
using | Probabilities = std::map< int, float > |
The likelyhood of a specific object class having been predicted. | |
using | SArgsAndParms = std::set< ArgsAndParms > |
using | Skeleton = VInt |
using | Skeletons = std::vector< Skeleton > |
using | VThreads = std::vector< std::thread > |
using | MStr = std::map< std::string, std::string > |
Convenient simple types used in the Darknet/YOLO C++ API. | |
using | MStrInt = std::map< std::string, int > |
Convenient simple types used in the Darknet/YOLO C++ API. | |
using | SStr = std::set< std::string > |
Convenient simple types used in the Darknet/YOLO C++ API. | |
using | SInt = std::set< int > |
Convenient simple types used in the Darknet/YOLO C++ API. | |
using | VFloat = std::vector< float > |
Convenient simple types used in the Darknet/YOLO C++ API. | |
using | VInt = std::vector< int > |
Convenient simple types used in the Darknet/YOLO C++ API. | |
using | VStr = std::vector< std::string > |
Convenient simple types used in the Darknet/YOLO C++ API. | |
using | VScalars = std::vector< cv::Scalar > |
Convenient simple types used in the Darknet/YOLO C++ API. | |
using | NetworkPtr = DarknetNetworkPtr |
Convenient simple types used in the Darknet/YOLO C++ API. | |
using | Box = DarknetBox |
Convenient simple types used in the Darknet/YOLO C++ API. | |
using | Detection = DarknetDetection |
Convenient simple types used in the Darknet/YOLO C++ API. | |
using | Image = DarknetImage |
Convenient simple types used in the Darknet/YOLO C++ API. | |
Enumerations | |
enum class | EActivation { LOGISTIC = ACTIVATION::LOGISTIC , RELU = ACTIVATION::RELU , RELU6 = ACTIVATION::RELU6 , RELIE = ACTIVATION::RELIE , LINEAR = ACTIVATION::LINEAR , RAMP = ACTIVATION::RAMP , TANH = ACTIVATION::TANH , PLSE = ACTIVATION::PLSE , REVLEAKY = ACTIVATION::REVLEAKY , LEAKY = ACTIVATION::LEAKY , ELU = ACTIVATION::ELU , LOGGY = ACTIVATION::LOGGY , STAIR = ACTIVATION::STAIR , HARDTAN = ACTIVATION::HARDTAN , LHTAN = ACTIVATION::LHTAN , SELU = ACTIVATION::SELU , GELU = ACTIVATION::GELU , SWISH = ACTIVATION::SWISH , MISH = ACTIVATION::MISH , HARD_MISH = ACTIVATION::HARD_MISH , NORM_CHAN = ACTIVATION::NORM_CHAN , NORM_CHAN_SOFTMAX = ACTIVATION::NORM_CHAN_SOFTMAX , NORM_CHAN_SOFTMAX_MAXVAL = ACTIVATION::NORM_CHAN_SOFTMAX_MAXVAL } |
The plan is to eventually remove ACTIVATION completely once we fully switch over to C++. More... | |
enum | EColour { kNormal = 0 , kBlack , kRed , kGreen , kBrown , kBlue , kMagenta , kCyan , kLightGrey , kDarkGrey , kBrightRed , kBrightGreen , kYellow , kBrightBlue , kBrightMagenta , kBrightCyan , kBrightWhite } |
enum class | ECostType { SSE = COST_TYPE::SSE , MASKED = COST_TYPE::MASKED , SMOOTH = COST_TYPE::SMOOTH } |
The plan is to eventually remove COST_TYPE completely once we fully switch over to C++. More... | |
enum class | EIoULoss { IOU = IOU_LOSS::IOU , GIOU = IOU_LOSS::GIOU , MSE = IOU_LOSS::MSE , DIOU = IOU_LOSS::DIOU , CIOU = IOU_LOSS::CIOU } |
The plan is to eventually remove IOU_LOSS completely once we fully switch over to C++. More... | |
enum class | ELayerType { CONVOLUTIONAL , CONNECTED , MAXPOOL , LOCAL_AVGPOOL , SOFTMAX , DROPOUT , ROUTE , COST , AVGPOOL , SHORTCUT , SCALE_CHANNELS , SAM , RNN , LSTM , CRNN , NETWORK , REGION , YOLO , GAUSSIAN_YOLO , REORG , UPSAMPLE , EMPTY , BLANK , CONTRASTIVE , LAYER_LAST_IDX = ELayerType::CONTRASTIVE } |
This is the new C++ version of what used to be called LAYER_TYPE in the old C code. More... | |
enum class | ELearningRatePolicy { CONSTANT = learning_rate_policy::CONSTANT , STEP = learning_rate_policy::STEP , EXP = learning_rate_policy::EXP , POLY = learning_rate_policy::POLY , STEPS = learning_rate_policy::STEPS , SIG = learning_rate_policy::SIG , RANDOM = learning_rate_policy::RANDOM , SGDR = learning_rate_policy::SGDR } |
The plan is to eventually remove learning_rate_policy completely once we fully switch over to C++. More... | |
enum class | ENMSKind { DEFAULT_NMS = NMS_KIND::DEFAULT_NMS , GREEDY_NMS = NMS_KIND::GREEDY_NMS , DIOU_NMS = NMS_KIND::DIOU_NMS , CORNERS_NMS = NMS_KIND::CORNERS_NMS } |
The plan is to eventually remove NMS_KIND completely once we fully switch over to C++. More... | |
enum class | EParmType { kUnknown , kCfgFilename , kNamesFilename , kWeightsFilename , kDirectory , kFilename , kOther } |
When parsing command-line parameters, each parameter is assigned a "type". More... | |
enum class | EWeightsNormalization { NO_NORMALIZATION = WEIGHTS_NORMALIZATION_T::NO_NORMALIZATION , RELU_NORMALIZATION = WEIGHTS_NORMALIZATION_T::RELU_NORMALIZATION , SOFTMAX_NORMALIZATION = WEIGHTS_NORMALIZATION_T::SOFTMAX_NORMALIZATION } |
The plan is to eventually remove WEIGHTS_NORMALIZATION_T completely once we fully switch over to C++. More... | |
enum class | EWeightsType { NO_WEIGHTS = WEIGHTS_TYPE_T::NO_WEIGHTS , PER_FEATURE = WEIGHTS_TYPE_T::PER_FEATURE , PER_CHANNEL = WEIGHTS_TYPE_T::PER_CHANNEL } |
The plan is to eventually remove WEIGHTS_TYPE_T completely once we fully switch over to C++. More... | |
enum class | EYoloPoint { YOLO_CENTER = YOLO_POINT::YOLO_CENTER , YOLO_LEFT_TOP = YOLO_POINT::YOLO_LEFT_TOP , YOLO_RIGHT_BOTTOM = YOLO_POINT::YOLO_RIGHT_BOTTOM } |
The plan is to eventually remove YOLO_POINT completely once we fully switch over to C++. More... | |
Functions | |
SInt | add_skipped_class (Darknet::NetworkPtr ptr, const int class_to_skip) |
Add the given class index to the set of classes that Darknet must ignore. | |
cv::Mat | annotate (const Darknet::NetworkPtr ptr, const Predictions &predictions, cv::Mat mat) |
Annotate the given image using the predictions from Darknet::predict(). | |
void | assign_default_class_colours (Darknet::Network *net) |
Generate the necessary class colours used to draw bounding boxes and labels. | |
int | best_3d_shift (const Darknet::Image &a, const Darknet::Image &b, int min, int max) |
int | best_3d_shift_r (const Darknet::Image &a, const Darknet::Image &b, int min, int max) |
Darknet::Image | bgr_mat_to_rgb_image (const cv::Mat &mat) |
Similar to the original mat_to_image(), but with 2 differences: | |
float | bilinear_interpolate (const Darknet::Image &im, float x, float y, int c) |
Darknet::Image | blend_image (const Darknet::Image &fore, const Darknet::Image &back, float alpha) |
void | cfg_layers () |
SInt | clear_skipped_classes (Darknet::NetworkPtr ptr) |
Clear the set of classes which Darknet must ignore. | |
Darknet::Image | collapse_image_layers (const Darknet::Image &source, int border) |
Darknet::Image | collapse_images_horz (const Darknet::Image *ims, int n) |
Darknet::Image | collapse_images_vert (const Darknet::Image *ims, int n) |
void | composite_3d (char *f1, char *f2, const char *out, int delta) |
void | composite_image (const Darknet::Image &source, Darknet::Image &dest, int dx, int dy) |
void | constrain_image (Darknet::Image &im) |
std::string | convert_to_lowercase_alphanum (const std::string &arg) |
Convert to lowercase and remove all but alphanumerics. | |
Darknet::Image | copy_image (const Darknet::Image &p) |
void | copy_image_inplace (const Darknet::Image &src, Darknet::Image &dst) |
Darknet::Image | crop_image (const Darknet::Image &im, const int dx, const int dy, const int w, const int h) |
Crop the given image. | |
SInt | del_skipped_class (Darknet::NetworkPtr ptr, const int class_to_include) |
Remove the given class index from the set of classes that Darknet must ignore. | |
char * | detection_to_json (Darknet::Detection *dets, int nboxes, int classes, const Darknet::VStr &names, long long int frame_id, char *filename) |
void | display_error_msg (const std::string &msg) |
Display the given message in bright red (if colour is enabled). The message is not linefeed terminated. | |
void | display_usage () |
void | display_warning_msg (const std::string &msg) |
Display the given message in yellow (if colour is enabled). The message is not linefeed terminated. | |
void | distort_image (Darknet::Image &im, float hue, float sat, float val) |
void | draw_bbox (Darknet::Image &a, const Darknet::Box &bbox, int w, float r, float g, float b) |
Draw the given bounding box. The line thickness can be specified using w . | |
void | draw_box (Darknet::Image &a, int x1, int y1, int x2, int y2, float r, float g, float b) |
Draw a bounding box at the rectangle coordinates within an image, using the specified colour. | |
void | draw_box_bw (Darknet::Image &a, int x1, int y1, int x2, int y2, float brightness) |
Draw a bounding box on a black-and-white image. | |
void | draw_box_width (Darknet::Image &a, int x1, int y1, int x2, int y2, int w, float r, float g, float b) |
Similiar to Darknet::draw_box(), but the line thickness can be specified using w . | |
void | draw_box_width_bw (Darknet::Image &a, int x1, int y1, int x2, int y2, int w, float brightness) |
Similar to Darknet::draw_box_bw(), but the line thickness can be specified using w . | |
void | draw_detections_v3 (Darknet::Image &im, const Darknet::Detection *dets, const int num, const float thresh, const Darknet::VStr &names, const int classes, const int ext_output) |
This is the function that is called from older Darknet code to draw annotations on an image. | |
void | draw_weighted_label (Darknet::Image &a, int r, int c, Darknet::Image &label, const float *rgb, const float alpha) |
Blend the label (actually an image) into the given image. | |
void | embed_image (const Darknet::Image &source, Darknet::Image &dest, int dx, int dy) |
void | fill_image (Darknet::Image &m, float s) |
void | fix_out_of_bound_values (Darknet::NetworkPtr ptr, const bool toggle) |
Fix out-of-bound values returned by Darknet::predict() for objects near the edges of images. | |
void | flip_image (Darknet::Image &a) |
Flip image left <-> right. | |
Darknet::Image | float_to_image (int w, int h, int c, float *data) |
Darknet::Image | float_to_image_scaled (int w, int h, int c, float *data) |
std::string | format_in_colour (const float &f, const EColour &colour, const size_t &len) |
std::string | format_in_colour (const float &f, const size_t &len, const bool inverted=false) |
std::string | format_in_colour (const int &i, const EColour &colour, const size_t &len) |
std::string | format_in_colour (const size_t &st, const EColour &colour, const size_t &len) |
std::string | format_in_colour (const std::string &str, const EColour &colour, const int &len) |
std::string | format_layer_summary (const size_t idx, const Darknet::CfgSection §ion, const Darknet::Layer &l) |
std::string | format_loss (const double &loss) |
Format the loss combined with ANSI colours. | |
std::string | format_map_accuracy (const float &accuracy) |
Format the mAP% accuracy with ANSI colours. | |
std::string | format_map_confusion_matrix_values (const int class_id, std::string name, const float &average_precision, const int &tp, const int &fn, const int &fp, const int &tn, const float &accuracy, const float &error_rate, const float &precision, const float &recall, const float &specificity, const float &false_pos_rate) |
std::string | format_time (const double &seconds_remaining) |
The time used by Darknet is a double, generated from what_time_is_it_now(). | |
std::string | format_time_remaining (const float &seconds_remaining) |
Format the time remaining using simple-to-read text. The time must be in seconds. | |
void | free_data (data &d) |
Frees the "data buffer" used to load images. | |
void | free_image (Darknet::Image &im) |
Free the image. | |
void | free_neural_network (Darknet::NetworkPtr &ptr) |
Free the neural network pointer allocated in Darknet::load_neural_network(). | |
const SArgsAndParms & | get_all_possible_arguments () |
Get all the possible arguments used by Darknet. | |
const Darknet::VScalars & | get_class_colours (const Darknet::NetworkPtr ptr) |
Get access to the vector of colours assigned to each class when the .names file was loaded. | |
const Darknet::VStr & | get_class_names (const Darknet::NetworkPtr ptr) |
Get access to the vector of names read from the .names file when the configuration was loaded. | |
float | get_color (int c, int x, int max) |
Generate some "random" colour value to use. Mostly used for labels and charts. | |
std::string | get_command_output (const std::string &cmd) |
std::filesystem::path | get_config_filename (const Darknet::NetworkPtr ptr) |
Get the filename of the configuration file that was used to load this neural network. | |
float | get_hierarchy_probability (float *x, Tree *hier, int c) |
Darknet::Image | get_image_layer (const Darknet::Image &m, int l) |
Return a specific channel (eg: R, G, B) from an image. | |
std::filesystem::path | get_names_filename (const Darknet::NetworkPtr ptr) |
Get the filename of the names file that was used to load this neural network. | |
std::filesystem::path | get_weights_filename (const Darknet::NetworkPtr ptr) |
Get the filename of the weights file that was used to load this neural network. | |
Darknet::Image | grayscale_image (const Darknet::Image &im) |
void | hierarchy_predictions (float *predictions, int n, Tree *hier, int only_leaves) |
int | hierarchy_top_prediction (float *predictions, Tree *hier, float thresh, int stride) |
void | hsv_to_rgb (Darknet::Image &im) |
std::string | image_as_debug_string (const Darknet::Image &m) |
Convert the image to a debug string to display the data pointer values. | |
Darknet::Image | image_distance (Darknet::Image &a, Darknet::Image &b) |
Create a single-channel image for ...? | |
void | image_loading_loop (const int idx, load_args args) |
Run the permanent thread image loading loop. | |
cv::Mat | image_to_mat (const Darknet::Image &img) |
Convert the usual Darknet::Image format to OpenCV cv::Mat . | |
std::string | in_colour (const EColour colour) |
std::string | in_colour (const EColour colour, const double d) |
std::string | in_colour (const EColour colour, const float f) |
std::string | in_colour (const EColour colour, const int i) |
std::string | in_colour (const EColour colour, const std::string &msg) |
void | initialize_new_charts (const Darknet::Network &net) |
Setup the new C++ charts. This is called once just prior to starting training. | |
float | iou (const cv::Rect &lhs, const cv::Rect &rhs) |
Calculate intersection-over-union given 2 OpenCV rectangles. | |
Darknet::Image | letterbox_image (const Darknet::Image &im, int w, int h) |
void | letterbox_image_into (const Darknet::Image &im, int w, int h, Darknet::Image &boxed) |
Darknet::Image | load_image (const char *filename, int desired_width=0, int desired_height=0, int channels=0) |
Load the given image. | |
void | load_names (Darknet::NetworkPtr net, const std::filesystem::path &filename) |
Load all of the names from a text .names file. | |
Darknet::NetworkPtr | load_neural_network (const std::filesystem::path &cfg_filename, const std::filesystem::path &names_filename, const std::filesystem::path &weights_filename) |
Load a neural network (.cfg) and the corresponding weights file. | |
Darknet::NetworkPtr | load_neural_network (Darknet::Parms &parms) |
Load a neural network. | |
void | load_single_image_data (load_args args) |
Load the given image data as described by the load_args parameter. | |
Darknet::Image | make_attention_image (int img_size, float *original_delta_cpu, float *original_input_cpu, int w, int h, int c, float alpha) |
The resulting image takes ownership of original_delta_cpu . | |
void | make_image_red (Darknet::Image &im) |
Darknet::Image | make_random_image (int w, int h, int c) |
Darknet::Image | mat_to_image (const cv::Mat &mat) |
Convert an OpenCV cv::Mat object to Darknet::Image. | |
void | network_dimensions (Darknet::NetworkPtr &ptr, int &w, int &h, int &c) |
Get the network dimensions (width, height, channels). | |
void | normalize_image (Darknet::Image &p) |
void | normalize_image2 (Darknet::Image &p) |
std::ostream & | operator<< (std::ostream &os, const Darknet::Prediction &pred) |
Display some information about this specific prediction. | |
std::ostream & | operator<< (std::ostream &os, const Darknet::Predictions &preds) |
Display some information about all the predictions. | |
Darknet::Parms | parse_arguments (const Darknet::VStr &v) |
Similar to the other Darknet::parse_arguments(), but uses a vector of strings as input. | |
Darknet::Parms | parse_arguments (int argc, char *argv[]) |
Parse common Darknet command-line parameters with the values from argc and argv in main() . | |
Predictions | predict (const Darknet::NetworkPtr ptr, const cv::Mat &mat) |
Get Darknet to look at the given image or video frame and return all predictions. | |
Predictions | predict (const Darknet::NetworkPtr ptr, const std::filesystem::path &image_filename) |
Get Darknet to look at the given image and return all predictions. | |
Predictions | predict (const Darknet::NetworkPtr ptr, Darknet::Image &img, cv::Size original_image_size=cv::Size(0, 0)) |
Get Darknet to look at the given image or video frame and return all predictions. | |
Predictions | predict_and_annotate (const Darknet::NetworkPtr ptr, cv::Mat mat) |
Combination of Darknet::predict() and Darknet::annotate(). | |
void | quantize_image (Darknet::Image &im) |
Darknet::Image | random_augment_image (const Darknet::Image &im, const float angle, float aspect, const int low, const int high, const int size) |
Apply a bunch of random augmentations. | |
Darknet::Image | random_crop_image (const Darknet::Image &im, const int w, const int h) |
Similar to Darknet::crop_image() but the dx and dy are random values. | |
void | random_distort_image (Darknet::Image &im, float hue, float saturation, float exposure) |
Tree * | read_tree (const char *filename) |
Darknet::Image | resize_image (const Darknet::Image &im, int w, int h) |
cv::Mat | resize_keeping_aspect_ratio (cv::Mat &mat, cv::Size desired_size, const cv::InterpolationFlags method=cv::InterpolationFlags::INTER_NEAREST) |
Resize the image as close as we can to the given size, but keep the aspect ratio the same as the original image. | |
Darknet::Image | resize_max (const Darknet::Image &im, int max) |
Darknet::Image | resize_min (const Darknet::Image &im, int min) |
cv::Mat | rgb_image_to_bgr_mat (const Darknet::Image &img) |
Similar to the original image_to_mat(), but with 2 differences: | |
void | rgb_to_hsv (Darknet::Image &im) |
void | rgbgr_image (Darknet::Image &im) |
Do the equivalent of OpenCV's cv::COLOR_BGR2RGB to swap red and blue floats. | |
Darknet::Image | rotate_crop_image (const Darknet::Image &im, float rad, float s, int w, int h, float dx, float dy, float aspect) |
Darknet::Image | rotate_image (const Darknet::Image &im, float rad) |
Rotate image. | |
void | rotate_image_cw (Darknet::Image &im, int times) |
Rotate image clockwise? | |
void | run_image_loading_control_thread (load_args args) |
This runs as a std::thread . | |
void | save_image (const Darknet::Image &p, const char *name) |
void | save_image_jpg (const Darknet::Image &im, const char *name) |
void | save_image_png (const Darknet::Image &im, const char *name) |
void | scale_image (Darknet::Image &m, const float s) |
Scale the RGB values in an image by the given amount. | |
void | scale_image_channel (Darknet::Image &im, int c, float v) |
void | set_annotation_draw_bb (Darknet::NetworkPtr ptr, const bool toggle) |
Determines if bounding boxes are drawn when calling either Darknet::annotate() or Darknet::predict_and_annotate(). | |
void | set_annotation_draw_label (Darknet::NetworkPtr ptr, const bool toggle) |
Determines if text labels are drawn above the bounding boxes when calling either Darknet::annotate() or Darknet::predict_and_annotate(). | |
void | set_annotation_font (Darknet::NetworkPtr ptr, const cv::LineTypes line_type, const cv::HersheyFonts font_face, const int font_thickness, const double font_scale) |
Set the font characteristics to use when drawing the bounding boxes and labels in either Darknet::annotate() or Darknet::predict_and_annotate(). | |
void | set_annotation_line_type (Darknet::NetworkPtr ptr, const cv::LineTypes line_type) |
The OpenCV line type can impact performance. | |
const Darknet::VScalars & | set_class_colours (Darknet::NetworkPtr ptr, const Darknet::VScalars &colours) |
Set the colours to use when drawing annotations. | |
void | set_default_keypoints_files (Darknet::Parms &parms) |
Add the default Darknet Keypoints neural network files to the given parms . | |
void | set_detection_threshold (Darknet::NetworkPtr ptr, float threshold) |
Detection threshold to use when Darknet::predict() is called. | |
void | set_gpu_index (int idx) |
Set the GPU index to use. | |
void | set_non_maximal_suppression_threshold (Darknet::NetworkPtr ptr, float threshold) |
Non-maximal suppression threshold to use when Darknet::predict() is called. | |
void | set_rounded_corner_bounding_boxes (Darknet::NetworkPtr ptr, const bool toggle, const float roundness) |
This determines if annotations are drawn as circles or rounded rectangles in either Darknet::annotate() or Darknet::predict_and_annotate(). | |
void | set_trace (const bool flag) |
Set the Darknet::CfgAndState::is_trace flag. | |
void | set_verbose (const bool flag) |
Set the Darknet::CfgAndState::is_verbose flag. | |
void | show_image (const Darknet::Image &p, const char *name) |
void | show_image_collapsed (const Darknet::Image &p, const char *name) |
void | show_image_layers (const Darknet::Image &p, const char *name) |
void | show_images (Darknet::Image *ims, int n, const char *window) |
void | show_version_info () |
Display a few lines of text with some version information. | |
SInt | skipped_classes (const Darknet::NetworkPtr ptr) |
Return the set of classes which Darknet must ignore. | |
SInt | skipped_classes (Darknet::NetworkPtr ptr, const SInt &classes_to_skip) |
Set the classes which Darknet must ignore, completely over-writing all previous values. | |
void | stop_image_loading_threads () |
Stop and join the image loading threads started in Darknet::run_image_loading_control_thread(). | |
void | test_resize (char *filename) |
std::string | text_to_simple_label (std::string txt) |
Convert the given text to plain alphanumeric ASCII string. | |
Darknet::Image | threshold_image (const Darknet::Image &im, float thresh) |
void | translate_image (Darknet::Image m, float s) |
void | update_accuracy_in_new_charts (const int class_index, const float accuracy) |
void | update_loss_in_new_charts (const int current_iteration, const float loss, const float seconds_remaining, const bool dont_show) |
Update the new C++ charts with the given loss and mAP% accuracy value. This is called at every iteration. | |
std::string | trim (const std::string &str) |
Trim leading and trailing whitespace from the given string. | |
std::string & | trim (std::string &str) |
Trim leading and trailing whitespace from the given string. | |
std::string | lowercase (const std::string &str) |
Simple conversion of the string to lowercase. | |
std::string & | lowercase (std::string &str) |
Simple conversion of the string to lowercase. | |
void | dump (Darknet::Network *net, const Darknet::CfgFile::CommonParms &parms) |
Dump some information on the given network and layers to a text file for debugging. | |
void | dump (Darknet::CfgFile &cfg) |
Dump some information on the given network and layers to a text file for debugging. | |
using | NamesAndLayers = std::map< std::string, ELayerType > |
Convert between names and Darknet/YOLO layer types. | |
const NamesAndLayers & | all_names_and_layers () |
Convert between names and Darknet/YOLO layer types. | |
ELayerType | get_layer_type_from_name (const std::string &name) |
Convert between names and Darknet/YOLO layer types. | |
std::string | to_string (const ELayerType type) |
Convert between names and Darknet/YOLO layer types. | |
using | NamesAndActivationTypes = std::map< std::string, EActivation > |
Convert between names and activation types. | |
const NamesAndActivationTypes & | all_names_and_activations () |
Convert between names and activation types. | |
EActivation | get_activation_from_name (const std::string &name) |
Convert between names and activation types. | |
std::string | to_string (const EActivation activation) |
Convert between names and activation types. | |
using | NamesAndLearningRatePolicies = std::map< std::string, ELearningRatePolicy > |
Convert between names and learning rate policies. | |
const NamesAndLearningRatePolicies & | all_names_and_learning_rate_policies () |
Convert between names and learning rate policies. | |
ELearningRatePolicy | get_learning_rate_policy_from_name (const std::string &name) |
Convert between names and learning rate policies. | |
std::string | to_string (const ELearningRatePolicy policy) |
Convert between names and learning rate policies. | |
using | NamesAndIoULoss = std::map< std::string, EIoULoss > |
Convert between names and IoU loss types. | |
const NamesAndIoULoss & | all_names_and_IoU_loss () |
Convert between names and IoU loss types. | |
EIoULoss | get_IoU_loss_from_name (const std::string &name) |
Convert between names and IoU loss types. | |
std::string | to_string (const EIoULoss loss) |
Convert between names and IoU loss types. | |
using | NamesAndNMSKind = std::map< std::string, ENMSKind > |
Convert between names and NMS kind. | |
const NamesAndNMSKind & | all_names_and_NMS_kind () |
Convert between names and NMS kind. | |
ENMSKind | get_NMS_kind_from_name (const std::string &name) |
Convert between names and NMS kind. | |
std::string | to_string (const ENMSKind nms_kind) |
Convert between names and NMS kind. | |
using | NamesAndWeightsType = std::map< std::string, EWeightsType > |
Convert between names and weights types. | |
const NamesAndWeightsType & | all_names_and_weights_types () |
Convert between names and weights types. | |
EWeightsType | get_weights_type_from_name (const std::string &name) |
Convert between names and weights types. | |
std::string | to_string (const EWeightsType type) |
Convert between names and weights types. | |
using | NamesAndWeightsNormalization = std::map< std::string, EWeightsNormalization > |
Convert between names and weights normalization. | |
const NamesAndWeightsNormalization & | all_names_and_weights_normalization () |
Convert between names and weights normalization. | |
EWeightsNormalization | get_weights_normalization_from_name (const std::string &name) |
Convert between names and weights normalization. | |
std::string | to_string (const EWeightsNormalization normalization) |
Convert between names and weights normalization. | |
using | NamesAndCostTypes = std::map< std::string, ECostType > |
Convert between names and cost types. | |
const NamesAndCostTypes & | all_names_and_cost_types () |
Convert between names and cost types. | |
ECostType | get_cost_types_from_name (const std::string &name) |
Convert between names and cost types. | |
std::string | to_string (const ECostType type) |
Convert between names and cost types. | |
using | NamesAndYoloPointTypes = std::map< std::string, EYoloPoint > |
Convert between names and YOLO point types. | |
const NamesAndYoloPointTypes & | all_names_and_yolo_point_types () |
Convert between names and YOLO point types. | |
EYoloPoint | get_yolo_point_types_from_name (const std::string &name) |
Convert between names and YOLO point types. | |
std::string | to_string (const EYoloPoint type) |
Convert between names and YOLO point types. | |
The namespace for the C++ Darknet API.
Note this namespace contains both public and private API calls. The structures, enums, classes and functions declared in darknet.hpp are part of the public API.
using Darknet::Box = typedef DarknetBox |
Convenient simple types used in the Darknet/YOLO C++ API.
using Darknet::CfgLines = typedef std::map<std::string, CfgLine> |
Lines are not stored in the order in which they are read.
Instead, they are stored as a map which allows us to quickly look up a value based on the key. There should be no duplicate keys within a section, nor should the order matter.
using Darknet::CfgSections = typedef std::vector<CfgSection> |
using Darknet::Detection = typedef DarknetDetection |
Convenient simple types used in the Darknet/YOLO C++ API.
using Darknet::Image = typedef DarknetImage |
Convenient simple types used in the Darknet/YOLO C++ API.
using Darknet::MArgsAndParms = typedef std::map<std::string, ArgsAndParms> |
The key is the argument name, the value is the details for that argument.
using Darknet::MStr = typedef std::map<std::string, std::string> |
Convenient simple types used in the Darknet/YOLO C++ API.
using Darknet::MStrInt = typedef std::map<std::string, int> |
Convenient simple types used in the Darknet/YOLO C++ API.
using Darknet::NamesAndActivationTypes = typedef std::map<std::string, EActivation> |
Convert between names and activation types.
using Darknet::NamesAndCostTypes = typedef std::map<std::string, ECostType> |
Convert between names and cost types.
using Darknet::NamesAndIoULoss = typedef std::map<std::string, EIoULoss> |
Convert between names and IoU loss types.
using Darknet::NamesAndLayers = typedef std::map<std::string, ELayerType> |
Convert between names and Darknet/YOLO layer types.
using Darknet::NamesAndLearningRatePolicies = typedef std::map<std::string, ELearningRatePolicy> |
Convert between names and learning rate policies.
using Darknet::NamesAndNMSKind = typedef std::map<std::string, ENMSKind> |
Convert between names and NMS kind.
using Darknet::NamesAndWeightsNormalization = typedef std::map<std::string, EWeightsNormalization> |
Convert between names and weights normalization.
using Darknet::NamesAndWeightsType = typedef std::map<std::string, EWeightsType> |
Convert between names and weights types.
using Darknet::NamesAndYoloPointTypes = typedef std::map<std::string, EYoloPoint> |
Convert between names and YOLO point types.
using Darknet::NetworkPtr = typedef DarknetNetworkPtr |
Convenient simple types used in the Darknet/YOLO C++ API.
using Darknet::Output_Object_Cache = typedef std::list<Output_Object> |
using Darknet::Parms = typedef std::vector<Parm> |
Structure returned by Darknet::parse_arguments().
using Darknet::Predictions = typedef std::vector<Prediction> |
Each image or video frame may contain many predictions.
These predictions are stored in a vector in no particular order.
using Darknet::Probabilities = typedef std::map<int, float> |
The likelyhood of a specific object class having been predicted.
This map contains all of the non-zero values. The key is the zero-based class indexes, and the values are the confidences for the classes, between 0.0f
and 1.0f
.
For example, if "car" is class #2 and "truck" is class #3, and Darknet is 95% certain it found a car and 82% certain it found a truck, the map would then contain "{ {2, 0.95}, {3, 0.82} }"
.
using Darknet::SArgsAndParms = typedef std::set<ArgsAndParms> |
using Darknet::SInt = typedef std::set<int> |
Convenient simple types used in the Darknet/YOLO C++ API.
using Darknet::Skeleton = typedef VInt |
using Darknet::Skeletons = typedef std::vector<Skeleton> |
using Darknet::SStr = typedef std::set<std::string> |
Convenient simple types used in the Darknet/YOLO C++ API.
using Darknet::VFloat = typedef std::vector<float> |
Convenient simple types used in the Darknet/YOLO C++ API.
using Darknet::VInt = typedef std::vector<int> |
Convenient simple types used in the Darknet/YOLO C++ API.
using Darknet::VScalars = typedef std::vector<cv::Scalar> |
Convenient simple types used in the Darknet/YOLO C++ API.
using Darknet::VStr = typedef std::vector<std::string> |
Convenient simple types used in the Darknet/YOLO C++ API.
using Darknet::VThreads = typedef std::vector<std::thread> |
|
strong |
The plan is to eventually remove ACTIVATION completely once we fully switch over to C++.
Enumerator | |
---|---|
LOGISTIC | |
RELU | |
RELU6 | |
RELIE | |
LINEAR | |
RAMP | |
TANH | |
PLSE | |
REVLEAKY | |
LEAKY | |
ELU | |
LOGGY | |
STAIR | |
HARDTAN | |
LHTAN | |
SELU | |
GELU | |
SWISH | |
MISH | |
HARD_MISH | |
NORM_CHAN | |
NORM_CHAN_SOFTMAX | |
NORM_CHAN_SOFTMAX_MAXVAL |
enum Darknet::EColour |
|
strong |
The plan is to eventually remove COST_TYPE completely once we fully switch over to C++.
Enumerator | |
---|---|
SSE | |
MASKED | |
SMOOTH |
|
strong |
The plan is to eventually remove IOU_LOSS completely once we fully switch over to C++.
Enumerator | |
---|---|
IOU | |
GIOU | |
MSE | |
DIOU | |
CIOU |
|
strong |
This is the new C++ version of what used to be called LAYER_TYPE
in the old C
code.
|
strong |
The plan is to eventually remove learning_rate_policy completely once we fully switch over to C++.
Enumerator | |
---|---|
CONSTANT | |
STEP | |
EXP | |
POLY | |
STEPS | |
SIG | |
RANDOM | |
SGDR |
|
strong |
The plan is to eventually remove NMS_KIND completely once we fully switch over to C++.
Enumerator | |
---|---|
DEFAULT_NMS | |
GREEDY_NMS | |
DIOU_NMS | |
CORNERS_NMS |
|
strong |
When parsing command-line parameters, each parameter is assigned a "type".
|
strong |
The plan is to eventually remove WEIGHTS_NORMALIZATION_T completely once we fully switch over to C++.
Enumerator | |
---|---|
NO_NORMALIZATION | |
RELU_NORMALIZATION | |
SOFTMAX_NORMALIZATION |
|
strong |
The plan is to eventually remove WEIGHTS_TYPE_T completely once we fully switch over to C++.
Enumerator | |
---|---|
NO_WEIGHTS | |
PER_FEATURE | |
PER_CHANNEL |
|
strong |
The plan is to eventually remove YOLO_POINT completely once we fully switch over to C++.
Enumerator | |
---|---|
YOLO_CENTER | |
YOLO_LEFT_TOP | |
YOLO_RIGHT_BOTTOM |
Darknet::SInt Darknet::add_skipped_class | ( | Darknet::NetworkPtr | ptr, |
const int | class_to_skip | ||
) |
Add the given class index to the set of classes that Darknet must ignore.
This may be called multiple times if you have many classes you want skipped, or you can call skipped_classes() if you want to set them all at once.
const Darknet::NamesAndActivationTypes & Darknet::all_names_and_activations | ( | ) |
Convert between names and activation types.
const Darknet::NamesAndCostTypes & Darknet::all_names_and_cost_types | ( | ) |
Convert between names and cost types.
const Darknet::NamesAndIoULoss & Darknet::all_names_and_IoU_loss | ( | ) |
Convert between names and IoU loss types.
const Darknet::NamesAndLayers & Darknet::all_names_and_layers | ( | ) |
Convert between names and Darknet/YOLO layer types.
const Darknet::NamesAndLearningRatePolicies & Darknet::all_names_and_learning_rate_policies | ( | ) |
Convert between names and learning rate policies.
const Darknet::NamesAndNMSKind & Darknet::all_names_and_NMS_kind | ( | ) |
Convert between names and NMS kind.
const Darknet::NamesAndWeightsNormalization & Darknet::all_names_and_weights_normalization | ( | ) |
Convert between names and weights normalization.
const Darknet::NamesAndWeightsType & Darknet::all_names_and_weights_types | ( | ) |
Convert between names and weights types.
const Darknet::NamesAndYoloPointTypes & Darknet::all_names_and_yolo_point_types | ( | ) |
Convert between names and YOLO point types.
cv::Mat Darknet::annotate | ( | const Darknet::NetworkPtr | ptr, |
const Predictions & | predictions, | ||
cv::Mat | mat | ||
) |
Annotate the given image using the predictions from Darknet::predict().
void Darknet::assign_default_class_colours | ( | Darknet::Network * | net | ) |
Generate the necessary class colours used to draw bounding boxes and labels.
The colours are stored in Darknet::NetworkDetails at the time the network is loaded, once the total number of classes are known.
This is called automatically when the network is initialized via Darknet::CfgFile. There is no need to manually call this function.
int Darknet::best_3d_shift | ( | const Darknet::Image & | a, |
const Darknet::Image & | b, | ||
int | min, | ||
int | max | ||
) |
int Darknet::best_3d_shift_r | ( | const Darknet::Image & | a, |
const Darknet::Image & | b, | ||
int | min, | ||
int | max | ||
) |
Darknet::Image Darknet::bgr_mat_to_rgb_image | ( | const cv::Mat & | mat | ) |
Similar to the original mat_to_image(), but with 2 differences:
cv::Mat
to Darknet::Image
which makes it much faster.Remember to call Darknet::free_image() when done.
float Darknet::bilinear_interpolate | ( | const Darknet::Image & | im, |
float | x, | ||
float | y, | ||
int | c | ||
) |
Darknet::Image Darknet::blend_image | ( | const Darknet::Image & | fore, |
const Darknet::Image & | back, | ||
float | alpha | ||
) |
void Darknet::cfg_layers | ( | ) |
Darknet::SInt Darknet::clear_skipped_classes | ( | Darknet::NetworkPtr | ptr | ) |
Clear the set of classes which Darknet must ignore.
The default is for Darknet/YOLO to not skip any classes, as if this function has been called.
Darknet::Image Darknet::collapse_image_layers | ( | const Darknet::Image & | source, |
int | border | ||
) |
Darknet::Image Darknet::collapse_images_horz | ( | const Darknet::Image * | ims, |
int | n | ||
) |
Darknet::Image Darknet::collapse_images_vert | ( | const Darknet::Image * | ims, |
int | n | ||
) |
void Darknet::composite_3d | ( | char * | f1, |
char * | f2, | ||
const char * | out, | ||
int | delta | ||
) |
void Darknet::composite_image | ( | const Darknet::Image & | source, |
Darknet::Image & | dest, | ||
int | dx, | ||
int | dy | ||
) |
void Darknet::constrain_image | ( | Darknet::Image & | im | ) |
std::string Darknet::convert_to_lowercase_alphanum | ( | const std::string & | arg | ) |
Convert to lowercase and remove all but alphanumerics.
Darknet::Image Darknet::copy_image | ( | const Darknet::Image & | p | ) |
void Darknet::copy_image_inplace | ( | const Darknet::Image & | src, |
Darknet::Image & | dst | ||
) |
Darknet::Image Darknet::crop_image | ( | const Darknet::Image & | im, |
const int | dx, | ||
const int | dy, | ||
const int | w, | ||
const int | h | ||
) |
Crop the given image.
Darknet::SInt Darknet::del_skipped_class | ( | Darknet::NetworkPtr | ptr, |
const int | class_to_include | ||
) |
Remove the given class index from the set of classes that Darknet must ignore.
This may be called multiple times if there are several class indexes you'll like to restore.
char * Darknet::detection_to_json | ( | Darknet::Detection * | dets, |
int | nboxes, | ||
int | classes, | ||
const Darknet::VStr & | names, | ||
long long int | frame_id, | ||
char * | filename | ||
) |
void Darknet::display_error_msg | ( | const std::string & | msg | ) |
Display the given message in bright red (if colour is enabled). The message is not linefeed terminated.
void Darknet::display_usage | ( | ) |
void Darknet::display_warning_msg | ( | const std::string & | msg | ) |
Display the given message in yellow (if colour is enabled). The message is not linefeed terminated.
void Darknet::distort_image | ( | Darknet::Image & | im, |
float | hue, | ||
float | sat, | ||
float | val | ||
) |
void Darknet::draw_bbox | ( | Darknet::Image & | a, |
const Darknet::Box & | bbox, | ||
int | w, | ||
float | r, | ||
float | g, | ||
float | b | ||
) |
Draw the given bounding box. The line thickness can be specified using w
.
void Darknet::draw_box | ( | Darknet::Image & | a, |
int | x1, | ||
int | y1, | ||
int | x2, | ||
int | y2, | ||
float | r, | ||
float | g, | ||
float | b | ||
) |
Draw a bounding box at the rectangle coordinates within an image, using the specified colour.
void Darknet::draw_box_bw | ( | Darknet::Image & | a, |
int | x1, | ||
int | y1, | ||
int | x2, | ||
int | y2, | ||
float | brightness | ||
) |
Draw a bounding box on a black-and-white image.
void Darknet::draw_box_width | ( | Darknet::Image & | a, |
int | x1, | ||
int | y1, | ||
int | x2, | ||
int | y2, | ||
int | w, | ||
float | r, | ||
float | g, | ||
float | b | ||
) |
Similiar to Darknet::draw_box(), but the line thickness can be specified using w
.
void Darknet::draw_box_width_bw | ( | Darknet::Image & | a, |
int | x1, | ||
int | y1, | ||
int | x2, | ||
int | y2, | ||
int | w, | ||
float | brightness | ||
) |
Similar to Darknet::draw_box_bw(), but the line thickness can be specified using w
.
void Darknet::draw_detections_v3 | ( | Darknet::Image & | im, |
const Darknet::Detection * | dets, | ||
const int | num, | ||
const float | thresh, | ||
const Darknet::VStr & | names, | ||
const int | classes, | ||
const int | ext_output | ||
) |
void Darknet::draw_weighted_label | ( | Darknet::Image & | a, |
int | r, | ||
int | c, | ||
Darknet::Image & | label, | ||
const float * | rgb, | ||
const float | alpha | ||
) |
Blend the label (actually an image) into the given image.
void Darknet::dump | ( | Darknet::CfgFile & | cfg | ) |
Dump some information on the given network and layers to a text file for debugging.
void Darknet::dump | ( | Darknet::Network * | net, |
const Darknet::CfgFile::CommonParms & | parms | ||
) |
Dump some information on the given network and layers to a text file for debugging.
void Darknet::embed_image | ( | const Darknet::Image & | source, |
Darknet::Image & | dest, | ||
int | dx, | ||
int | dy | ||
) |
void Darknet::fill_image | ( | Darknet::Image & | m, |
float | s | ||
) |
void Darknet::fix_out_of_bound_values | ( | Darknet::NetworkPtr | ptr, |
const bool | toggle | ||
) |
Fix out-of-bound values returned by Darknet::predict() for objects near the edges of images.
When set to true
, this will ensure that normalized coordinates are between 0.0
and 1.0
, and do not extend beyond the borders of the image or video frame.
Default is true
.
void Darknet::flip_image | ( | Darknet::Image & | a | ) |
Flip image left <-> right.
Darknet::Image Darknet::float_to_image | ( | int | w, |
int | h, | ||
int | c, | ||
float * | data | ||
) |
Darknet::Image Darknet::float_to_image_scaled | ( | int | w, |
int | h, | ||
int | c, | ||
float * | data | ||
) |
std::string Darknet::format_in_colour | ( | const float & | f, |
const EColour & | colour, | ||
const size_t & | len | ||
) |
std::string Darknet::format_in_colour | ( | const float & | f, |
const size_t & | len, | ||
const bool | inverted = false |
||
) |
std::string Darknet::format_in_colour | ( | const int & | i, |
const EColour & | colour, | ||
const size_t & | len | ||
) |
std::string Darknet::format_in_colour | ( | const size_t & | st, |
const EColour & | colour, | ||
const size_t & | len | ||
) |
std::string Darknet::format_in_colour | ( | const std::string & | str, |
const EColour & | colour, | ||
const int & | len | ||
) |
std::string Darknet::format_layer_summary | ( | const size_t | idx, |
const Darknet::CfgSection & | section, | ||
const Darknet::Layer & | l | ||
) |
std::string Darknet::format_loss | ( | const double & | loss | ) |
Format the loss combined with ANSI colours.
std::string Darknet::format_map_accuracy | ( | const float & | accuracy | ) |
Format the mAP% accuracy with ANSI colours.
std::string Darknet::format_map_confusion_matrix_values | ( | const int | class_id, |
std::string | name, | ||
const float & | average_precision, | ||
const int & | tp, | ||
const int & | fn, | ||
const int & | fp, | ||
const int & | tn, | ||
const float & | accuracy, | ||
const float & | error_rate, | ||
const float & | precision, | ||
const float & | recall, | ||
const float & | specificity, | ||
const float & | false_pos_rate | ||
) |
std::string Darknet::format_time | ( | const double & | seconds_remaining | ) |
The time used by Darknet is a double, generated from what_time_is_it_now().
It is the number of seconds since epoch
with milliseconds and microseconds as decimals. This function will format one of these double
using the most intelligent unit necessary.
std::string Darknet::format_time_remaining | ( | const float & | seconds_remaining | ) |
Format the time remaining using simple-to-read text. The time must be in seconds.
void Darknet::free_data | ( | data & | d | ) |
Frees the "data buffer" used to load images.
void Darknet::free_image | ( | Darknet::Image & | im | ) |
Free the image.
Unlike the C
version free_image(), the image object is passed by reference, so the pointer to the data will be reset to nullptr
once the memory has been freed. When possible, prefer calling Darknet::free_image()
.
All images must call either free_image() or Darknet::free_image() to avoid memory leaks.
void Darknet::free_neural_network | ( | Darknet::NetworkPtr & | ptr | ) |
Free the neural network pointer allocated in Darknet::load_neural_network().
Does nothing if the pointer has already been freed. Will reset the pointer to nullptr
once the structure has been freed.
You should call this once you are done with Darknet to avoid memory leaks in your application.
Darknet::EActivation Darknet::get_activation_from_name | ( | const std::string & | name | ) |
Convert between names and activation types.
const Darknet::SArgsAndParms & Darknet::get_all_possible_arguments | ( | ) |
const Darknet::VScalars & Darknet::get_class_colours | ( | const Darknet::NetworkPtr | ptr | ) |
Get access to the vector of colours assigned to each class when the .names file was loaded.
const Darknet::VStr & Darknet::get_class_names | ( | const Darknet::NetworkPtr | ptr | ) |
Get access to the vector of names read from the .names file when the configuration was loaded.
float Darknet::get_color | ( | int | c, |
int | x, | ||
int | max | ||
) |
Generate some "random" colour value to use. Mostly used for labels and charts.
std::string Darknet::get_command_output | ( | const std::string & | cmd | ) |
std::filesystem::path Darknet::get_config_filename | ( | const Darknet::NetworkPtr | ptr | ) |
Get the filename of the configuration file that was used to load this neural network.
Darknet::ECostType Darknet::get_cost_types_from_name | ( | const std::string & | name | ) |
Convert between names and cost types.
float Darknet::get_hierarchy_probability | ( | float * | x, |
Darknet::Tree * | hier, | ||
int | c | ||
) |
Darknet::Image Darknet::get_image_layer | ( | const Darknet::Image & | m, |
int | l | ||
) |
Return a specific channel (eg: R, G, B) from an image.
Darknet::EIoULoss Darknet::get_IoU_loss_from_name | ( | const std::string & | name | ) |
Convert between names and IoU loss types.
Darknet::ELayerType Darknet::get_layer_type_from_name | ( | const std::string & | name | ) |
Convert between names and Darknet/YOLO layer types.
Darknet::ELearningRatePolicy Darknet::get_learning_rate_policy_from_name | ( | const std::string & | name | ) |
Convert between names and learning rate policies.
std::filesystem::path Darknet::get_names_filename | ( | const Darknet::NetworkPtr | ptr | ) |
Get the filename of the names file that was used to load this neural network.
Darknet::ENMSKind Darknet::get_NMS_kind_from_name | ( | const std::string & | name | ) |
Convert between names and NMS kind.
std::filesystem::path Darknet::get_weights_filename | ( | const Darknet::NetworkPtr | ptr | ) |
Get the filename of the weights file that was used to load this neural network.
Darknet::EWeightsNormalization Darknet::get_weights_normalization_from_name | ( | const std::string & | name | ) |
Convert between names and weights normalization.
Darknet::EWeightsType Darknet::get_weights_type_from_name | ( | const std::string & | name | ) |
Convert between names and weights types.
Darknet::EYoloPoint Darknet::get_yolo_point_types_from_name | ( | const std::string & | name | ) |
Convert between names and YOLO point types.
Darknet::Image Darknet::grayscale_image | ( | const Darknet::Image & | im | ) |
void Darknet::hierarchy_predictions | ( | float * | predictions, |
int | n, | ||
Darknet::Tree * | hier, | ||
int | only_leaves | ||
) |
int Darknet::hierarchy_top_prediction | ( | float * | predictions, |
Darknet::Tree * | hier, | ||
float | thresh, | ||
int | stride | ||
) |
void Darknet::hsv_to_rgb | ( | Darknet::Image & | im | ) |
std::string Darknet::image_as_debug_string | ( | const Darknet::Image & | m | ) |
Convert the image to a debug string to display the data
pointer values.
For example, a tiny 5x3 image might look like this:
Darknet::Image Darknet::image_distance | ( | Darknet::Image & | a, |
Darknet::Image & | b | ||
) |
Create a single-channel image for ...?
void Darknet::image_loading_loop | ( | const int | idx, |
load_args | args | ||
) |
Run the permanent thread image loading loop.
This is started by Darknet::run_image_loading_control_thread(), and is stopped by Darknet::stop_image_loading_threads().
This was originally called run_thread_loop()
and used pthread
, but has since been re-written to use C++11.
cv::Mat Darknet::image_to_mat | ( | const Darknet::Image & | img | ) |
Convert the usual Darknet::Image format to OpenCV cv::Mat
.
The mat object will be in RGB
format, not BGR
.
cv::COLOR_RGB2BGR
std::string Darknet::in_colour | ( | const EColour | colour | ) |
std::string Darknet::in_colour | ( | const EColour | colour, |
const double | d | ||
) |
std::string Darknet::in_colour | ( | const EColour | colour, |
const float | f | ||
) |
std::string Darknet::in_colour | ( | const EColour | colour, |
const int | i | ||
) |
std::string Darknet::in_colour | ( | const EColour | colour, |
const std::string & | msg | ||
) |
void Darknet::initialize_new_charts | ( | const Darknet::Network & | net | ) |
Setup the new C++ charts. This is called once just prior to starting training.
float Darknet::iou | ( | const cv::Rect & | lhs, |
const cv::Rect & | rhs | ||
) |
Calculate intersection-over-union given 2 OpenCV rectangles.
Will return a value between 0.0f
and 1.0f
.
Darknet::Image Darknet::letterbox_image | ( | const Darknet::Image & | im, |
int | w, | ||
int | h | ||
) |
void Darknet::letterbox_image_into | ( | const Darknet::Image & | im, |
int | w, | ||
int | h, | ||
Darknet::Image & | boxed | ||
) |
Darknet::Image Darknet::load_image | ( | const char * | filename, |
int | desired_width = 0 , |
||
int | desired_height = 0 , |
||
int | channels = 0 |
||
) |
Load the given image.
If both desired_width
and desired_height
have been set, then the image will be resized to match those dimensions. Otherwise, specify 0
(zero) to leave the image dimensions unchanged.
Unless single channel greyscale has been requested, the image returned will be in RGB format, not BGR.
void Darknet::load_names | ( | Darknet::NetworkPtr | net, |
const std::filesystem::path & | filename | ||
) |
Load all of the names from a text .names file.
The file must exist, and must have the same number of classes as the network.
This will automatically be called if you use Darknet::load_neural_network() from the new recommended V3 API.
You may need to manually call it if you use the old load_network() or load_network_custom() from the original C
API. If you don't call it, some default placeholders will be used instead, such as "#0"
, "#1"
, etc.
Darknet::NetworkPtr Darknet::load_neural_network | ( | const std::filesystem::path & | cfg_filename, |
const std::filesystem::path & | names_filename, | ||
const std::filesystem::path & | weights_filename | ||
) |
Load a neural network (.cfg) and the corresponding weights file.
Remember to call Darknet::free_neural_network() once the neural network is no longer needed.
Darknet::NetworkPtr Darknet::load_neural_network | ( | Darknet::Parms & | parms | ) |
Load a neural network.
Remember to call Darknet::free_neural_network() once the neural network is no longer needed.
void Darknet::load_single_image_data | ( | load_args | args | ) |
Load the given image data as described by the load_args
parameter.
This is typically used to load images on a secondary thread, such as image_loading_loop().
args.n
argument is used to describe the number of images that will be loaded together. This will typically be the batch size divided by the number of worker threads (default is 6 threads).This was originally called load_thread()
.
std::string Darknet::lowercase | ( | const std::string & | str | ) |
Simple conversion of the string to lowercase.
std::string & Darknet::lowercase | ( | std::string & | str | ) |
Simple conversion of the string to lowercase.
Darknet::Image Darknet::make_attention_image | ( | int | img_size, |
float * | original_delta_cpu, | ||
float * | original_input_cpu, | ||
int | w, | ||
int | h, | ||
int | c, | ||
float | alpha | ||
) |
The resulting image takes ownership of original_delta_cpu
.
void Darknet::make_image_red | ( | Darknet::Image & | im | ) |
Darknet::Image Darknet::make_random_image | ( | int | w, |
int | h, | ||
int | c | ||
) |
Darknet::Image Darknet::mat_to_image | ( | const cv::Mat & | mat | ) |
Convert an OpenCV cv::Mat
object to Darknet::Image.
The cv::Mat
is expected to already have been converted from BGR
to RGB
. The result Darknet::Image floats will be normalized between 0.0
and 1.0
. Remember to call Darknet::free_image() when done.
cv::COLOR_BGR2RGB
void Darknet::network_dimensions | ( | Darknet::NetworkPtr & | ptr, |
int & | w, | ||
int & | h, | ||
int & | c | ||
) |
Get the network dimensions (width, height, channels).
void Darknet::normalize_image | ( | Darknet::Image & | p | ) |
void Darknet::normalize_image2 | ( | Darknet::Image & | p | ) |
std::ostream & Darknet::operator<< | ( | std::ostream & | os, |
const Darknet::Prediction & | pred | ||
) |
Display some information about this specific prediction.
Use like this:
std::ostream & Darknet::operator<< | ( | std::ostream & | os, |
const Darknet::Predictions & | preds | ||
) |
Display some information about all the predictions.
Use like this:
Output would look similar to this:
Darknet::Parms Darknet::parse_arguments | ( | const Darknet::VStr & | v | ) |
Similar to the other Darknet::parse_arguments(), but uses a vector of strings as input.
Output can be used with Darknet::load_neural_network().
Darknet::Parms Darknet::parse_arguments | ( | int | argc, |
char * | argv[] | ||
) |
Parse common Darknet command-line parameters with the values from argc
and argv
in main()
.
Output can be used with Darknet::load_neural_network().
This function will attempt to identify the following:
.cfg files (Darknet configuration)
.names files (Darknet classes)
.weights files (Darknet weights)If the .names or
.weights files were not found, then attempts will be made to locate a suitable file to use based on the given
.cfg file. This means as long as the 3 Darknet files are named in a similar way, there is no need to specify all 3 files. The
.cfg file is enough to find the neural network.
In addition, if no Darknet files were found but a "stem" was specified, then this stem will be used to attempt and find all the necessary files. For example, if the following files exist:
animals.cfg
animals.names
animals_best.weights
These files will be found if this function is called with the parameter "anim"
, since all the files begin with that stem.
Given the example files listed above, the following commands are interpreted the exact same way:
Darknet::Predictions Darknet::predict | ( | const Darknet::NetworkPtr | ptr, |
const cv::Mat & | mat | ||
) |
Get Darknet to look at the given image or video frame and return all predictions.
This is similar to the other Darknet::predict() that takes a Darknet::Image
object as input.
OpenCV cv::Mat
images (and video frames) are typically stored in BGR format, not RGB. This function expects the images to be in the usual BGR format for 3-channel networks.
Darknet::Predictions Darknet::predict | ( | const Darknet::NetworkPtr | ptr, |
const std::filesystem::path & | image_filename | ||
) |
Get Darknet to look at the given image and return all predictions.
The image must be in a format supported by OpenCV, such as JPG
or PNG
.
Darknet::Predictions Darknet::predict | ( | const Darknet::NetworkPtr | ptr, |
Darknet::Image & | img, | ||
cv::Size | original_image_size = cv::Size(0, 0) |
||
) |
Get Darknet to look at the given image or video frame and return all predictions.
The provided image must be in Darknet's RGB image format. This is similar to the other predict() that takes a cv::Mat
object as input.
todo pass net by ref or pointer, not copy constructor!
Darknet::Predictions Darknet::predict_and_annotate | ( | const Darknet::NetworkPtr | ptr, |
cv::Mat | mat | ||
) |
Combination of Darknet::predict() and Darknet::annotate().
Remember to clone mat
prior to calling predict_and_annotate()
if you need to keep a copy of the original image.
void Darknet::quantize_image | ( | Darknet::Image & | im | ) |
Darknet::Image Darknet::random_augment_image | ( | const Darknet::Image & | im, |
const float | angle, | ||
float | aspect, | ||
const int | low, | ||
const int | high, | ||
const int | size | ||
) |
Apply a bunch of random augmentations.
Darknet::Image Darknet::random_crop_image | ( | const Darknet::Image & | im, |
const int | w, | ||
const int | h | ||
) |
Similar to Darknet::crop_image() but the dx
and dy
are random values.
void Darknet::random_distort_image | ( | Darknet::Image & | im, |
float | hue, | ||
float | saturation, | ||
float | exposure | ||
) |
Darknet::Tree * Darknet::read_tree | ( | const char * | filename | ) |
Darknet::Image Darknet::resize_image | ( | const Darknet::Image & | im, |
int | w, | ||
int | h | ||
) |
cv::Mat Darknet::resize_keeping_aspect_ratio | ( | cv::Mat & | mat, |
cv::Size | desired_size, | ||
const cv::InterpolationFlags | method = cv::InterpolationFlags::INTER_NEAREST |
||
) |
Resize the image as close as we can to the given size, but keep the aspect ratio the same as the original image.
This method will modify the image that is passed in, so clone it beforehand if you need a copy of the original.
Several notes in regards to the resize method:
cv::InterpolationFlags::INTER_NEAREST
is the fastest resize method, but the quality is poor. cv::InterpolationFlags::INTER_AREA
is good when shrinking an image. cv::InterpolationFlags::INTER_CUBIC
is good when growing an image cv::InterpolationFlags::INTER_LINEAR
is similar to INTER_CUBIC, but fasterDarknet::Image Darknet::resize_max | ( | const Darknet::Image & | im, |
int | max | ||
) |
Darknet::Image Darknet::resize_min | ( | const Darknet::Image & | im, |
int | min | ||
) |
cv::Mat Darknet::rgb_image_to_bgr_mat | ( | const Darknet::Image & | img | ) |
Similar to the original image_to_mat(), but with 2 differences:
Darknet::Image
to cv::Mat
which makes it much faster.void Darknet::rgb_to_hsv | ( | Darknet::Image & | im | ) |
void Darknet::rgbgr_image | ( | Darknet::Image & | im | ) |
Do the equivalent of OpenCV's cv::COLOR_BGR2RGB
to swap red and blue floats.
Darknet::Image Darknet::rotate_crop_image | ( | const Darknet::Image & | im, |
float | rad, | ||
float | s, | ||
int | w, | ||
int | h, | ||
float | dx, | ||
float | dy, | ||
float | aspect | ||
) |
Darknet::Image Darknet::rotate_image | ( | const Darknet::Image & | im, |
float | rad | ||
) |
Rotate image.
void Darknet::rotate_image_cw | ( | Darknet::Image & | im, |
int | times | ||
) |
Rotate image clockwise?
void Darknet::run_image_loading_control_thread | ( | load_args | args | ) |
This runs as a std::thread
.
It is started by the main thread during training and ensures the data-loading threads are running. This starts the thread that controls all of the permanent image loading threads.
This was originally called load_threads()
and used pthread
, but has since been re-written to use C++11.
void Darknet::save_image | ( | const Darknet::Image & | p, |
const char * | name | ||
) |
void Darknet::save_image_jpg | ( | const Darknet::Image & | im, |
const char * | name | ||
) |
void Darknet::save_image_png | ( | const Darknet::Image & | im, |
const char * | name | ||
) |
void Darknet::scale_image | ( | Darknet::Image & | m, |
const float | s | ||
) |
Scale the RGB values in an image by the given amount.
void Darknet::scale_image_channel | ( | Darknet::Image & | im, |
int | c, | ||
float | v | ||
) |
void Darknet::set_annotation_draw_bb | ( | Darknet::NetworkPtr | ptr, |
const bool | toggle | ||
) |
Determines if bounding boxes are drawn when calling either Darknet::annotate() or Darknet::predict_and_annotate().
The default is true
.
void Darknet::set_annotation_draw_label | ( | Darknet::NetworkPtr | ptr, |
const bool | toggle | ||
) |
Determines if text labels are drawn above the bounding boxes when calling either Darknet::annotate() or Darknet::predict_and_annotate().
The default is true
.
void Darknet::set_annotation_font | ( | Darknet::NetworkPtr | ptr, |
const cv::LineTypes | line_type, | ||
const cv::HersheyFonts | font_face, | ||
const int | font_thickness, | ||
const double | font_scale | ||
) |
Set the font characteristics to use when drawing the bounding boxes and labels in either Darknet::annotate() or Darknet::predict_and_annotate().
[in] | ptr | Neural network pointer obtained from Darknet::load_neural_network(). |
[in] | line_type | should be cv::LineTypes::LINE_4 , cv::LineTypes::LINE_8 , or cv::LineTypes::CV_LINE_AA . LINE_4 is the fastest but lower quality, while LINE_AA (anti-alias) is the slowest with highest quality. Default is LINE_4 . Also see set_annotation_line_type() which modifies the same setting. |
[in] | font_face | is the OpenCV built-in font to use. Default is cv::HersheyFonts::FONT_HERSHEY_PLAIN . |
[in] | font_thickness | determines how thick the lines are drawn when the text is rendered. Default is 1 . |
[in] | font_scale | determines how large or small the text is rendered. For example, this could be set to 0.5 for extremely small text, and 1.75 for large text. Default is 1.0 . |
void Darknet::set_annotation_line_type | ( | Darknet::NetworkPtr | ptr, |
const cv::LineTypes | line_type | ||
) |
The OpenCV line type can impact performance.
Anti-aliased lines are expensive to draw. Possible options for line_type
is cv::LineTypes::LINE_4
, cv::LineTypes::LINE_8
, or cv::LineTypes::CV_LINE_AA
. LINE_4
is the fastest but lower quality, while LINE_AA
(anti-alias) is the slowest with highest quality. Default is LINE_4
.
This setting can also be modified with set_annotation_font().
const Darknet::VScalars & Darknet::set_class_colours | ( | Darknet::NetworkPtr | ptr, |
const Darknet::VScalars & | colours | ||
) |
Set the colours to use when drawing annotations.
The colours are in OpenCV's usual BGR format, not RGB. So pure red for example is "{0, 0, 255}"
while pure blue would be "{255, 0, 0}"
. The middle value is green.
void Darknet::set_default_keypoints_files | ( | Darknet::Parms & | parms | ) |
Add the default Darknet Keypoints neural network files to the given parms
.
If parms
doesn't seem to reference neural network files, then this function will automatically add the names "Darknet-Keypoints.cfg"
and "Darknet-Keypoints.weights"
.
void Darknet::set_detection_threshold | ( | Darknet::NetworkPtr | ptr, |
float | threshold | ||
) |
Detection threshold to use when Darknet::predict() is called.
Default is 0.25
.
void Darknet::set_gpu_index | ( | int | idx | ) |
Set the GPU index to use.
This may be set to -1
to indicate no GPU has been selected, or may be set to a 0-based GPU. In normal situations, this must be set prior to calling Darknet::load_neural_network() where the GPU is usually initialized.
If set to -1
and Darknet was compiled with support for CUDA GPUs, then the GPU index will default to 0
when Darknet::load_neural_network() is called. If no CUDA GPU is detected, then the GPU index will be set to -1
and the CPU will be used instead.
Default is -1
.
void Darknet::set_non_maximal_suppression_threshold | ( | Darknet::NetworkPtr | ptr, |
float | threshold | ||
) |
Non-maximal suppression threshold to use when Darknet::predict() is called.
Default is 0.45
.
void Darknet::set_rounded_corner_bounding_boxes | ( | Darknet::NetworkPtr | ptr, |
const bool | toggle, | ||
const float | roundness | ||
) |
This determines if annotations are drawn as circles or rounded rectangles in either Darknet::annotate() or Darknet::predict_and_annotate().
The defaul is to use square – not rounded – bounding boxes.
[in] | ptr | Neural network pointer obtained from Darknet::load_neural_network(). |
[in] | toggle | Determines if rounded corners are used. The default is false in which case normal "square" bounding boxes are used. |
[in] | roundness | Determines how large the rounded corners will appear. The value must be between 0.0 (small rounded corners) and 1.0 (large rounded corners). At the extreme of 1.0 , the bounding box will appear as a circle. The default is 0.5 , but will only take effect if rounded is also set to true . |
void Darknet::set_trace | ( | const bool | flag | ) |
Set the Darknet::CfgAndState::is_trace flag.
When enabled, debug information will be sent to STDOUT
. Default value is false
.
trace
will also enable verbose
.void Darknet::set_verbose | ( | const bool | flag | ) |
Set the Darknet::CfgAndState::is_verbose flag.
When enabled, extra information will be sent to STDOUT
. Default value is false
.
verbose
will also disable trace
.void Darknet::show_image | ( | const Darknet::Image & | p, |
const char * | name | ||
) |
void Darknet::show_image_collapsed | ( | const Darknet::Image & | p, |
const char * | name | ||
) |
void Darknet::show_image_layers | ( | const Darknet::Image & | p, |
const char * | name | ||
) |
void Darknet::show_images | ( | Darknet::Image * | ims, |
int | n, | ||
const char * | window | ||
) |
void Darknet::show_version_info | ( | ) |
Display a few lines of text with some version information.
Darknet::SInt Darknet::skipped_classes | ( | const Darknet::NetworkPtr | ptr | ) |
Return the set of classes which Darknet must ignore.
Default set is empty.
Darknet::SInt Darknet::skipped_classes | ( | Darknet::NetworkPtr | ptr, |
const SInt & | classes_to_skip | ||
) |
Set the classes which Darknet must ignore, completely over-writing all previous values.
If you'd rather add a single class at a time, call add_skipped_class() which can be called repeatedly without overwriting previous settings.
void Darknet::stop_image_loading_threads | ( | ) |
Stop and join the image loading threads started in Darknet::run_image_loading_control_thread().
This was originally called free_load_threads()
and used pthread
, but has since been re-written to use C++11.
void Darknet::test_resize | ( | char * | filename | ) |
std::string Darknet::text_to_simple_label | ( | std::string | txt | ) |
Convert the given text to plain alphanumeric ASCII string.
Remove whitespace, keep just alphanumeric and underscore. Good to use as a base for a filename.
Darknet::Image Darknet::threshold_image | ( | const Darknet::Image & | im, |
float | thresh | ||
) |
std::string Darknet::to_string | ( | const EActivation | activation | ) |
Convert between names and activation types.
std::string Darknet::to_string | ( | const ECostType | type | ) |
Convert between names and cost types.
std::string Darknet::to_string | ( | const EIoULoss | loss | ) |
Convert between names and IoU loss types.
std::string Darknet::to_string | ( | const ELayerType | type | ) |
Convert between names and Darknet/YOLO layer types.
std::string Darknet::to_string | ( | const ELearningRatePolicy | policy | ) |
Convert between names and learning rate policies.
std::string Darknet::to_string | ( | const ENMSKind | nms_kind | ) |
Convert between names and NMS kind.
std::string Darknet::to_string | ( | const EWeightsNormalization | normalization | ) |
Convert between names and weights normalization.
std::string Darknet::to_string | ( | const EWeightsType | type | ) |
Convert between names and weights types.
std::string Darknet::to_string | ( | const EYoloPoint | type | ) |
Convert between names and YOLO point types.
void Darknet::translate_image | ( | Darknet::Image | m, |
float | s | ||
) |
std::string Darknet::trim | ( | const std::string & | str | ) |
Trim leading and trailing whitespace from the given string.
std::string & Darknet::trim | ( | std::string & | str | ) |
Trim leading and trailing whitespace from the given string.
void Darknet::update_accuracy_in_new_charts | ( | const int | class_index, |
const float | accuracy | ||
) |
void Darknet::update_loss_in_new_charts | ( | const int | current_iteration, |
const float | loss, | ||
const float | seconds_remaining, | ||
const bool | dont_show | ||
) |
Update the new C++ charts with the given loss and mAP% accuracy value. This is called at every iteration.