上一篇文章解析了SiamRPN(DaSiamRPN)的论文,但是光说不练是不行的,好在其团队还是给出了竞赛用的代码,虽然没有训练部分,但有的总比没有的强。这里就简要解析一下代码,欢迎交流。
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
# 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)
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
p.score_size = (p.instance_size - p.exemplar_size) / p.total_stride + 1
[[ 0. 0. 104. 32.]
[ 0. 0. 88. 40.]
[ 0. 0. 64. 64.]
[ 0. 0. 40. 80.]
[ 0. 0. 32. 96.]]
[[-72. -72. 104. 32.] [-64. -72. 104. 32.] [-56. -72. 104. 32.]
......
[ 56. 72. 32. 96.] [ 64. 72. 32. 96.] [ 72. 72. 32. 96.]]
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