Skip to content

Commit

Permalink
TDD compatibel with cudnn2.0 and above
Browse files Browse the repository at this point in the history
  • Loading branch information
wanglimin committed Dec 24, 2015
1 parent 8ae2c24 commit af0157e
Show file tree
Hide file tree
Showing 61 changed files with 789 additions and 4,793 deletions.
1 change: 1 addition & 0 deletions FeatureMapNormalization.m
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
cnn_feature1 = bsxfun(@rdivide,cnn_feature1,max(cnn_feature1,[],1)+eps);
cnn_feature1 = reshape(cnn_feature1,r,c,t,f);
cnn_feature1 = permute(cnn_feature1,[1,2,4,3]);

cnn_feature2 = bsxfun(@rdivide,cnn_feature,max(cnn_feature,[],3)+eps);

end
83 changes: 0 additions & 83 deletions FlowCNNFeature.m

This file was deleted.

53 changes: 0 additions & 53 deletions RGBCNNFeature.m

This file was deleted.

47 changes: 47 additions & 0 deletions SpatialCNNFeature.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
function [FCNNFeature_c5, FCNNFeature_c4] = SpatialCNNFeature(vid_name, net, NUM_HEIGHT, NUM_WIDTH)

% Input video
vidObj = VideoReader(vid_name);

duration = vidObj.NumberOfFrame;
video = zeros(NUM_HEIGHT, NUM_WIDTH, 3, duration,'single');
for i = 1 : duration
tmp = read(vidObj,i);
video(:,:,:,i) = imresize(tmp, [NUM_HEIGHT, NUM_WIDTH], 'bilinear');
end


d = load('VGG_mean');
IMAGE_MEAN = d.image_mean;
IMAGE_MEAN = imresize(IMAGE_MEAN,[NUM_HEIGHT,NUM_WIDTH]);
video = video(:,:,[3,2,1],:);
video = bsxfun(@minus,video,IMAGE_MEAN);
video = permute(video,[2,1,3,4]);

batch_size = 40;
num_images = size(video,4);
num_batches = ceil(num_images/batch_size);

FCNNFeature_c5 = [];
FCNNFeature_c4 = [];

images = zeros(NUM_WIDTH, NUM_HEIGHT, 3, batch_size, 'single');
for bb = 1 : num_batches
range = 1 + batch_size*(bb-1): min(num_images,batch_size*bb);
tmp = video(:,:,:,range);
images(:,:,:,1:size(tmp,4)) = tmp;

net.blobs('data').set_data(images);
net.forward_prefilled();
feature_c5 = permute(net.blobs('conv5').get_data(),[2,1,3,4]);
feature_c4 = permute(net.blobs('conv4').get_data(),[2,1,3,4]);

if isempty(FCNNFeature_c5)
FCNNFeature_c5 = zeros(size(feature_c5,1), size(feature_c5,2), size(feature_c5,3), num_images, 'single');
FCNNFeature_c4 = zeros(size(feature_c4,1), size(feature_c4,2), size(feature_c4,3), num_images, 'single');
end
FCNNFeature_c5(:,:,:,range) = feature_c5(:,:,:,mod(range-1,batch_size)+1);
FCNNFeature_c4(:,:,:,range) = feature_c4(:,:,:,mod(range-1,batch_size)+1);
end

end
11 changes: 11 additions & 0 deletions TDD.m
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@

function [feature] = TDD(inf,tra,cnn_feature,scale_x,scale_y,num_cell)
% TDD: perform trajectory pooling over convolutional feature maps.
% Input:
% inf: information of trajectories from iDTs (10*N)
% traj: extracted trajectories (2L*N)
% cnn_feature: cnn feature maps (convlutional layers: W*H*C*L)
% scale_x: width ratio
% scale_y: height ratio
% num_cell: the number of cell in temporal dimension
% Output:
% feature: trajectory pooled descriptors ((C*NUM_CELL) *N)

if ~isempty(inf)
ind = inf(7,:)==1;
Expand Down
14 changes: 3 additions & 11 deletions TemporalCNNFeature.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [FCNNFeature_c5, FCNNFeature_c4, FCNNFeature_c3, FCNNFeature_p2] = TemporalCNNFeature(vid_name, net, NUM_HEIGHT, NUM_WIDTH)
function [FCNNFeature_c4, FCNNFeature_c3] = TemporalCNNFeature(vid_name, net, NUM_HEIGHT, NUM_WIDTH)

L = 10;
% Input video
Expand All @@ -24,10 +24,8 @@
num_images = size(video,4);
num_batches = ceil(num_images/batch_size);

FCNNFeature_c5 = [];
FCNNFeature_c4 = [];
FCNNFeature_c3 = [];
FCNNFeature_p2 = [];

for bb = 1 : num_batches
range = 1 + batch_size*(bb-1): min(num_images,batch_size*bb);
Expand All @@ -41,21 +39,15 @@

net.blobs('data').set_data(images);
net.forward_prefilled();
feature_c5 = permute(net.blobs('conv5').get_data(),[2,1,3,4]);
feature_c4 = permute(net.blobs('conv4').get_data(),[2,1,3,4]);
feature_c3 = permute(net.blobs('conv3').get_data(),[2,1,3,4]);
feature_p2 = permute(net.blobs('pool2').get_data(),[2,1,3,4]);

if isempty(FCNNFeature_c5)
FCNNFeature_c5 = zeros(size(feature_c5,1), size(feature_c5,2), size(feature_c5,3), num_images, 'single');
if isempty(FCNNFeature_c4)
FCNNFeature_c4 = zeros(size(feature_c4,1), size(feature_c4,2), size(feature_c4,3), num_images, 'single');
FCNNFeature_c3 = zeros(size(feature_c3,1), size(feature_c3,2), size(feature_c3,3), num_images, 'single');
FCNNFeature_p2 = zeros(size(feature_p2,1), size(feature_p2,2), size(feature_p2,3), num_images, 'single');
end
FCNNFeature_c5(:,:,:,range) = feature_c5(:,:,:,mod(range-1,batch_size)+1);
FCNNFeature_c4(:,:,:,range) = feature_c4(:,:,:,mod(range-1,batch_size)+1);
FCNNFeature_c3(:,:,:,range) = feature_c3(:,:,:,mod(range-1,batch_size)+1);
FCNNFeature_p2(:,:,:,range) = feature_p2(:,:,:,mod(range-1,batch_size)+1);
FCNNFeature_c3(:,:,:,range) = feature_c3(:,:,:,mod(range-1,batch_size)+1);
end

end
Empty file modified extract_tdd.m
100755 → 100644
Empty file.
Empty file modified flow_mean.mat
100755 → 100644
Empty file.
Empty file modified import_idt.m
100755 → 100644
Empty file.
47 changes: 0 additions & 47 deletions matcaffe_init.m

This file was deleted.

Loading

0 comments on commit af0157e

Please sign in to comment.