fix Reshape layer attribute name from shape to targetShape

This commit is contained in:
Leon Chen
2016-10-05 18:26:30 -04:00
parent 39c6afc902
commit a9f6a6bd0b
2 changed files with 8 additions and 8 deletions
+5 -5
View File
@@ -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
}
}
+3 -3
View File
@@ -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()