forked from msavva/ReVision
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetTxtAll.m
93 lines (79 loc) · 2.45 KB
/
getTxtAll.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
%% Set Range
%clear;
setOpt;
rfs = 6;%5:1:20;
DIMS = 128;%[64 128 256];
%rfd = combvec(rfs,DIMS)
% combvec requires neural network toolbox so do it manually instead
rfd = nan(2,length(rfs)*length(DIMS));
for n = 1:length(rfs)
for m = 1:length(DIMS)
rfd(:,n+length(rfs)*(m-1)) = [rfs(n); DIMS(m)];
end
end
for i=1:size(rfd,2)
%% Get iteration variables
rf = rfd(1,i);
d = rfd(2,i);
setName = strcat('rf',num2str(rf),'_d',num2str(d));
opt.rfSize = rf;
opt.DIM = [d d 1];
%% Load DataSet
data = DataSet(opt);
ws = data.getWSFull();
tic;
%% Learn image features
ps = PatchSet(opt, ws.X, ws.Y);
ps.kmeansCentroids();
% ps.showCentroids();
% Compute feature vectors
fs = ps.extractFeatures(ws.X,1);
featureNames = strnum('centroid',4*opt.Ncentroids);
if (opt.useTextFeatures)
%% Get text features
tws = data.getTextFeatureSetVectors(3);
%% Normalize text features and concatenate with image feature vectors
tXmean = mean(tws.X);
tXsd = sqrt(var(tws.X)+0.01);
tXs = bsxfun(@rdivide, bsxfun(@minus, tws.X, tXmean), tXsd);
% tXs = tws.X;
X = [fs.XCs(:,1:end-1) tXs];
Y = ws.Y;
featureNames = [featureNames; data.cat{1}.txt(1).featureVectorLabels(3)];
else
X = fs.XCs(:,1:end-1);
Y = ws.Y;
end
%% Add category indicator binary variables
% catIndicators = bsxfun(@eq,ws.Y,1:data.Ncategories);
% catIndicatorNames = strcat('is_',opt.catDirs);
% X = [X catIndicators];
% featureNames = [featureNames; catIndicatorNames'];
%% Add filename tags
% cats = [data.cat{:}];
% txts = [cats.txt]';
% fullnames = char(txts.fname);
% fnames = zeros(data.NtotalImages,1);
% for j=1:data.NtotalImages
% fnames(j) = filenameToIndex(fullnames(j,:));
% end
% X = [X fnames];
% featureNames = [featureNames; 'filenameIndex'];
% Add is3D tag
if (opt.addIs3Dtag)
featureNames = [featureNames; 'is3D'];
X = [X ~cellfun('isempty',strfind(ws.C,'3D'))];
end
%% Output
if (opt.useTextFeatures)
prefix = '../../feats_txt_';
else
prefix = '../../feats_';
end
filename = strcat(prefix, setName, '.arff');
data.featuresToARFF(filename, X, Y, setName, featureNames);
fprintf('Saved to %s\n', filename);
%% Save feature matrix and patch set
save revisionFeats X Y ps fs;
end
totalTime = toc;