Yolo-tensorflow Recurrence Analysis

Source: Internet
Author: User

See someone using TensorFlow to reproduce the yoloV3, to record the code reading. The code that feels reproduced is not written very well, and some other people use Keras to reproduce the code.

TensorFlow Code Address: 79940118

The source code is divided into the following sections:

train.py The main program train.py part of the training of their own data set, eval.py to take advantage of the training of good weights to predict. Reader for reading data labels, etc., config.yml for some parameters in the training process settings, EVAL_CONFIG.YML for the prediction process of some parameters set. Utils package for some of the network structure, IOU and other intermediate steps. The following first describes the program in Utils

net.py: Set the network structure, extract picture information. The DARKNET-53 network structure is as follows. 1X,2X, respectively, said that the structure repeated 1 times two times, residual and the structure outside the front box is superimposed by dimension, similar to the residual network.

The Feature_extractor function extracts three scales of information scale1,scale2,scale3, respectively, to the output of the network structure in the penultimate 1th, 2, 3 squares. After that, the scales function interacts with feature units of three scales by 1x1,3x3 convolution respectively. Returns the three scale information after the interaction.
The final output of the three different scales for 13x13x75,26x26x75,52x52x75 specific interaction information can refer to the code structure. The last training will choose different scale to participate in the calculation loss,select_things is to choose the characteristics of different scale.
Don't quite understand how to use it? Is the scale selection required to manually change the configuration file? How to choose?

iou.py filters anchor for NMS to participate in the final loss calculation get_loss.py. First to explain IOU

1 defiou_calculator (x, y, width, height, l_x, l_y, L_width, l_height):2     " "3 X,y,width,height are the center coordinates of the prediction box and the width, height, l_x, l_y, L_width, L_height, respectively, the center coordinates of the real frame and the width, height4     " "5     ##x_min =x-w/2,y_min=y-h/2,x_max=x+w/2,y_max=y+h/2 The meaning of this paragraph to find out four angular coordinates respectively6X_max = Calculate_max (x, WIDTH/2 )7Y_max = Calculate_max (y, HEIGHT/2 )8X_min = Calculate_min (x, WIDTH/2 )9Y_min = Calculate_min (y, HEIGHT/2 )Ten  OneL_x_max = Calculate_max (l_x, WIDTH/2 ) AL_y_max = Calculate_max (l_y, HEIGHT/2 ) -L_x_min = Calculate_min (l_x, WIDTH/2 ) -L_y_min = Calculate_min (l_y, HEIGHT/2 ) the  -     " "find the area of the intersecting part" " -Xend =tf.minimum (X_max, L_x_max) -Xstart =tf.maximum (x_min, l_x_min) +  -Yend =tf.minimum (Y_max, L_y_max) +Ystart =tf.maximum (y_min, l_y_min) A  atArea_width = xend-Xstart -Area_height = Yend-Ystart -  -     " "Iou=a & (A+b-a & B) If the intersection of A and B is 0, 1e-8 is returned" " -Area = Area_width *Area_height -  inAll_area = Tf.cond ((Width * height + l_width * l_height-area) <= 0,Lambda: Tf.cast (1e-8, Tf.float32),Lambda: (Width * height + l_width * l_height-Area )) -  toIOU = Area/All_area +  -IOU = Tf.cond (Area_width < 0,Lambda: Tf.cast (1e-8, Tf.float32),Lambda: IOU) theIOU = Tf.cond (Area_height < 0,Lambda: Tf.cast (1e-8, Tf.float32),Lambda: IOU) *  $     returnIOU

get_loss.py to calculate the loss function, his loss function calculation is calculated according to YOLOV1, a bit of a problem.

1 defObjectness_loss (input, switch, l_switch, alpha = 0.5 ):2     " "3 input is iou,switch to 1 if there is an object in the box, otherwise 0,l_switch is the actual box with an object then 1, otherwise 04     " "5 6Iou_loss = tf.square (l_switch-input * switch)##input * Switch category confidence level C7Loss_max = Tf.square (L_switch * 0.5-input *switch)8 9Iou_loss = Tf.cond (Iou_loss < Loss_max,Lambda: Tf.cast (1e-8, Tf.float32),Lambda: Iou_loss)Ten  OneIou_loss = Tf.cond (L_switch < 1,Lambda: Iou_loss * Alpha,Lambda: Iou_loss) A  -     returnIou_loss -  the defLocation_loss (x, y, width, height, l_x, l_y, L_width, l_height, alpha = 5 ): -Point_loss = (Tf.square (l_x-x) + tf.square (l_y-y)) *Alpha -Size_loss = (Tf.square (tf.sqrt (l_width)-tf.sqrt (width)) + Tf.square (tf.sqrt (l_height)-tf.sqrt (height))) *Alpha -  +Location_loss = Point_loss +Size_loss -  +     returnLocation_loss A  at defClass_loss (inputs, labels): -Classloss = tf.square (Labels-inputs) -Loss_sum =tf.reduce_sum (Classloss) -  -     returnLoss_sum

Next is the program that extracts the training data extract_labels.py can download the Pascal VOC DataSet and read the data against the data format. More trouble, but this is the training program and prediction program The biggest difference, this code the biggest highlight is also here, other parts of the realization of personal feeling is not very good. The data can read both the category label and the object frame information.

Roughly wrote a program interpretation, because can only find a TensorFlow code implementation, the individual think is not very good, I hope someone has a better reproduction can say a bit. At the same time learn C + + is very important, you can directly read the source code.



Yolo-tensorflow Recurrence Analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.