nilboy / tensorflow-yolo

tensorflow implementation of 'YOLO : Real-Time Object Detection'(train and test)
773 stars 312 forks source link

the iou method in yolo_tiny_net.py #67

Open xadxxadx opened 5 years ago

xadxxadx commented 5 years ago

at line 115 : boxes1 = tf.transpose(boxes1, [1, 2, 3, 0])

the boxes1 data format transform from [cx, cy, w, h] to [x1, y1, x2, y2] yet. why there is line 115 convet format to [y1, x2, y2, x1] ????

I don't understand

thanks

Jerryzhangzhao commented 5 years ago

The result of line 115 : boxes1 = tf.transpose(boxes1, [1, 2, 3, 0]) is not with format [y1, x2, y2, x1]. Actually, boxes1 is a 4-D tensor, the tf.transpose operation change the order of dimensions from [0,1,2,3] to [1,2,3,0]. To understand why there is a transpose operation, we have to take line 114 and 115 together into consideration.

114: boxes1 = tf.stack([boxes1[:, :, :, 0] - boxes1[:, :, :, 2] / 2, boxes1[:, :, :, 1] - boxes1[:, :, :, 3] / 2,boxes1[:, :, :, 0] 
                           + boxes1[:, :, :, 2] / 2, boxes1[:, :, :, 1] + boxes1[:, :, :, 3] / 2])
115: boxes1 = tf.transpose(boxes1, [1, 2, 3, 0])

In line 114, the coordinate 'data format' was transformed from [center_x,center_y,w,h] to [x_min,y_min,x_max,y_max] and then stack the four tensor to be one with the default parameter 'axis=0', thus the result tensorboxes1 is no longer has the same shape before tf.stack() operation. So the transpose operation is aim to transform the shape of tensor boxes1 to original.

Actually, line 114 and 115 can be written as a single line:

boxes1 = tf.stack([boxes1[:, :, :, 0] - boxes1[:, :, :, 2] / 2, boxes1[:, :, :, 1] - boxes1[:, :, :, 3] / 2,boxes1[:, :, :, 0] 
                           + boxes1[:, :, :, 2] / 2, boxes1[:, :, :, 1] + boxes1[:, :, :, 3] / 2], axis=3)
yuanliangxie commented 5 years ago

the iou methed is wrong, buddy!