mirror of
https://github.com/wassname/keras-js.git
synced 2026-09-11 12:20:53 +08:00
fix Reshape layer attribute name from shape to targetShape
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user