mirror of
https://github.com/wassname/keras-js.git
synced 2026-09-09 11:25:25 +08:00
49 lines
2.1 KiB
JavaScript
49 lines
2.1 KiB
JavaScript
/* eslint-env browser, mocha */
|
|
|
|
describe('core layer: Permute', function () {
|
|
const assert = chai.assert
|
|
const styles = testGlobals.styles
|
|
const logTime = testGlobals.logTime
|
|
const stringifyCondensed = testGlobals.stringifyCondensed
|
|
const approxEquals = KerasJS.testUtils.approxEquals
|
|
const layers = KerasJS.layers
|
|
|
|
before(function () {
|
|
console.log('\n%ccore layer: Permute', styles.h1)
|
|
})
|
|
|
|
it('[core.Permute.0] should be able to go from shape [3, 2] -> [2, 3]', function () {
|
|
const key = 'core.Permute.0'
|
|
console.log(`\n%c[${key}] shape [3, 2] -> [2, 3]`, styles.h3)
|
|
let testLayer = new layers.Permute({ dims: [2, 1] })
|
|
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()
|
|
t = testLayer.call(t)
|
|
const endTime = performance.now()
|
|
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
|
logTime(startTime, endTime)
|
|
const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
|
|
const shapeExpected = TEST_DATA[key].expected.shape
|
|
assert.deepEqual(t.tensor.shape, shapeExpected)
|
|
assert.isTrue(approxEquals(t.tensor, dataExpected))
|
|
})
|
|
|
|
it('[core.Permute.1] should be able to go from shape [2, 3, 4] -> [4, 3, 2]', function () {
|
|
const key = 'core.Permute.1'
|
|
console.log(`\n%c[${key}] shape [2, 3, 4] -> [4, 3, 2]`, styles.h3)
|
|
let testLayer = new layers.Permute({ dims: [3, 2, 1] })
|
|
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()
|
|
t = testLayer.call(t)
|
|
const endTime = performance.now()
|
|
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
|
logTime(startTime, endTime)
|
|
const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
|
|
const shapeExpected = TEST_DATA[key].expected.shape
|
|
assert.deepEqual(t.tensor.shape, shapeExpected)
|
|
assert.isTrue(approxEquals(t.tensor, dataExpected))
|
|
})
|
|
})
|