From a9f6a6bd0b068fa4d4907c294bd19174b659a595 Mon Sep 17 00:00:00 2001 From: Leon Chen Date: Wed, 5 Oct 2016 18:26:30 -0400 Subject: [PATCH] fix Reshape layer attribute name from shape to targetShape --- src/layers/core/Reshape.js | 10 +++++----- test/core/Reshape.js | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/layers/core/Reshape.js b/src/layers/core/Reshape.js index 12d836a..61ce31b 100644 --- a/src/layers/core/Reshape.js +++ b/src/layers/core/Reshape.js @@ -11,16 +11,16 @@ import flattenDeep from 'lodash/flattenDeep' export default class Reshape extends Layer { /** * Creates a Reshape layer - * @param {number[]} attrs.shape + * @param {number[]} attrs.targetShape */ constructor (attrs = {}) { super(attrs) this.layerClass = 'Reshape' const { - shape = [] + targetShape = [] } = attrs - this.shape = shape + this.targetShape = targetShape } /** @@ -29,10 +29,10 @@ export default class Reshape extends Layer { * @returns {Tensor} x */ call (x) { - if (this.shape.reduce((a, b) => a * b, 1) !== x.tensor.size) { + if (this.targetShape.reduce((a, b) => a * b, 1) !== x.tensor.size) { throw new Error(`${this.name} [Reshape layer] The total size of new array must be unchanged in reshape layer.`) } - x.tensor = ndarray(new x._type(flattenDeep(unpack(x.tensor))), this.shape) + x.tensor = ndarray(new x._type(flattenDeep(unpack(x.tensor))), this.targetShape) return x } } diff --git a/test/core/Reshape.js b/test/core/Reshape.js index 9d7f771..c8b5ffe 100644 --- a/test/core/Reshape.js +++ b/test/core/Reshape.js @@ -15,7 +15,7 @@ describe('core layer: Reshape', function () { it('[core.Reshape.0] should be able to go from shape [6] -> [2, 3]', function () { const key = 'core.Reshape.0' console.log(`\n%c[${key}] shape [6] -> [2, 3]`, styles.h3) - let testLayer = new layers.Reshape({ shape: [2, 3] }) + let testLayer = new layers.Reshape({ targetShape: [2, 3] }) let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape) console.log('%cin', styles.h4, stringifyCondensed(t.tensor)) const startTime = performance.now() @@ -32,7 +32,7 @@ describe('core layer: Reshape', function () { it('[core.Reshape.1] should be able to go from shape [3, 2] -> [6]', function () { const key = 'core.Reshape.1' console.log(`\n%c[${key}] shape [3, 2] -> [6]`, styles.h3) - let testLayer = new layers.Reshape({ shape: [6] }) + let testLayer = new layers.Reshape({ targetShape: [6] }) let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape) console.log('%cin', styles.h4, stringifyCondensed(t.tensor)) const startTime = performance.now() @@ -49,7 +49,7 @@ describe('core layer: Reshape', function () { it('[core.Reshape.2] should be able to go from shape [3, 2, 2] -> [4, 3]', function () { const key = 'core.Reshape.2' console.log(`\n%c[${key}] shape [3, 2, 2] -> [4, 3]`, styles.h3) - let testLayer = new layers.Reshape({ shape: [4, 3] }) + let testLayer = new layers.Reshape({ targetShape: [4, 3] }) let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape) console.log('%cin', styles.h4, stringifyCondensed(t.tensor)) const startTime = performance.now()