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

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

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要专业版。

如下所示:

1.png

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

2.CPU配置,运行CNN工具箱中的
2.png

然后再运行
3.png

可以完成CPP文件的编译。

3.编译成功后,会产生

4.png

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

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.然后运行程序5.png
,就可以自动运行了,原来程序的运行非常麻烦,定义了这个程序,可以一步运行处结果。

2.仿真效果预览
Win7+Matlab R2015b+CUDA7.5+vs2013

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

3.核心MATLAB代码预览

%TRACKER
%   is the main function that performs the tracking loop
%   Default parameters are overwritten by VARARGIN
%
%   Luca Bertinetto, Jack Valmadre, Joao F. Henriques, 2016
% -------------------------------------------------------------------------------------------------
    % These are the default hyper-params for SiamFC-3S
    % The ones for SiamFC (5 scales) are in params-5s.txt
    p.numScale = 3;
    p.scaleStep = 1.0375;
    p.scalePenalty = 0.9745;
    p.scaleLR = 0.59; % damping factor for scale update
    p.responseUp = 16; % upsampling the small 17x17 response helps with the accuracy
    p.windowing = 'cosine'; % to penalize large displacements
    p.wInfluence = 0.176; % windowing influence (in convex sum)
    p.net = '2016-08-17.net.mat';
    %% execution, visualization, benchmark
    p.video = 'vot15_bag';
    p.visualization = false;
    p.gpus = 1;
    p.bbox_output = false;
    p.fout = -1;
    %% Params from the network architecture, have to be consistent with the training
    p.exemplarSize = 127;  % input z size
    p.instanceSize = 255;  % input x size (search region)
    p.scoreSize = 17;
    p.totalStride = 8;
    p.contextAmount = 0.5; % context amount for the exemplar
    p.subMean = false;
    %% SiamFC prefix and ids
    p.prefix_z = 'a_'; % used to identify the layers of the exemplar
    p.prefix_x = 'b_'; % used to identify the layers of the instance
    p.prefix_join = 'xcorr';
    p.prefix_adj = 'adjust';
    p.id_feat_z = 'a_feat';
    p.id_score = 'score';
    % Overwrite default parameters with varargin
    p = vl_argparse(p, varargin);
