-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompute_kernel_map.m
More file actions
46 lines (31 loc) · 1.35 KB
/
compute_kernel_map.m
File metadata and controls
46 lines (31 loc) · 1.35 KB
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
function [kernelTrain,kernelTest] = compute_kernel_map(dataset,datasetDir,dictDir,params,kernelType)
% Load dictionary of training images
dictFname = sprintf('dictionary_%d.mat',params.dictionarySize);
load(fullfile(dictDir,dictFname));
stackTrain = [];
stackTest = [];
for cat = 1:length(dataset)
% Initial parameters
numImgs = length(dataset(cat).files);
catPath = fullfile(datasetDir,dataset(cat).className);
% Concatenate the svm training and test features
trainIndices = dataset(cat).train_id;
testIndices = dataset(cat).test_id;
numTrainSam = sum(trainIndices);
numTestSam = sum(testIndices);
% Load training features
load(fullfile(datasetDir,dataset(cat).className,...
[params.encodingMethod '_' num2str(params.dictionarySize) '.mat']));
stackTrain = [stackTrain; HoVW_all(trainIndices,:)];
stackTest = [stackTest; HoVW_all(testIndices,:)];
end % end for categories
% Normalize
stackTrain = stackTrain./repmat(sum(stackTrain.^2,2)+eps,[1, params.dictionarySize]);
stackTest = stackTest./repmat(sum(stackTest.^2,2)+eps,[1, params.dictionarySize]);
% Compute the feature maps
psiTrain = vl_homkermap(stackTrain',1,kernelType);
psiTest = vl_homkermap(stackTest',1,kernelType);
% Compute the kernels
kernelTrain = psiTrain'*psiTrain;
kernelTest = psiTest'*psiTest;
end % end