-
Notifications
You must be signed in to change notification settings - Fork 75
/
TDD.m
51 lines (40 loc) · 1.38 KB
/
TDD.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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;
inf = inf(:,ind);
tra = tra(:,ind);
end
if ~isempty(inf)
NUM_DIM = size(cnn_feature,3);
NUM_DES = size(inf,2);
TRA_LEN = size(tra,1)/2;
num_fea = TRA_LEN / num_cell;
pos = reshape(tra,2,[])-1;
pos = round(bsxfun(@rdivide,pos,[scale_x;scale_y]) + 1);
pos = bsxfun(@max,pos,[1;1]);
pos = bsxfun(@min,pos,[size(cnn_feature,2);size(cnn_feature,1)]);
pos = reshape(pos,TRA_LEN*2,[]);
cnn_feature = permute(cnn_feature,[1,2,4,3]);
offset = [TRA_LEN-1:-1:0];
size_mat = [size(cnn_feature,1),size(cnn_feature,2),size(cnn_feature,3)];
cnn_feature = reshape(cnn_feature,[],NUM_DIM);
cur_x = pos(1:2:end,:);
cur_y = pos(2:2:end,:);
cur_t = bsxfun(@minus,inf(1,:),offset');
tmp = cnn_feature(sub2ind(size_mat,cur_y,cur_x,cur_t),:)';
tmp = reshape(tmp,NUM_DIM,num_fea,[]);
feature = reshape(sum(tmp,2),[],NUM_DES);
else
feature = [];
end
end