MDNet(multi domain CNN用于视觉跟踪)--源代码详解--mdnet_features_fcX.m

该函数,输入全连接网络的网络参数、卷积层网络的输出,计算全连接网络的计算结果,源文件如下:

function [ feat ] = mdnet_features_fcX(net, ims, opts)
% MDNET_FEATURES_FCX
% Compute CNN scores from input features.
%
% Hyeonseob Nam, 2015
% 

n = size(ims,4);
nBatches = ceil(n/opts.batchSize);% ceil表示进一法

net.layers = net.layers(1:end-1);% 最后一层不需要计算
for i=1:nBatches
    
    batch = ims(:,:,:,opts.batchSize*(i-1)+1:min(end,opts.batchSize*i));% 为每个batch取数据
    if(opts.useGpu)
        batch = gpuArray(batch);
    end
    
    res = vl_simplenn(net, batch, [], [], ...
        'disableDropout', true, ...
        'conserveMemory', true, ...
        'sync', true) ;% 禁用了dropout
    
    f = gather(res(end).x) ;% 取最后一层结果的数据
    if ~exist('feat','var')
        feat = zeros(size(f,1),size(f,2),size(f,3),n,'single');
    end
    feat(:,:,:,opts.batchSize*(i-1)+1:min(end,opts.batchSize*i)) = f;% 把计算得到的结果放到变量feat中
    
end














猜你喜欢

转载自blog.csdn.net/sloanqin/article/details/55051774