理解的是作者的源码,地址 GitHub - ohhhyeahhh/SiamGAT: Code for the paper "Graph Attention Tracking". (CVPR2021)
project部分结构

一、从testTracker中的main()函数进入
def main():
# load config
cfg.merge_from_file(args.config)
# Test dataset
dataset_root='/1904server/share/Data/GOT_10k/full_data/test_data/test/'
# set hyper parameters
params = getattr(cfg.HP_SEARCH, args.dataset)
cfg.TRACK.LR = params[0]
cfg.TRACK.PENALTY_K = params[1]
cfg.TRACK.WINDOW_INFLUENCE = params[2]
model = ModelBuilder()
在ModelBuilder()
https://blog.youkuaiyun.com/every_step/article/details/120684274中主要
# build backbone # build car head 分类和回归子网的包围盒预测 # build response map
# load model
model = load_pretrain(model, args.snapshot).cuda().eval()
# build tracker
tracker = SiamGATTracker(model)
在SiamGATTracker()
https://blog.youkuaiyun.com/every_step/article/details/120686343里,主要包含两个函数 init()和tracker()
- initi:当idx == 0,即传入第一帧图片时,初始化参数,计算一些之后搜索区域的中心等
- tracker:idx不等于0,传入后续的帧,根据网络返回目标的box坐标。
# create dataset
dataset = DatasetFactory.create_dataset(name=args.dataset,
dataset_root=dataset_root,
load_img=False)
model_name = args.snapshot.split('/')[-1].split('.')[-2]
# OPE tracking
for v_idx, video in enumerate(dataset):
if args.video != '':
# test one special video
if video.name != args.video:
continue
toc = 0
pred_bboxes = []
track_times = []
for idx, (img, gt_bbox) in enumerate(video):
tic = cv2.getTickCount()
if idx == 0:
cx, cy, w, h = get_axis_aligned_bbox(np.array(gt_bbox))
gt_bbox_ = [cx-(w-1)/2, cy-(h-1)/2, w, h]
tracker.init(img, gt_bbox_)
pred_bbox = gt_bbox_
pred_bboxes.append(pred_bbox)
else:
outputs = tracker.track(img)
pred_bbox = outputs['bbox']
pred_bboxes.append(pred_bbox)
toc += cv2.getTickCount() - tic
track_times.append((cv2.getTickCount() - tic)/cv2.getTickFrequency())
if idx == 0:
cv2.destroyAllWindows()
if args.vis and idx > 0:
if not any(map(math.isnan,gt_bbox)):
gt_bbox = list(map(int, gt_bbox))
pred_bbox = list(map(int, pred_bbox))
cv2.rectangle(img, (gt_bbox[0], gt_bbox[1]),
(gt_bbox[0]+gt_bbox[2], gt_bbox[1]+gt_bbox[3]), (0, 255, 0), 3)
cv2.rectangle(img, (pred_bbox[0], pred_bbox[1]),
(pred_bbox[0]+pred_bbox[2], pred_bbox[1]+pred_bbox[3]), (0, 255, 255), 3)
cv2.putText(img, str(idx), (40, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 2)
cv2.imshow(video.name, img)
cv2.waitKey(1)
toc /= cv2.getTickFrequency()
跟踪并且框出目标。
本文介绍了GitHub项目SiamGAT的实现细节,涉及模型构建、预训练模型加载、Tracker组件和测试过程。重点在于理解SiamGATTracker的init和track函数,以及如何通过配置参数进行目标追踪。
https://blog.youkuaiyun.com/every_step/article/details/120684274
3045





