From cbdce83f1ecfe0a0b645b58bff8cbcf59620b72f Mon Sep 17 00:00:00 2001 From: Leon Chen Date: Tue, 20 Sep 2016 11:24:55 -0400 Subject: [PATCH] update Model class --- src/Input.js | 1 + src/Model.js | 3 ++- src/Tensor.js | 4 +--- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Input.js b/src/Input.js index a74c7a6..23fdada 100644 --- a/src/Input.js +++ b/src/Input.js @@ -10,6 +10,7 @@ export default class Input extends Layer { */ constructor (attrs = {}) { super(attrs) + this.layerClass = 'Input' const { shape = [] diff --git a/src/Model.js b/src/Model.js index 5a4567d..1105974 100644 --- a/src/Model.js +++ b/src/Model.js @@ -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 } diff --git a/src/Tensor.js b/src/Tensor.js index b37d281..95e57a4 100644 --- a/src/Tensor.js +++ b/src/Tensor.js @@ -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