Skip to content

Commit

Permalink
tidy up source files
Browse files Browse the repository at this point in the history
  • Loading branch information
suhangpro committed Feb 28, 2016
1 parent ef1aeec commit ed6ffd2
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 731 deletions.
41 changes: 23 additions & 18 deletions get_cnn_activations.m → cnn_shape_get_activations.m
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
function [ feat ] = get_cnn_activations( im, net, subWins, layers, varargin)
%GET_CNN_FEATURE Get CNN activation responses for im
function [ feat ] = cnn_shape_get_activations(im, net, layers, subWins, varargin)
%CNN_SHAPE_GET_ACTIVATIONS Get CNN activation responses for im
% im::
% image matrix, #channels (size(im,3)) must be compatible with net
% 0~255
% net::
% cnn model structure
% layers:: {'relu7'}
% can be either a structure (.name, .sizes, .index) or string array
% subWins:: [0; 1; 0; 1; 0]
% see get_augmentation_matrix.m for details
% layers:: {'fc7'}
% can be either a structure (.name, .sizes, .index) or string array
% `gpuMode`:: false
% set to true to compute on GPU

if nargin<4 || isempty(layers),
layers = {'fc7'};
if ~exist('layers','var') || isempty(layers),
layers = {'relu7'};
end
if nargin<3 || isempty(subWins),
if ~exist('subWins','var') || isempty(subWins),
subWins = get_augmentation_matrix('none');
end

opts.gpuMode = false;
opts = vl_argparse(opts,varargin);

nSubWins = size(subWins,2);
if isfield(net.layers{1},'weights'),
nChannels = size(net.layers{1}.weights{1},3);
Expand All @@ -27,16 +31,16 @@

if iscell(im),
imCell = im;
im = zeros(net.normalization.imageSize(1), ...
net.normalization.imageSize(2), ...
im = zeros(net.meta.normalization.imageSize(1), ...
net.meta.normalization.imageSize(2), ...
nChannels, ...
numel(imCell));
for i=1:numel(imCell),
if size(imCell{i},3) ~= nChannels,
error('image (%d channels) is not compatible with net (%d channels)', ...
size(imCell{i},3), nChannels);
end
im(:,:,:,i) = imresize(imCell{i}, net.normalization.imageSize(1:2));
im(:,:,:,i) = imresize(imCell{i}, net.meta.normalization.imageSize(1:2));
end
elseif size(im,3) ~= nChannels,
error('image (%d channels) is not compatible with net (%d channels)', ...
Expand All @@ -49,14 +53,11 @@
if numel(viewpoolIdx)>1,
error('More than one viewpool layers found!');
end
nViews = net.layers{viewpoolIdx}.stride;
nViews = net.layers{viewpoolIdx}.vstride;
else
nViews = 1;
end

opts.gpuMode = false;
opts = vl_argparse(opts,varargin);

if iscell(layers),
layersName = layers;
layers = struct;
Expand All @@ -67,8 +68,8 @@
[~,layers.index] = ismember(layers.name,allLayersName);
layers.index = layers.index + 1;
% sizes
im0 = zeros(net.normalization.imageSize(1), ...
net.normalization.imageSize(2), nChannels, nViews, 'single') * 255;
im0 = zeros(net.meta.normalization.imageSize(1), ...
net.meta.normalization.imageSize(2), nChannels, nViews, 'single') * 255;
if opts.gpuMode, im0 = gpuArray(im0); end
res = vl_simplenn(net,im0);
layers.sizes = zeros(3,numel(layers.name));
Expand All @@ -84,15 +85,19 @@
end

im = single(im);
averageImage = net.meta.normalization.averageImage;
if numel(averageImage)==nChannels,
averageImage = reshape(averageImage, [1 1 nChannels]);
end

for ri = 1:nSubWins,
r = subWins(1:4,ri).*[size(im,2);size(im,2);size(im,1);size(im,1)];
r = round(r);
im_ = im(max(1,r(3)):min(size(im,1),r(3)+r(4)),...
max(1,r(1)):min(size(im,2),r(1)+r(2)),:,:);
if subWins(5,ri), im_ = flipdim(im_,2); end
im_ = bsxfun(@minus, imresize(im_, net.normalization.imageSize(1:2)), ...
net.normalization.averageImage);
im_ = bsxfun(@minus, imresize(im_, net.meta.normalization.imageSize(1:2)), ...
averageImage);
if opts.gpuMode,
im_ = gpuArray(im_);
end
Expand Down
224 changes: 0 additions & 224 deletions evaluate_classification.m

This file was deleted.

2 changes: 1 addition & 1 deletion imdb_compute_cnn_features.m
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
end
end

feat = get_cnn_activations( im, net, subWins, layers, ...
feat = cnn_shape_get_activations( im, net, layers, subWins, ...
'gpuMode', opts.gpuMode);
parsave(fullfile(cacheDir, [num2str(i) '.mat']),feat);

Expand Down
58 changes: 0 additions & 58 deletions imdb_render_views.m

This file was deleted.

Loading

0 comments on commit ed6ffd2

Please sign in to comment.