-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexperiment.m
160 lines (128 loc) · 4.62 KB
/
experiment.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
%% Measuring and Reducing Observational Latency when Recognizing Actions
%
% Implementation of the base line method
%
% Original authors:
% Syed Z. Masood
% Chris Ellis
% Adarsh Nagaraja
% Marshall F. Tappen
% Joseph J. LaViola Jr.
% Rahul Sukthankar
%
% 2011: http://www.cs.ucf.edu/~smasood/publications/ICCV2011_LatencyReduction.pdf
% 2012: http://www.cs.ucf.edu/~smasood/publications/IJCV2012_LatencyReduction.pdf
%
% Author: Samo Sela
% e-mail: samo.sela-at-gmail.com
%%=========================================================================
%% PATH SETUP
addpath( pwd )
addpath([ pwd '/hist']);
addpath([ pwd '/libsvmhist']);
addpath([ pwd '/svm']);
% path to the dataset folder
DATA_PATH = '~/workspace/rahul/dg1public/';
%%=========================================================================
%% LOAD DATASET
fprintf('\n===========================================================\n');
fprintf('Load dataset\n');
if exist([ DATA_PATH 'DATASET.mat'],'file')
load([ DATA_PATH 'DATASET.mat']);
else
DATASET = load_data_set(DATA_PATH);
end
if(~exist('DATASET','var'))
error('Data set not loaded!');
end
% Size of the data set:
% * number of subjects
% * number of actions
% * number of records per action
%
% numSubj = size(DATASET.subj,2);
% numAct = size(DATASET.subj(1).act,2);
% numRec = size(DATASET.subj(1).act(1).rec,2);
% Animate the whole dataset:
% check_data_set( DATASET )
%fprintf('Program paused. Press enter to continue.\n');
%pause;
%%=========================================================================
%% COMPUTE FEATURES
fprintf('\n===========================================================\n');
fprintf('Compute features\n');
% Hand check:
% check_compute_features(1)
if exist([ DATA_PATH 'FEATURES.mat' ],'file')
load([ DATA_PATH 'FEATURES.mat' ]);
else
[FEATURES] = compute_all_features( DATASET, 'no', 'iccv' );
end
if(~exist('FEATURES','var'))
error('Features not computed!');
end
%fprintf('Program paused. Press enter to continue.\n');
%pause;
%%=========================================================================
%% DIVIDE DATASET -> TRAIN, TEST
fprintf('\n===========================================================\n');
fprintf('Divide dataset: train/test\n');
%[ TRAIN, TEST ] = divide_dataset_max( FEATURES, k, max )
% k - # of train examples
% (N-k) - # of test examples
% max - # of "frames" to be considered (feature vectors)
[ TRAIN, TEST ] = divide_dataset_max( FEATURES, 10, 30);
%[ TRAIN, ~ ] = divide_dataset_max( FEATURES, 16, 30);
%fprintf('Program paused. Press enter to continue.\n');
%pause;
%%=========================================================================
%% TRANSFROM DATASET
fprintf('\n===========================================================\n');
fprintf('Transform dataset\n');
% reduce data set size by selecting a subset of actions
%[F_sub, T_table] = get_sub_set( FEATURES, [4 5 10 11 12 13 2 1] );
% reformat features
[ train ] = transform_f( TRAIN );
%fprintf('Program paused. Press enter to continue.\n');
%pause;
%%=========================================================================
%% PCA
% fprintf('\n===========================================================\n');
% fprintf('PCA\n');
%{
[train_norm, mu, sigma] = feature_normalize(train);
[U, S] = pca_compute(train_norm);
r = 0.95;
[k] = pca_var_retain(S, r);
[Z] = pca_project(train_norm, U, k);
%}
% fprintf('Program paused. Press enter to continue.\n');
% pause;
%%=========================================================================
%% CLUSTER-BASED QUANTIZATION
fprintf('\n===========================================================\n');
fprintf('Cluster-based quantization\n');
% Number of clusters
K = 1000;
% Use random cluster selection
% [C] = random_cluster_selection(F_trans, K);
% [X, y] = compute_histograms(F_trans, C);
% K-means clustering
max_iters = 100;
[C, IDX] = cluster_all_features( train, K, max_iters );
[ X, y ] = compute_histograms(TRAIN, C, IDX);
% Piotr's Image & Video Matlab Toolbox
% http://vision.ucsd.edu/~pdollar/toolbox/doc/
%
%prm.display = 1
%[ IDX, C, d ] = kmeans2( train, K, prm);
%[ X, y ] = compute_histograms(TRAIN, C, IDX);
%fprintf('Program paused. Press enter to continue.\n');
%pause;
%%=========================================================================
%% SVM
fprintf('\n===========================================================\n');
fprintf('SVM\n');
[svm_model, predicted_label, accuracy, decision_values ] = train_svm(X, y);
fprintf('\n===========================================================\n');
%%=========================================================================