-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakebatches.m
executable file
·66 lines (54 loc) · 1.77 KB
/
makebatches.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
function [batchdata,batchtargets]=makebatches(TrainingSet,ScratchFolder,lastlag,batchsize)
% This is an essential function which prepares the training set by postprocessing the feature
% files in the scratch folder. It is called by the TrainingAlgorithm.
% m-file.
% Aggelos Pikrakis, pikrakis@unipi.gr
digitdata=[];
targets=[];
genres=detectGenres(TrainingSet);
NumOfClasses=length(genres);
fin=fopen(TrainingSet);
while ~feof(fin)
filestr=fscanf(fin,'%s\t',1);
indfilesep=strfind(filestr,filesep);
indfilesep=indfilesep(end)+1;
inddot=strfind(filestr,'.');
if isempty(inddot)
inddot=length(filestr);
else
inddot=inddot(end)-1;
end
foutname=[ScratchFolder filesep filestr(indfilesep:inddot) '.features.txt'];
D=load(foutname);
D=D(:,1:lastlag);
for m=1:size(D,1)
D(m,:)=expFeature(D(m,:),0.005);
end
digitdata = [digitdata; D];
blabel=fscanf(fin,'%s\n',1);
i=1;
while i<=length(genres)
if strcmp(genres{i},blabel)
break;
else
i=i+1;
end
end
labelid=zeros(1,NumOfClasses);
labelid(i)=1;
targets = [targets; repmat(labelid, size(D,1), 1)];
end
fclose(fin);
totnum=size(digitdata,1);
fprintf(1, 'Size of the training dataset= %5d \n', totnum);
rand('state',sum(100*clock()));
randomorder=randperm(totnum);
numbatches=floor(totnum/batchsize)-1;
numdims = size(digitdata,2);
batchdata = zeros(batchsize, numdims, numbatches);
batchtargets = zeros(batchsize, NumOfClasses, numbatches);
for b=1:numbatches
batchdata(:,:,b) = digitdata(randomorder(1+(b-1)*batchsize:b*batchsize), :);
batchtargets(:,:,b) = targets(randomorder(1+(b-1)*batchsize:b*batchsize), :);
end;
save([ScratchFolder filesep 'TrainingData'],'genres');