Darknet source code understanding (1) - understanding of the main framework

Introduction:

This series of blog posts introduces the understanding of the Darknet source code, which is the understanding of the main framework of the program. The default readers of this blog post are basically familiar with the use of Darknet.


text:

The main function of darknet is in darknet.c , in which the main () function turns to different functional functions according to the terminal input parameters.


If argv[1] = "detector" , turn to run_detector() ( this function is in detector.c ) , and pass the input parameters to

run_detector()。

run_detector () turns to different function functions according to different parameters, as shown in the figure below, this code is at the bottom of detector.c .


Friends who are familiar with the use of darknet must know that the command executed when detecting a picture is generally

./darknet detector test cfg/coco.data cfg/yolov3.cfg yolov3.weights data/dog.jpg

Combined with the above figure, when the second parameter is test , it will turn to execute test_detector() (in detector.c ) . For specific procedures, refer to detector.c.

In test_detector (),

1. Execute network*net = load_network(cfgfile, weightfile, 0) to initialize a network, cfgfile is the model configuration file, and weightfile is

Model weights file.

2. Execute image im= load_image_color(input,0,0) to read a picture, input is the picture address. execute imagesized =

letterbox_image(im, net->w, net→h) , resize the image to the size required by the model.

3. Execute network_predict(net,X) , and the model performs forward propagation. X is the input image.

4. Execute detection*dets = get_network_boxes(net, im.w, im.h, thresh, hier_thresh, 0, 1,&nboxes) , according to the output of the network

out to extract the location and category of the detected target.

5. Execute draw_detections(im,dets, nboxes, thresh, names, alphabet, l.classes) , mark the position and category of the target in the figure

in the film.


Note:

network , image , detection , etc. are structures defined in the framework, which are declared in the darknet.h file.


Summarize:


In the test_detector () function, an end-to-end process that we are familiar with is included. That is, initialize the model, read the weight of the model, read the image, resize the image ,

Feed the image to the model for forward propagation, obtain the target position and category according to the model output, and mark the target position and category on the image.


The next blog will introduce the specific process of input image reading!











Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324759946&siteId=291194637