HDT算法(Hedged Deep Tracking)是发表在cvpr2016上的一篇论文,关于HDT跟踪算法代码运行的资料比较少,可能大家对这个算法的关注度不是很高吧,这里简单写下自己调试的过程。
论文:Hedged Deep Tracking
代码:https://github.com/JHvisionchen/HDT-matlab
作者的project页面始终打不开(https://sites.google.com/site/yuankiqi/hdt/),只找到了这个链接。代码下载下来后解压缩并命名为HDT
网络:http://www.vlfeat.org/matconvnet/models/beta16/imagenet-vgg-verydeep-19.mat(代码中用到的CNN网络)
将网络下载下来后,我是在代码文件夹HDT中新建model文件夹,然后将imagenet-vgg-verydeep-19.mat文件放进去。
首先在run_tracker.m文件中把base_path和pathModel两个变量路径改一下,base_path应该指向自己下载的数据集文件夹位置,这里我使用的是OTB2013数据集;pathModel就是刚才下载的
imagenet-vgg-verydeep-19.mat文件所在位置:
% path to the folder with VOT sequences
base_path = 'F:/Postgraduate Learning/OTB/TB50/';
pathModel = './model/imagenet-vgg-verydeep-19.mat';
这时候点击运行会发现好久没反应,然后突然出现如下错误:
出错是因为get_features.m文件中载入了网络,但是网络中没有‘meta’这个字段,设置断点后发现网络中真的是没有这个字段,不知道这个是不是作者的原代码,最后参考HCF算法,对几个文件进行了改动:
1. run_tracker.m
%error('Note: you need to compile the Matconvnet according to Readme.txt, and then comment the FIRST line in run_HDT.m')
addpath('model','matconvnet/matlab');
vl_setupnn();
vl_compilenn();
% path to the folder with VOT sequences
base_path = 'F:/Postgraduate Learning/OTB/TB50/';
% choose name of the VOT sequence
sequence_name = choose_video(base_path);
images_folder = [base_path sequence_name '/img/'];
pathAnno = [base_path sequence_name '/groundtruth_rect.txt'];
pathModel = './model/imagenet-vgg-verydeep-19.mat';
show_visualization = 1;
images = dir(fullfile(images_folder,'*.jpg'));
len = size(images,1);
img_files = cell(len,1);
for i = 1:len
img_files{i} = [images_folder images(i).name];
end
rect_anno = dlmread(pathAnno);
% rect_anno: nx4 matrix, storing gt bounding box in the form of [left top width height]
init_rect = rect_anno(1,:);
target_sz = [init_rect(4), init_rect(3)];
pos = [init_rect(2), init_rect(1)] + floor(target_sz/2);
% extra area surrounding the target
padding = struct('generic', 2.2, 'large', 1, 'height', 0.4);
lambda = 1e-4; %regularization
output_sigma_factor = 0.1; %spatial bandwidth (proportional to target)
interp_factor = 0.01;
cell_size = 4;
bSaveImage = 0;
[positions] = tracker_ensemble(img_files, pos, target_sz, ...
padding, lambda, output_sigma_factor, interp_factor, ...
cell_size, show_visualization, rect_anno, bSaveImage, pathModel);
% save results
rects = [positions(:,2) - target_sz(2)/2, positions(:,1) - target_sz(1)/2];
rects(:,3) = target_sz(2);
rects(:,4) = target_sz(1);
res.type = 'rect';
res.res = rects;
results=res;
2.initial_net.m
function initial_net(pathModel)
global net;
net = load(pathModel);
net.layers(37+1:end)=[];
% net=vl_simplenn_move(net,'gpu');
% Switch to GPU mode
global enableGPU;
if enableGPU
net = vl_simplenn_move(net, 'gpu');
end
net=vl_simplenn_tidy(net);
end
3.get_features.m
function feat = get_features(im, cos_window, layers)
%GET_FEATURES
% Extracts dense features from image.
global net
global enableGPU
if isempty(net)
initial_net();
end
sz_window=size(cos_window);
img = single(im); % note: 255 range
img = imResample(img, net.meta.normalization.imageSize(1:2));
% img = img - net.meta.normalization.averageImage;
average=net.meta.normalization.averageImage;
if numel(average)==3
average=reshape(average,1,1,3);
end
img = bsxfun(@minus, img, average);
if enableGPU, img = gpuArray(img); end
% run the CNN
res=vl_simplenn(net,img);
feat={};
for ii=1:length(layers)
% Resize to sz_window
if enableGPU
x = gather(res(layers(ii)).x);
else
x = res(layers(ii)).x;
end
x = imResample(x, sz_window(1:2));
%process with cosine window if needed
if ~isempty(cos_window),
x = bsxfun(@times, x, cos_window);
end
feat{ii}=x;
end
end
这样运行run_tracker.m文件时会先编译再运行。
然而发现仍然有错!!
最后我的结论是:原来代码里面的 matconvnet文件夹有问题,不全,后来从别的地方复制过去一个新的matconvnet文件夹,代码就能正常运行了。
matconvnet下载地址:https://github.com/vlfeat/matconvnet
下面的是我修改好的,需要的话可以下载,记得使用时修改数据集路径:
下载链接:https://pan.baidu.com/s/1QH00Slg5b-MCkvuOQzqkaw
提取码:1xj2