• 基于全卷积Fully-Convolutional-Siamese-Networks的目标跟踪仿真


    目录

    1.算法概述

    2.仿真效果预览

    3.核心MATLAB代码预览

    4.完整MATLAB程序


    1.算法概述

    1.正确版本组合:Win7+Matlab R2015b+CUDA7.5+vs2013

    CUDA7.5下载地址为:

    http://developer.download.nvidia.com/compute/cuda/7.5/Prod/local_installers/cuda_7.5.18_windows.exe

    vs2013要专业版。

    如下所示:

     全部安装好之后,做如下操作:

    2.CPU配置,运行CNN工具箱中的 ,然后再运行 可以完成CPP文件的编译。

    3.编译成功后,会产生

    这些必须在电脑上编译,否则别人的复制给你,如果配置不一样,可能会报错。

    4.GPU配置:

    安装cudnn:https://developer.nvidia.com/rdp/cudnn-archive,放到CNN工具箱中的新建local文件夹中,

    然后mex -setup下,操作和CPU一样。

    然后执行matlab程序:

    vl_setupnn;

    vl_compilenn('enableGpu', true,'cudaRoot', 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5','cudaMethod', 'nvcc', 'enableCudnn', 'true','cudnnRoot', 'E:\A_2016_FPGA_Test\FC_tracking\A_FC\matconvnet-1.0-beta20\local\cudnn');

    红色部分为你的路径,不要有中文。

    5.然后运行我给的程序 ,就可以自动运行了,原来程序的运行非常麻烦,我定义了这个程序,可以一步运行处结果。

    2.仿真效果预览

    Win7+Matlab R2015b+CUDA7.5+vs2013

    运行后,如果可以出现如下结果:

    3.核心MATLAB代码预览

    1. % -------------------------------------------------------------------------------------------------
    2. function bboxes = tracker(varargin)
    3. %TRACKER
    4. % is the main function that performs the tracking loop
    5. % Default parameters are overwritten by VARARGIN
    6. %
    7. % Luca Bertinetto, Jack Valmadre, Joao F. Henriques, 2016
    8. % -------------------------------------------------------------------------------------------------
    9. % These are the default hyper-params for SiamFC-3S
    10. % The ones for SiamFC (5 scales) are in params-5s.txt
    11. p.numScale = 3;
    12. p.scaleStep = 1.0375;
    13. p.scalePenalty = 0.9745;
    14. p.scaleLR = 0.59; % damping factor for scale update
    15. p.responseUp = 16; % upsampling the small 17x17 response helps with the accuracy
    16. p.windowing = 'cosine'; % to penalize large displacements
    17. p.wInfluence = 0.176; % windowing influence (in convex sum)
    18. p.net = '2016-08-17.net.mat';
    19. %% execution, visualization, benchmark
    20. p.video = 'vot15_bag';
    21. p.visualization = false;
    22. p.gpus = 1;
    23. p.bbox_output = false;
    24. p.fout = -1;
    25. %% Params from the network architecture, have to be consistent with the training
    26. p.exemplarSize = 127; % input z size
    27. p.instanceSize = 255; % input x size (search region)
    28. p.scoreSize = 17;
    29. p.totalStride = 8;
    30. p.contextAmount = 0.5; % context amount for the exemplar
    31. p.subMean = false;
    32. %% SiamFC prefix and ids
    33. p.prefix_z = 'a_'; % used to identify the layers of the exemplar
    34. p.prefix_x = 'b_'; % used to identify the layers of the instance
    35. p.prefix_join = 'xcorr';
    36. p.prefix_adj = 'adjust';
    37. p.id_feat_z = 'a_feat';
    38. p.id_score = 'score';
    39. % Overwrite default parameters with varargin
    40. p = vl_argparse(p, varargin);
    41. % -------------------------------------------------------------------------------------------------
    42. % Get environment-specific default paths.
    43. p = env_paths_tracking(p);
    44. 1
    45. % Load ImageNet Video statistics
    46. if exist(p.stats_path,'file')
    47. stats = load(p.stats_path);
    48. else
    49. warning('No stats found at %s', p.stats_path);
    50. stats = [];
    51. end
    52. 2
    53. % Load two copies of the pre-trained network
    54. net_z = load_pretrained([p.net_base_path p.net], p.gpus);
    55. 3
    56. net_x = load_pretrained([p.net_base_path p.net], []);
    57. 4
    58. p.seq_base_path
    59. p.video
    60. [imgFiles, targetPosition, targetSize] = load_video_info(p.seq_base_path, p.video);
    61. nImgs = numel(imgFiles);
    62. startFrame = 1;
    63. 5
    64. % Divide the net in 2
    65. % exemplar branch (used only once per video) computes features for the target
    66. remove_layers_from_prefix(net_z, p.prefix_x);
    67. remove_layers_from_prefix(net_z, p.prefix_join);
    68. remove_layers_from_prefix(net_z, p.prefix_adj);
    69. % instance branch computes features for search region x and cross-correlates with z features
    70. 6
    71. remove_layers_from_prefix(net_x, p.prefix_z);
    72. zFeatId = net_z.getVarIndex(p.id_feat_z);
    73. scoreId = net_x.getVarIndex(p.id_score);
    74. % get the first frame of the video
    75. im = gpuArray(single(imgFiles{startFrame}));
    76. % if grayscale repeat one channel to match filters size
    77. if(size(im, 3)==1)
    78. im = repmat(im, [1 1 3]);
    79. end
    80. % Init visualization
    81. videoPlayer = [];
    82. if p.visualization && isToolboxAvailable('Computer Vision System Toolbox')
    83. videoPlayer = vision.VideoPlayer('Position', [100 100 [size(im,2), size(im,1)]+30]);
    84. end
    85. 7
    86. % get avg for padding
    87. avgChans = gather([mean(mean(im(:,:,1))) mean(mean(im(:,:,2))) mean(mean(im(:,:,3)))]);
    88. wc_z = targetSize(2) + p.contextAmount*sum(targetSize);
    89. hc_z = targetSize(1) + p.contextAmount*sum(targetSize);
    90. s_z = sqrt(wc_z*hc_z);
    91. scale_z = p.exemplarSize / s_z;
    92. % initialize the exemplar
    93. [z_crop, ~] = get_subwindow_tracking(im, targetPosition, [p.exemplarSize p.exemplarSize], [round(s_z) round(s_z)], avgChans);
    94. if p.subMean
    95. z_crop = bsxfun(@minus, z_crop, reshape(stats.z.rgbMean, [1 1 3]));
    96. end
    97. d_search = (p.instanceSize - p.exemplarSize)/2;
    98. pad = d_search/scale_z;
    99. s_x = s_z + 2*pad;
    100. % arbitrary scale saturation
    101. min_s_x = 0.2*s_x;
    102. max_s_x = 5*s_x;
    103. switch p.windowing
    104. case 'cosine'
    105. window = single(hann(p.scoreSize*p.responseUp) * hann(p.scoreSize*p.responseUp)');
    106. case 'uniform'
    107. window = single(ones(p.scoreSize*p.responseUp, p.scoreSize*p.responseUp));
    108. end
    109. % make the window sum 1
    110. window = window / sum(window(:));
    111. scales = (p.scaleStep .^ ((ceil(p.numScale/2)-p.numScale) : floor(p.numScale/2)));
    112. % evaluate the offline-trained network for exemplar z features
    113. net_z.eval({'exemplar', z_crop});
    114. z_features = net_z.vars(zFeatId).value;
    115. z_features = repmat(z_features, [1 1 1 p.numScale]);
    116. bboxes = zeros(nImgs, 4);
    117. % start tracking
    118. tic;
    119. for i = startFrame:nImgs
    120. i
    121. if i>startFrame
    122. % load new frame on GPU
    123. im = gpuArray(single(imgFiles{i}));
    124. % if grayscale repeat one channel to match filters size
    125. if(size(im, 3)==1)
    126. im = repmat(im, [1 1 3]);
    127. end
    128. scaledInstance = s_x .* scales;
    129. scaledTarget = [targetSize(1) .* scales; targetSize(2) .* scales];
    130. % extract scaled crops for search region x at previous target position
    131. x_crops = make_scale_pyramid(im, targetPosition, scaledInstance, p.instanceSize, avgChans, stats, p);
    132. % evaluate the offline-trained network for exemplar x features
    133. [newTargetPosition, newScale] = tracker_eval(net_x, round(s_x), scoreId, z_features, x_crops, targetPosition, window, p);
    134. targetPosition = gather(newTargetPosition);
    135. % scale damping and saturation
    136. s_x = max(min_s_x, min(max_s_x, (1-p.scaleLR)*s_x + p.scaleLR*scaledInstance(newScale)));
    137. targetSize = (1-p.scaleLR)*targetSize + p.scaleLR*[scaledTarget(1,newScale) scaledTarget(2,newScale)];
    138. else
    139. % at the first frame output position and size passed as input (ground truth)
    140. end
    141. rectPosition = [targetPosition([2,1]) - targetSize([2,1])/2, targetSize([2,1])];
    142. % output bbox in the original frame coordinates
    143. oTargetPosition = targetPosition; % .* frameSize ./ newFrameSize;
    144. oTargetSize = targetSize; % .* frameSize ./ newFrameSize;
    145. bboxes(i, :) = [oTargetPosition([2,1]) - oTargetSize([2,1])/2, oTargetSize([2,1])];
    146. % if p.visualization
    147. if isempty(videoPlayer)
    148. figure(1), imshow(im/255);
    149. figure(1), rectangle('Position', rectPosition, 'LineWidth', 4, 'EdgeColor', 'y');
    150. drawnow
    151. fprintf('Frame %d\n', startFrame+i);
    152. else
    153. im = gather(im)/255;
    154. im = insertShape(im, 'Rectangle', rectPosition, 'LineWidth', 4, 'Color', 'yellow');
    155. % Display the annotated video frame using the video player object.
    156. step(videoPlayer, im);
    157. end
    158. % end
    159. if p.bbox_output
    160. fprintf(p.fout,'%.2f,%.2f,%.2f,%.2f\n', bboxes(i, :));
    161. end
    162. end
    163. bboxes = bboxes(startFrame : i, :);
    164. end
    165. A000

    4.完整MATLAB程序

    matlab源码说明_我爱C编程的博客-CSDN博客

    V

  • 相关阅读:
    VSCode 使用CMakePreset找不到cl.exe编译器的问题
    类似 MS Project 的项目管理工具有哪些
    Java笔记 实用类(二)
    Junit5的断言方式,一学就会
    MAC系统下Xcode连接iOS真机实现iOS App自动化测试(上)
    代码随想录算法训练营Day1 : 704.二分查找、27.移除元素
    C/C++模拟校园卡
    【Java】Java中的零拷贝
    Linux系统编程 系统编程概念
    Flutter高仿微信-第32篇-单聊-语音
  • 原文地址:https://blog.csdn.net/hlayumi1234567/article/details/125155060