|
1 | 1 |
|
2 |
| -# variance变量 |
| 2 | +# variance变量 |
| 3 | + |
| 4 | +## 边界框回归 |
| 5 | + |
| 6 | +参考:[[R-CNN]边界框回归](https://blog.zhujian.life/posts/dd3aa53a.html) |
| 7 | + |
| 8 | +已知先验框$P=(P_{x}, P_{y}, P_{w}, P_{h})$和标注框坐标$G=(G_{x}, G_{y}, G_{w}, G_{h})$,计算回归目标$t$ |
| 9 | + |
| 10 | +$$ |
| 11 | +t_{x} = (G_{x} - P_{x}) / P_{w} \\ |
| 12 | +t_{y} = (G_{y} - P_{y}) / P_{h} \\ |
| 13 | +t_{w} = \log(G_{w} / P_{w}) \\ |
| 14 | +t_{h} = \log(G_{h} / P_{h}) |
| 15 | +$$ |
| 16 | + |
| 17 | +## variance使用 |
| 18 | + |
| 19 | +不过在`SSD`算法实现中,额外增加了一个`variance`变量 |
| 20 | + |
| 21 | +$$ |
| 22 | +t_{x} = (G_{x} - P_{x}) / P_{w} /center\_variance\\ |
| 23 | +t_{y} = (G_{y} - P_{y}) / P_{h} /center\_variance\\ |
| 24 | +t_{w} = \log(G_{w} / P_{w}) /size\_variance\\ |
| 25 | +t_{h} = \log(G_{h} / P_{h}) /size\_variance |
| 26 | +$$ |
| 27 | + |
| 28 | +其中 |
| 29 | + |
| 30 | +$$ |
| 31 | +center\_variance = 0.1 \ \ |
| 32 | +size\_variance=0.2 |
| 33 | +$$ |
| 34 | + |
| 35 | +参考: |
| 36 | + |
| 37 | +[[question] What is the purpose of the variances?](https://github.com/rykov8/ssd_keras/issues/53) |
| 38 | + |
| 39 | +[variance in priorbox layer #155](https://github.com/weiliu89/caffe/issues/155) |
| 40 | + |
| 41 | +[Bounding Box Encoding and Decoding in Object Detection](https://leimao.github.io/blog/Bounding-Box-Encoding-Decoding/) |
| 42 | + |
| 43 | +`variance`的作用在于对回归目标$t$进行了一次归一化操作,从而实现更好的训练精度 |
| 44 | + |
| 45 | +$$ |
| 46 | +{t}' = \frac {t - mean}{variance} = \frac {t - 0}{0.1或者0.2} |
| 47 | +$$ |
| 48 | + |
| 49 | +`variance`表示的其实是标准方差(`standard variance`) |
| 50 | + |
| 51 | +当然最后预测时,同样需要使用`variance`变量 |
| 52 | + |
| 53 | +$$ |
| 54 | +Pred_{x} = {t}'_{x} * center\_variance * P_{w} + P_{x}\\ |
| 55 | +Pred_{y} = {t}'_{y} * center\_variance * P_{h} + P_{y}\\ |
| 56 | +Pred_{w} = \exp ({t}'_{w} * size\_variance) * P_{w}\\ |
| 57 | +Pred_{h} = \exp ({t}'_{h} * size\_variance) * P_{h} |
| 58 | +$$ |
| 59 | + |
| 60 | +## 具体实现 |
| 61 | + |
| 62 | +* `py/ssd/utils/box_utils.py` |
| 63 | + |
| 64 | +``` |
| 65 | +def convert_locations_to_boxes(locations, priors, center_variance, size_variance): |
| 66 | +。。。 |
| 67 | +def convert_boxes_to_locations(center_form_boxes, center_form_priors, center_variance, size_variance): |
| 68 | +。。。 |
| 69 | +``` |
0 commit comments