阅读 $SiamMask/tools/test.py
$SiamMask/tools/test.py
pip install ipdb
修改 $SiamMask/tools/test.py
在代码开头import ipdb,如下:
# --------------------------------------------------------
# SiamMask
# Licensed under The MIT License
# Written by Qiang Wang (wangqiang2015 at ia.ac.cn)
# --------------------------------------------------------
from __future__ import division
import argparse
......
# added by shifangxu
import ipdb
thrs = np.arange(0.3, 0.5, 0.05)
在需要开始调试的地方加入语句:
def siamese_track(state, im, mask_enable=False, refine_enable=False, device='cpu', debug=False):
p = state['p']
net = state['net']
avg_chans = state['avg_chans']
window = state['window']
target_pos = state['target_pos']
target_sz = state['target_sz']
wc_x = target_sz[1] + p.context_amount * sum(target_sz)
hc_x = target_sz[0] + p.context_amount * sum(target_sz)
s_x = np.sqrt(wc_x * hc_x)
scale_x = p.exemplar_size / s_x
d_search = (p.instance_size - p.exemplar_size) / 2
pad = d_search / scale_x
s_x = s_x + 2 * pad
crop_box = [target_pos[0] - round(s_x) / 2, target_pos[1] - round(s_x) / 2, round(s_x), round(s_x)]
# added by shifangxu
ipdb.set_trace()
if debug:
im_debug = im.copy()
crop_box_int = np.int0(crop_box)
cv2.rectangle(im_debug, (crop_box_int[0], crop_box_int[1]),
(crop_box_int[0] + crop_box_int[2], crop_box_int[1] + crop_box_int[3]), (255, 0, 0), 2)
cv2.imshow('search area', im_debug)
cv2.waitKey(0)
# 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))
运行目标跟踪程序
bash test_mask_refine.sh config_vot.json SiamMask_VOT.pth VOT2018 0
到达断点之后,程序暂停,可以用p命令打印变量。
例如: “ p crop_box” 打印变量 crop_box
(siammask) anna@anna-TM1801:~/object_track_xu/3_SiamMask/2_code/SiamMask-master/experiments/siammask_sharp$ bash test_mask_refine.sh config_vot.json SiamMask_VO
T.pth VOT2018 0
test_mask_refine.sh: line 8: ./: Is a directory
added by shifangxu, score_size!!!
25
[2019-07-16 17:01:32,227-rk0-test.py#583] Namespace(arch=‘Custom’, config=‘config_vot.json’, cpu=False, dataset=‘VOT2018’, debug=False, gt=False, log=‘log_test.txt’, mask=True, refine=True, resume=‘SiamMask_VOT.pth’, save_mask=False, video=’’, visualization=False)
[2019-07-16 17:01:32,426-rk0-features.py# 66] Current training 0 layers:
[2019-07-16 17:01:32,426-rk0-features.py# 66] Current training 1 layers:
[2019-07-16 17:01:32,476-rk0-load_helper.py# 31] load pretrained model from SiamMask_VOT.pth
[2019-07-16 17:01:34,084-rk0-load_helper.py# 25] remove prefix ‘module.’
[2019-07-16 17:01:34,085-rk0-load_helper.py# 18] used keys:356
added by shifangxu !!!
target_sz[0] =
24.256231789032594
target_sz[1] =
59.781759822510274
wc_z =
66.27522759480402
hc_z =
101.8007556282817
/home/anna/object_track_xu/3_SiamMask/2_code/SiamMask-master/tools/test.py(214)siamese_track()
213
–> 214 if debug:
215 im_debug = im.copy()
ipdb> p crop_box
[60.2775, 411.385, 165.0, 165.0]
ipdb>
参考如下博客:
python、pytorch调试工具——ipdb
https://blog.csdn.net/hajungong007/article/details/80379209
n (下一个),next单步执行
ENTER (重复上次命令)
q (退出)
p <变量> (打印变量)
-b 10(在第10行设置断点)break的缩写
c (继续) 直到遇到断点
l (查找当前位于哪里)
s (进入子程序) step的缩写,进入到函数内部
r (运行直到子程序结束返回) rerurn的缩写
! r(查看变量r的值)
u(跳回上一层)up的缩写
d(跳到下一层)down的缩写
X (查看变量X)
X[0] = 1000 (修改变量x的值为1000)
j 10 (跳到第十行) jump的缩写
h (查看调试的命令)help的缩写
tab (自动补全)