在Faster RCNN中有使用一些额外的程序,类等等,为了使文章整体内容不过于分散,这里作为篇外卷学习。
文件地址:\py-faster-rcnn\lib\datasets
本文章解析代码为ds_utils.py。
代码包含5个子函数,逐一进行解析。
第一个子函数unique_boxes,作者命名为独一无二的盒子们。
def unique_boxes(boxes, scale=1.0):
"""Return indices of unique boxes."""
v = np.array([1, 1e3, 1e6, 1e9])
hashes = np.round(boxes * scale).dot(v)
_, index = np.unique(hashes, return_index=True)
return np.sort(index)
首先是生存一个1*4的向量V(np.array),然后是一个矩阵的乘(np.round 和dot()),输出不一样的数的位置索引(_, index = np.unique(hashes, return_index=True) ),然后对索引进行排序(np.sort(),默认为升序)
重点说明:np.unique的输出,根据一个简单的例子可知
A = [1, 2, 2, 3, 4, 5]
a, b, c = np.unique(A, return_index=True, return_inverse=True)
print a, b, c # 输出为 [1 2 3 4 5], [0 1 3 4 5], [0 1 1 2 3 4]
可以看出第一个输出是不重复的值,第二个是每个不重复在A中的位置索引,第三个是每个值在A中的位置。
简单来说,该子函数unique_boxes输入了盒子的尺寸,乘以一个放缩尺度大小(估计是后面三个尺度太小需要放大便于比较。)后删除了重复的盒子。
然后的格式数据的转化xywh_to_xyxy()和xyxy_to_xywh()。</