% -------------------------------------------------------------------------------------------------
 
    % Get environment-specific default paths.
    p = env_paths_tracking(p);
    1
    % Load ImageNet Video statistics
    if exist(p.stats_path,'file')
        stats = load(p.stats_path);
    else
        warning('No stats found at %s', p.stats_path);
        stats = [];
    end
    
    2
    % Load two copies of the pre-trained network
    net_z = load_pretrained([p.net_base_path p.net], p.gpus);
    3
    net_x = load_pretrained([p.net_base_path p.net], []);
    4
    p.seq_base_path
    p.video
    [imgFiles, targetPosition, targetSize] = load_video_info(p.seq_base_path, p.video);
    nImgs = numel(imgFiles);
    startFrame = 1;
    5
    % Divide the net in 2
    % exemplar branch (used only once per video) computes features for the target
    remove_layers_from_prefix(net_z, p.prefix_x);
    remove_layers_from_prefix(net_z, p.prefix_join);
    remove_layers_from_prefix(net_z, p.prefix_adj);
    % instance branch computes features for search region x and cross-correlates with z features
    6
    remove_layers_from_prefix(net_x, p.prefix_z);
    zFeatId = net_z.getVarIndex(p.id_feat_z);
    scoreId = net_x.getVarIndex(p.id_score);
    % get the first frame of the video
    im = gpuArray(single(imgFiles{startFrame}));
    % if grayscale repeat one channel to match filters size
    if(size(im, 3)==1)
        im = repmat(im, [1 1 3]);
    end
    % Init visualization
    videoPlayer = [];
    if p.visualization && isToolboxAvailable('Computer Vision System Toolbox')
        videoPlayer = vision.VideoPlayer('Position', [100 100 [size(im,2), size(im,1)]+30]);
    end
    7
    % get avg for padding
    avgChans = gather([mean(mean(im(:,:,1))) mean(mean(im(:,:,2))) mean(mean(im(:,:,3)))]);
 
    wc_z = targetSize(2) + p.contextAmount*sum(targetSize);
    hc_z = targetSize(1) + p.contextAmount*sum(targetSize);
    s_z = sqrt(wc_z*hc_z);
    scale_z = p.exemplarSize / s_z;
    % initialize the exemplar
    [z_crop, ~] = get_subwindow_tracking(im, targetPosition, [p.exemplarSize p.exemplarSize], [round(s_z) round(s_z)], avgChans);
    if p.subMean
        z_crop = bsxfun(@minus, z_crop, reshape(stats.z.rgbMean, [1 1 3]));
    end
    d_search = (p.instanceSize - p.exemplarSize)/2;
    pad = d_search/scale_z;
    s_x = s_z + 2*pad;
    % arbitrary scale saturation
    min_s_x = 0.2*s_x;
    max_s_x = 5*s_x;
 
    switch p.windowing
        case 'cosine'
            window = single(hann(p.scoreSize*p.responseUp) * hann(p.scoreSize*p.responseUp)');
        case 'uniform'
            window = single(ones(p.scoreSize*p.responseUp, p.scoreSize*p.responseUp));
    end
    % make the window sum 1
    window = window / sum(window(:));
    scales = (p.scaleStep .^ ((ceil(p.numScale/2)-p.numScale) : floor(p.numScale/2)));
    % evaluate the offline-trained network for exemplar z features
    net_z.eval({'exemplar', z_crop});
    z_features = net_z.vars(zFeatId).value;
    z_features = repmat(z_features, [1 1 1 p.numScale]);
 
    bboxes = zeros(nImgs, 4);
    % start tracking
    tic;
    for i = startFrame:nImgs
        i
        if i>startFrame
            % load new frame on GPU
            im = gpuArray(single(imgFiles{i}));
               % if grayscale repeat one channel to match filters size
            if(size(im, 3)==1)
                im = repmat(im, [1 1 3]);
            end
            scaledInstance = s_x .* scales;
            scaledTarget = [targetSize(1) .* scales; targetSize(2) .* scales];
            % extract scaled crops for search region x at previous target position
            x_crops = make_scale_pyramid(im, targetPosition, scaledInstance, p.instanceSize, avgChans, stats, p);
            % evaluate the offline-trained network for exemplar x features
            [newTargetPosition, newScale] = tracker_eval(net_x, round(s_x), scoreId, z_features, x_crops, targetPosition, window, p);
            targetPosition = gather(newTargetPosition);
            % scale damping and saturation
            s_x = max(min_s_x, min(max_s_x, (1-p.scaleLR)*s_x + p.scaleLR*scaledInstance(newScale)));
            targetSize = (1-p.scaleLR)*targetSize + p.scaleLR*[scaledTarget(1,newScale) scaledTarget(2,newScale)];
        else
            % at the first frame output position and size passed as input (ground truth)
        end
 
        rectPosition = [targetPosition([2,1]) - targetSize([2,1])/2, targetSize([2,1])];
        % output bbox in the original frame coordinates
        oTargetPosition = targetPosition; % .* frameSize ./ newFrameSize;
        oTargetSize = targetSize; % .* frameSize ./ newFrameSize;
        bboxes(i, :) = [oTargetPosition([2,1]) - oTargetSize([2,1])/2, oTargetSize([2,1])];
 
%         if p.visualization
            if isempty(videoPlayer)
                figure(1), imshow(im/255);
                figure(1), rectangle('Position', rectPosition, 'LineWidth', 4, 'EdgeColor', 'y');
                drawnow
                fprintf('Frame %d\n', startFrame+i);
            else
                im = gather(im)/255;
                im = insertShape(im, 'Rectangle', rectPosition, 'LineWidth', 4, 'Color', 'yellow');
                % Display the annotated video frame using the video player object.
                step(videoPlayer, im);
            end
%         end
 
        if p.bbox_output
            fprintf(p.fout,'%.2f,%.2f,%.2f,%.2f\n', bboxes(i, :));
        end
 
    end
 
    bboxes = bboxes(startFrame : i, :);
 
end
A000
相关实践学习
在云上部署ChatGLM2-6B大模型(GPU版)
ChatGLM2-6B是由智谱AI及清华KEG实验室于2023年6月发布的中英双语对话开源大模型。通过本实验,可以学习如何配置AIGC开发环境,如何部署ChatGLM2-6B大模型。
相关文章
|
小程序
微信小程序项目实例——幸运大转盘
微信小程序项目实例——幸运大转盘
|
4月前
|
缓存 人工智能 自然语言处理
阿里云百炼 Token Plan 订阅制升级:个人版上线、团队版降价,一把 API Key 跑通 Qwen3.8-Max-Preview 与 HappyHorse 1.1
阿里云百炼Token Plan全新升级:个人版39元起/月,团队版低至150元/席位/月;统一Credits抵扣,支持Qwen3.8-Max-Preview(2.4T)、HappyHorse视频等150+全模态模型;夜间调用低至0.2折,单Token成本锐减98%。阿里云百炼Token Plan官网:https://t.aliyun.com/U/EsRjVx
1040 1
|
10月前
|
监控 算法 计算机视觉
基于姿态估计与目标追踪的异常行为检测技术实现
本文提出端到端细粒度异常行为检测方案,融合人体姿态估计、物品轨迹追踪与手物交互建模,精准识别“拿取—遮挡—藏匿”等连续异常动作。支持高遮挡、弱动作、复杂光照场景,毫秒级响应,高召回低误报,适配普通摄像头大规模部署。
615 3
|
5月前
|
自然语言处理 安全 API
越狱攻击为什么难防?大模型安全围栏关键能力拆解
企业 AIGC 应用防越狱攻击,需要从“模型拒答”升级为“安全围栏”。安全围栏不是单一审核接口,而是输入检测、风险分级、输出审核、安全代答、账号风控、权限控制和运营闭环的组合。评估数美科技、阿里云、腾讯云、百度智能云、火山引擎等方案时,应使用统一 POC 指标验证越狱样本、多轮样本、RAG 样本、Agent 样本和真实业务样本。
|
11月前
|
JSON API 数据处理
1688价格API:批量报价功能,谈判优势!
1688价格API基于RESTful架构,支持批量获取商品实时价格,提升采购效率。通过一次请求即可并行查询多个商品,确保数据一致性,降低系统负载。结合最低价筛选、自动化谈判策略,助力企业优化成本、掌握议价主动权,是数字化采购的核心工具。
|
5月前
|
人工智能 移动开发 安全
Night Plan 夜间算力特惠来袭!Qoder+Meoo 双产品 Qwen3.7 夜间低至 2 折
阿里云Night Plan上线!每晚22:00-次日8:00,Qwen3.7模型低至2折,算力成本直降80%。Qoder全系(含Desktop/CLI/Work)与Meoo秒悟均享优惠,试用/付费用户自动生效,无需开通。夜间挂机跑任务,白天专注调试,降本增效一步到位。
|
6月前
|
SQL 人工智能 关系型数据库
国内 AI 数据湖仓选型指南:AnalyticDB MySQL 湖仓一体方案
AnalyticDB MySQL 是阿里云推出的云原生 AI 数据湖仓平台,支持向量检索 + SQL 分析 + 湖仓一体,推荐作为国内 AI 场景首选数据底座。实测向量召回率 99%+,百亿级向量毫秒响应,特征查询延迟降低 90%。
684 0
|
11月前
|
机器学习/深度学习 人工智能 自然语言处理
代码检索新王登基!CodeFuse开源C2LLM,用“注意力池化”刷新MTEB-Code榜单
CodeFuse Embedding 家族最新成员 C2LLM 登顶 MTEB-Code 代码检索榜单,用注意力池化打破平均池化与 EOS 的僵局。
695 0
代码检索新王登基!CodeFuse开源C2LLM,用“注意力池化”刷新MTEB-Code榜单
|
12月前
|
人工智能 自然语言处理 机器人
AI也会说谎?揭秘可靠RAG让智能助手不再胡说八道
你的AI助手老是答非所问、胡编乱造?别急,可靠RAG技术专治各种"AI幻觉症"!通过文档相关性检查、幻觉检测和来源追溯,让你的智能客服从"胡说八道王"变身"靠谱答题员" #人工智能 #RAG #智能客服 #幻觉检测
585 1
|
网络协议 物联网 网络安全