Skip to content

Commit

Permalink
Cut down memory use
Browse files Browse the repository at this point in the history
The grad values will only be allocated at training time so that
forwarding a network will need less memory.
  • Loading branch information
suquark committed Jan 24, 2017
1 parent e1fc613 commit b0dd856
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 74 deletions.
64 changes: 0 additions & 64 deletions cnnutil.js

This file was deleted.

2 changes: 1 addition & 1 deletion convnet.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { Vol } from 'vol.js';
export { Net } from 'topology.js';
export { Net } from 'topology/vallia.js';
5 changes: 3 additions & 2 deletions layers/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ class Layer {

compile(options) {
// setup optimizers
this.updated.forEach(function(w) {
w.optimizer = get_optimizer(w.length, options);
this.updated.forEach(function(V) {
V.optimizer = get_optimizer(V.size, options);
V.dw = V.zeros_like();
});
}

Expand Down
File renamed without changes.
15 changes: 8 additions & 7 deletions vol.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class Vol {
}
}

this.dw = this.zeros_like();
this.length = this.w.length;
// this.dw = this.zeros_like(); -- save memory, allocmem at training
this.length = this.size;
}


Expand Down Expand Up @@ -56,16 +56,17 @@ class Vol {
var ix = ((this.sx * y) + x) * this.depth + d;
this.dw[ix] += v;
}
max(limit=V.w.length) {
if (limit === V.w.length)
return Math.max.apply(Math, V.w);
max(limit=this.size) {
if (limit === this.size)
return Math.max.apply(Math, this.w);

var amax = V.w[0];
var amax = this.w[0];
for(let i = 1; i < limit; i++) {
if(as[i] > amax) amax = as[i];
if(w[i] > amax) amax = w[i];
}
return amax;
}

cloneAndZero() { return new Vol(this.sx, this.sy, this.depth, 0.0); }
clone() {
var V = new Vol(this.sx, this.sy, this.depth, 0.0);
Expand Down

0 comments on commit b0dd856

Please sign in to comment.