SiamRPN VOT2018竞赛提交代码解读

SiamRPN VOT CODE

上一篇文章解析了SiamRPN(DaSiamRPN)的论文,但是光说不练是不行的,好在其团队还是给出了竞赛用的代码,虽然没有训练部分,但有的总比没有的强。这里就简要解析一下代码,欢迎交流。

1. 主要文件引用关系

vot_SiamRPN文件引入的函数:

vot (Rectangle) -->> vot_SiamRPN
net (SiamRPNBIG) -->> vot_SiamRPN
run_SiamRPN (SiamRPN_init SiamRPN_track) -->> vot_SiamRPN
utils (get_axis_aligned_bbox, cxy_wh_2_rect) -->> vot_SiamRPN
run_SiamRPN文件引入的函数:
utils (get_subwindow_tracking) -->> run_SiamRPN

2.代码说明

vot_SiamRPN

# load net
net = SiamRPNBIG()

# warm up in realtime
net.temple(
    torch.autograd.Variable(
        torch.FloatTensor(1, 3, 127, 127)
    ).cuda()
)

# start to track
handle = vot.VOT("polygon")
Polygon = handle.region()
cx, cy, w, h = get_axis_aligned_bbox(Polygon)
target_pos, target_sz = np.array([cx, cy]), np.array([w, h])

image_file = handle.frame()
im = cv2.imread(image_file)  # HxWxC

# init tracker
state = SiamRPN_init(im, target_pos, target_sz, net)  

# track
state = SiamRPN_track(state, im)  
  1. 载入网络,读取ground truth,读取图像;
  2. 调用SiamRPN_init处理初始帧,输出第一个state;
  3. 以上一帧的输出state为参数调用SiamRPN_track,处理下一帧,输出下一帧的state;
  4. 重复步骤3

run_SiamRPN

SiamRPN_init:
    p = TrackerConfig()
    p.anchor = generate_anchor(
    	p.total_stride, 
    	p.scales, 
    	p.ratios, 
    	p.score_size)
    z_crop = get_subwindow_tracking(
    	im, 
    	target_pos, 
    	p.exemplar_size, 
    	s_z, 
    	avg_chans)
    net.temple(z.cuda())
    return state
  • 载入参数TrackerConfig;
  • 选定input x size (search region),即参数p.instance_size,计算p.score_size = 19 (17?):
p.score_size = (p.instance_size - p.exemplar_size) / p.total_stride + 1
  • 计算anchor,调用generate_anchor:
  1. ratios = [0.33, 0.5, 1, 2, 3],所以有五种尺度的anchor:
[[  0.   0. 104.  32.] 
[  0.   0.  88.  40.] 
[  0.   0.  64.  64.] 
[  0.   0.  40.  80.]
[  0.   0.  32.  96.]]
  1. score map size: 19x19 = 361
    即有361个位置需要布置anchor,一组anchor有五种尺度,共计361x5=1805个anchor;
  2. 计算出score map映射回原图的坐标,与anchor尺度数据结合后,得到完整的anchor:
[[-72. -72. 104.  32.] [-64. -72. 104.  32.] [-56. -72. 104.  32.]
 ......
 [ 56.  72.  32.  96.] [ 64.  72.  32.  96.] [ 72.  72.  32.  96.]]
  • 初始化模板分支(initialize the exemplar):
  1. 调用get_subwindow_tracking使输入的图像尺寸一致,尺寸由参数exemplar_size决定(127x127);
  2. 图像尺寸调整后输入网络,调用net.temple,模板分支完成。
  • 设置余弦窗;
  • 将以上初始化过程得到的结果存入state,初始化完成!
SiamRPN_track:

    # extract scaled crops for search region x at previous target position
    
    x_crop = Variable(get_subwindow_tracking(
    	im, 
    	target_pos, 
    	p.instance_size, 
    	round(s_x), 
    	avg_chans).unsqueeze(0))
    
    target_pos, target_sz, score = tracker_eval(
        net, 
        x_crop.cuda(), 
        target_pos, 
        target_sz * scale_z, 
        window, scale_z, 
        p)
    
    return state

你可能感兴趣的:(自我总结归纳)