1. 程式人生 > >MDNet(multi domain CNN用於視覺跟蹤)--原始碼詳解--mdnet_features_fcX.m

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