leeyoshinari / YOLO_v2

The implementation of YOLO v2 with TensorFlow
GNU General Public License v3.0
80 stars 38 forks source link

关于bounding box的计算问题 #9

Closed ruikun closed 6 years ago

ruikun commented 6 years ago

你好,在preprocess.py 文件中计算box的 x,y,w,h 的代码如下: boxes = [0.5 (x1 + x2), 0.5 (y1 + y2), np.sqrt((x2 - x1) / self.image_size), np.sqrt((y2 - y1) / self.image_size)]

请问w,h,的计算问什么要经过开平方? 直接相减不行吗?

ruikun commented 6 years ago

@leeyoshinari 而且为什么要先除掉image_size再开方呢? 此外我注意到你的yolov1,yolov2,yolov3在计算box的 x,y,w,h 的方式上都不一样, yolo v1:boxes = [(x2 + x1) / 2.0, (y2 + y1) / 2.0, x2 - x1, y2 - y1] yolo v2:如楼上 yolo v3:boxes = [0.5 (x1 + x2) / self.image_size, 0.5 (y1 + y2) / self.image_size, np.sqrt((x2 - x1) / self.image_size), np.sqrt((y2 - y1) / self.image_size)]

请问是有什么原理上的不同吗?我的理解的话应该就是yolo v1那种形式,很困惑,望赐教。

leeyoshinari commented 6 years ago

yolo v1's original is "Sum-squared error also equally weights errors in large boxes and small boxes. Our error metric should reflect that small deviations in large boxes matter less than in small boxes. To partially address this we predict the square root of the bounding box width and height instead of the width and height directly." It is not impossible to directly subtract.

leeyoshinari commented 6 years ago

The code you mentioned for calculating boxes isn't real, it's just preprocessing. You have to see how boxes are calculated when calculating loss. If this, you will find that the calculations for yolo's boxes are very similar.