update Model class

This commit is contained in:
Leon Chen
2016-09-20 11:24:55 -04:00
parent 86f03882ec
commit cbdce83f1e
3 changed files with 4 additions and 4 deletions
+1
View File
@@ -10,6 +10,7 @@ export default class Input extends Layer {
*/
constructor (attrs = {}) {
super(attrs)
this.layerClass = 'Input'
const {
shape = []
+2 -1
View File
@@ -283,7 +283,8 @@ export default class Model {
if (inboundLayers.length !== 1) {
throw new Error(`Layer name ${currentLayer.name} has ${inboundLayers.length} inbound nodes, but is not a Merge layer.`)
}
currentLayer.result = currentLayer.call(new Tensor(inboundLayers[0].result.tensor.data, inboundLayers[0].result.tensor.shape, { gpu: this.gpu }))
const prevLayerResult = inboundLayers[0].result
currentLayer.result = currentLayer.call(new Tensor(prevLayerResult.tensor.data, prevLayerResult.tensor.shape, { gpu: this.gpu }))
}
currentLayer.hasResult = true
}
+1 -3
View File
@@ -20,11 +20,9 @@ export default class Tensor {
constructor (data, shape, options = {}) {
this._type = options.type || Float32Array
if (data && data.length && data instanceof this._type) {
if (data && data.length && (data instanceof this._type || data instanceof Array)) {
checkShape(data, shape)
this.tensor = ndarray(data, shape)
} else if (data && data.length && data instanceof Array) {
checkShape(data, shape)
this.tensor = ndarray(new this._type(data), shape)
} else if (!data.length && shape.length) {
// if shape present but data not provided, initialize with 0s