Skip to content

Commit 1db6764

Browse files
committed
cnn_train.m: fixes a bug in computing the errors when using more than one sub batch
1 parent 80ef8a5 commit 1db6764

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

examples/cnn_train.m

+3-2
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@
250250
batchSize = min(opts.batchSize, numel(subset) - t + 1) ;
251251
batchTime = tic ;
252252
numDone = 0 ;
253+
error = [] ;
253254
for s=1:opts.numSubBatches
254255
% get this image batch and prefetch the next
255256
batchStart = t + (labindex-1) + (s-1) * numlabs ;
@@ -283,9 +284,9 @@
283284
'sync', opts.sync) ;
284285

285286
% accumulate training errors
286-
error = [...
287+
error = sum([error, [...
287288
sum(double(gather(res(end).x))) ;
288-
reshape(opts.errorFunction(opts, labels, res),[],1) ; ] ;
289+
reshape(opts.errorFunction(opts, labels, res),[],1) ; ]],2) ;
289290
numDone = numDone + numel(batch) ;
290291
end
291292

0 commit comments

Comments
 (0)