Skip to content

Commit

Permalink
Few changes to make CNNs work on Octave.
Browse files Browse the repository at this point in the history
  • Loading branch information
albertoandreottiATgmail committed Nov 21, 2013
1 parent 0971101 commit 8deea58
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 133 deletions.
7 changes: 6 additions & 1 deletion CNN/cnnbp.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@
if strcmp(net.layers{l}.type, 'c')
for j = 1 : numel(net.layers{l}.a)
for i = 1 : numel(net.layers{l - 1}.a)
net.layers{l}.dk{i}{j} = custom_convn(flipall(net.layers{l - 1}.a{i}), net.layers{l}.d{j}, 'valid') / size(net.layers{l}.d{j}, 3);
%ugly if, until convn() is fixed in Octave.
if(isOctave())
net.layers{l}.dk{i}{j} = convn_valid(flipall(net.layers{l - 1}.a{i}), net.layers{l}.d{j}) / size(net.layers{l}.d{j}, 3);
else
net.layers{l}.dk{i}{j} = convn(flipall(net.layers{l - 1}.a{i}), net.layers{l}.d{j}, 'valid') / size(net.layers{l}.d{j}, 3);
end
end
net.layers{l}.db{j} = sum(net.layers{l}.d{j}(:)) / size(net.layers{l}.d{j}, 3);
end
Expand Down
26 changes: 12 additions & 14 deletions CNN/cnntrain.m
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@

function net = cnntrain(net, x, y, opts)
m = size(x, 3);

This comment has been minimized.

Copy link
@moahaimen

moahaimen Apr 26, 2018

what do u mean here ? please

numbatches = m / opts.batchsize;

This comment has been minimized.

Copy link
@moahaimen

moahaimen Apr 26, 2018

and here?

if rem(numbatches, 1) ~= 0
error('numbatches not integer');
end

net.rL = [];
for i = 1 : opts.numepochs
disp(['epoch ' num2str(i) '/' num2str(opts.numepochs)]);
tic;
kk = randperm(m);

This comment has been minimized.

Copy link
@moahaimen

moahaimen Apr 26, 2018

and here what is happening

%how many processes?
numWorkers = 4
pids = 0:numWorkers-1;
starts = pids * numbatches / numWorkers

%process starts
turn = 0;
for l = 1 : numbatches
batch_x = x(:, :, kk((l - 1) * opts.batchsize + 1 : l * opts.batchsize));

This comment has been minimized.

Copy link
@moahaimen

moahaimen Apr 26, 2018

what does these 2 lines means in detail please i am coding it but i dont understand it thank you

batch_y = y(:, kk((l - 1) * opts.batchsize + 1 : l * opts.batchsize));

pararrayfun(numWorkers,
@(starts, pids)process_batch(x, y, kk, net, turn, starts, (numbatches/numWorkers), pids, numWorkers, opts),
starts,
pids,
"ErrorHandler" , @eh);
net = cnnff(net, batch_x);
net = cnnbp(net, batch_y);
net = cnnapplygrads(net, opts);
if isempty(net.rL)
net.rL(1) = net.L;
end
net.rL(end + 1) = 0.99 * net.rL(end) + 0.01 * net.L;
end
toc;
end

end
20 changes: 4 additions & 16 deletions CNN/convn_valid.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,10 @@
%equivalent to convn(A,B, 'valid')

function result = convn_valid(A, B)

m = size(A, 1) - size(B, 1) + 1;
numWorkers = 2;

function retcode = eh(error)
a = error
retcode = zeros(25, 1);
result = zeros(m, m);
B = flipdim(B,3);
for j=1:size(A, 3)
result += conv2(A(:,:,j),B(:,:,j), 'valid');
end

%each worker will write its output to specific part of the output
chunkSize = size(A,3)/numWorkers;
result = pararrayfun(numWorkers, @(i)convadd(A, B, m, i, chunkSize), 0:numWorkers-1, "ErrorHandler" , @eh);

for j=m:numWorkers*m:m
result(:,1:m) += result(:,j+1:j+m);
end

result = result(1:m,1:m);
end
87 changes: 0 additions & 87 deletions data/generate_mfcc.m

This file was deleted.

15 changes: 0 additions & 15 deletions data/readhtk.m

This file was deleted.

3 comments on commit 8deea58

@G33kyKitty
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, I am new to cnn.

Just started to use these codes.

I am a bit confused on which code to run first and what arguments to use.

Grateful if someone could help me.

@wajihullahbaig
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You dont post comments here :) Try using the test folder to run the programs.

@moahaimen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi i need explinations for what the code is doing please i left comments to code please answer me
thank you

Please sign in to comment.