Permalink
Browse files

added CNN test and cleaned up

  • Loading branch information...
1 parent 45ef96c commit 5f8e1af4a6c2db9560bb8b5b7a58f0bd20d12393 @rasmusbergpalm committed Sep 30, 2012
Showing with 17 additions and 13 deletions.
  1. +0 −3 CNN/cnntrain.m
  2. +0 −1 NN/nnff.m
  3. +1 −7 NN/nntrain.m
  4. +1 −2 SAE/saetrain.m
  5. +15 −0 tests/test_cnn_gradients_are_numerically_correct.m
View
@@ -15,9 +15,6 @@
net = cnnff(net, batch_x);
net = cnnbp(net, batch_y);
-% disp('checking grads');
-% cnnnumgradcheck(net,batch_x,batch_y);
-% disp('done.');
net = cnnapplygrads(net, opts);
if isempty(net.rL)
net.rL(1) = net.L;
View
@@ -13,5 +13,4 @@
net.e = y - net.a{n};
net.L = 1/2 * sum(sum(net.e .^ 2)) / m;
-% net.L = 0.5 * sum(sum(net.e .^ 2)) / m;
end
View
@@ -22,13 +22,7 @@
batch_y = y(kk((l - 1) * batchsize + 1 : l * batchsize), :);
nn = nnff(nn, batch_x, batch_y);
- nn = nnbp(nn);
-
-% Enable to verify numerical correcness of algorithm
-% disp 'Performing numerical gradient checking ...';
-% nnchecknumgrad(nn, batch_x, batch_y);
-% disp 'No errors found ...';
-
+ nn = nnbp(nn);
nn = nnapplygrads(nn);
if n == 1
View
@@ -1,7 +1,6 @@
function sae = saetrain(sae, x, opts)
for i = 1 : numel(sae.ae);
-% disp(['Training AE ' num2str(i) '/' num2str(numel(sae.ae))]);
- printf('Training AE %d / %d.', num2str(i), num2str(numel(sae.ae)));
+ disp(['Training AE ' num2str(i) '/' num2str(numel(sae.ae))]);
sae.ae{i} = nntrain(sae.ae{i}, x, x, opts);
t = nnff(sae.ae{i}, x, x);
x = t.a{2};
@@ -0,0 +1,15 @@
+function test_cnn_gradients_are_numerically_correct
+batch_x = rand(28,28,5);
+batch_y = rand(10,5);
+cnn.layers = {
+ struct('type', 'i') %input layer
+ struct('type', 'c', 'outputmaps', 2, 'kernelsize', 5) %convolution layer
+ struct('type', 's', 'scale', 2) %sub sampling layer
+ struct('type', 'c', 'outputmaps', 2, 'kernelsize', 5) %convolution layer
+ struct('type', 's', 'scale', 2) %subsampling layer
+};
+cnn = cnnsetup(cnn, batch_x, batch_y);
+
+cnn = cnnff(cnn, batch_x);
+cnn = cnnbp(cnn, batch_y);
+cnnnumgradcheck(cnn, batch_x, batch_y);

0 comments on commit 5f8e1af

Please sign in to comment.