mirror of
https://github.com/wassname/keras-js.git
synced 2026-09-12 12:33:40 +08:00
update tests
This commit is contained in:
+12
-3
@@ -16,10 +16,19 @@
|
||||
<script src="/dist/keras.js"></script>
|
||||
|
||||
<script>mocha.setup('bdd')</script>
|
||||
<script src="/test/globals.js"></script>
|
||||
|
||||
<script src="/test/utils/globals.js"></script>
|
||||
|
||||
<script src="/test/data/activations.js"></script>
|
||||
<script src="/test/data/advanced_activations.js"></script>
|
||||
<script src="/test/data/core.js"></script>
|
||||
<script src="/test/data/convolutional.js"></script>
|
||||
|
||||
<script src="/test/activations.js"></script>
|
||||
<script src="/test/layers/core.js"></script>
|
||||
<script src="/test/layers/advanced_activations.js"></script>
|
||||
<script src="/test/advanced_activations.js"></script>
|
||||
<script src="/test/core.js"></script>
|
||||
<script src="/test/convolutional.js"></script>
|
||||
|
||||
<script>
|
||||
// mocha.checkLeaks();
|
||||
mocha.globals(['jQuery']);
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
"KerasJS",
|
||||
"chai",
|
||||
"testGlobals",
|
||||
"TEST_DATA",
|
||||
"weblas",
|
||||
"GPU",
|
||||
"performance"
|
||||
|
||||
+150
-125
@@ -21,32 +21,34 @@ describe('activations', function () {
|
||||
console.log('\n%csoftmax', styles.h2)
|
||||
})
|
||||
|
||||
it('should work for 1D tensor', function () {
|
||||
console.log('\n%c1D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
it('[activations.softmax.0] should work for 1D tensor', function () {
|
||||
const key = 'activations.softmax.0'
|
||||
console.log(`\n%c[${key}] 1D`, styles.h3)
|
||||
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()
|
||||
activations.softmax(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.067194, 0.082071, 0.110784, 0.0608, 0.182652, 0.4965])
|
||||
const shapeExpected = [6]
|
||||
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('should work for 2D tensor', function () {
|
||||
console.log('\n%c2D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], [2, 6])
|
||||
it('[activations.softmax.1] should work for 2D tensor', function () {
|
||||
const key = 'activations.softmax.1'
|
||||
console.log(`\n%c[${key}] 2D`, styles.h3)
|
||||
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()
|
||||
activations.softmax(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.067194, 0.082071, 0.110784, 0.0608, 0.182652, 0.4965, 0.107768, 0.149902, 0.11105, 0.247147, 0.082268, 0.301865])
|
||||
const shapeExpected = [2, 6]
|
||||
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))
|
||||
})
|
||||
@@ -61,47 +63,50 @@ describe('activations', function () {
|
||||
console.log('\n%csoftplus', styles.h2)
|
||||
})
|
||||
|
||||
it('should work for 1D tensor', function () {
|
||||
console.log('\n%c1D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
it('[activations.softplus.0] should work for 1D tensor', function () {
|
||||
const key = 'activations.softplus.0'
|
||||
console.log(`\n%c[${key}] 1D`, styles.h3)
|
||||
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()
|
||||
activations.softplus(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.693147, 0.798139, 0.974077, 0.644397, 1.313262, 2.126928])
|
||||
const shapeExpected = [6]
|
||||
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('should work for 2D tensor', function () {
|
||||
console.log('\n%c2D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], [2, 6])
|
||||
it('[activations.softplus.1] should work for 2D tensor', function () {
|
||||
const key = 'activations.softplus.1'
|
||||
console.log(`\n%c[${key}] 2D`, styles.h3)
|
||||
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()
|
||||
activations.softplus(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.693147, 0.798139, 0.974077, 0.644397, 1.313262, 2.126928, 0.67826, 0.854355, 0.693147, 1.171101, 0.554355, 1.313262])
|
||||
const shapeExpected = [2, 6]
|
||||
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('should work for 3D tensor', function () {
|
||||
console.log('\n%c3D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], [2, 2, 3])
|
||||
it('[activations.softplus.2] should work for 3D tensor', function () {
|
||||
const key = 'activations.softplus.2'
|
||||
console.log(`\n%c[${key}] 3D`, styles.h3)
|
||||
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()
|
||||
activations.softplus(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.693147, 0.798139, 0.474077, 0.644397, 1.313262, 2.126928, 0.67826, 2.395545, 0.693147, 1.171101, 0.554355, 1.313262])
|
||||
const shapeExpected = [2, 2, 3]
|
||||
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))
|
||||
})
|
||||
@@ -116,47 +121,50 @@ describe('activations', function () {
|
||||
console.log('\n%csoftsign', styles.h2)
|
||||
})
|
||||
|
||||
it('should work for 1D tensor', function () {
|
||||
console.log('\n%c1D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
it('[activations.softsign.0] should work for 1D tensor', function () {
|
||||
const key = 'activations.softsign.0'
|
||||
console.log(`\n%c[${key}] 1D`, styles.h3)
|
||||
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()
|
||||
activations.softsign(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.0, 0.166667, 0.333333, -0.090909, 0.5, 0.666667])
|
||||
const shapeExpected = [6]
|
||||
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('should work for 2D tensor', function () {
|
||||
console.log('\n%c2D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], [2, 6])
|
||||
it('[activations.softsign.1] should work for 2D tensor', function () {
|
||||
const key = 'activations.softsign.1'
|
||||
console.log(`\n%c[${key}] 2D`, styles.h3)
|
||||
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()
|
||||
activations.softsign(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.0, 0.166667, 0.333333, -0.090909, 0.5, 0.666667, -0.029126, 0.230769, 0.0, 0.444444, -0.230769, 0.5])
|
||||
const shapeExpected = [2, 6]
|
||||
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('should work for 3D tensor', function () {
|
||||
console.log('\n%c3D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], [2, 2, 3])
|
||||
it('[activations.softsign.2] should work for 3D tensor', function () {
|
||||
const key = 'activations.softsign.2'
|
||||
console.log(`\n%c[${key}] 3D`, styles.h3)
|
||||
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()
|
||||
activations.softsign(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.0, 0.166667, -0.333333, -0.090909, 0.5, 0.666667, -0.029126, 0.69697, 0.0, 0.444444, -0.230769, 0.5])
|
||||
const shapeExpected = [2, 2, 3]
|
||||
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))
|
||||
})
|
||||
@@ -171,77 +179,82 @@ describe('activations', function () {
|
||||
console.log('\n%crelu', styles.h2)
|
||||
})
|
||||
|
||||
it('should work for 1D tensor', function () {
|
||||
console.log('\n%c1D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
it('[activations.relu.0] should work for 1D tensor', function () {
|
||||
const key = 'activations.relu.0'
|
||||
console.log(`\n%c[${key}] 1D`, styles.h3)
|
||||
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()
|
||||
activations.relu(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.0, 0.2, 0.5, 0.0, 1.0, 2.0])
|
||||
const shapeExpected = [6]
|
||||
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('should work for 2D tensor', function () {
|
||||
console.log('\n%c2D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], [2, 6])
|
||||
it('[activations.relu.1] should work for 2D tensor', function () {
|
||||
const key = 'activations.relu.1'
|
||||
console.log(`\n%c[${key}] 2D`, styles.h3)
|
||||
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()
|
||||
activations.relu(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.0, 0.2, 0.5, 0.0, 1.0, 2.0, 0.0, 0.3, 0.0, 0.8, 0.0, 1.0])
|
||||
const shapeExpected = [2, 6]
|
||||
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('should work for 3D tensor', function () {
|
||||
console.log('\n%c3D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], [2, 2, 3])
|
||||
it('[activations.relu.2] should work for 3D tensor', function () {
|
||||
const key = 'activations.relu.2'
|
||||
console.log(`\n%c[${key}] 3D`, styles.h3)
|
||||
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()
|
||||
activations.relu(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.0, 0.2, 0.0, 0.0, 1.0, 2.0, 0.0, 2.3, 0.0, 0.8, 0.0, 1.0])
|
||||
const shapeExpected = [2, 2, 3]
|
||||
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('should work with maxValue', function () {
|
||||
console.log('\n%c3D, maxValue=0.5', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], [2, 2, 3])
|
||||
it('[activations.relu.3] should work with maxValue', function () {
|
||||
const key = 'activations.relu.3'
|
||||
console.log(`\n%c[${key}] 3D, maxValue=0.5`, styles.h3)
|
||||
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()
|
||||
activations.relu(t, { maxValue: 0.5 })
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.0, 0.2, 0.0, 0.0, 0.5, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5])
|
||||
const shapeExpected = [2, 2, 3]
|
||||
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('should work with alpha (slope of negative portion)', function () {
|
||||
console.log('\n%c3D, alpha=0.3', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], [2, 2, 3])
|
||||
it('[activations.relu.4] should work with alpha (slope of negative portion)', function () {
|
||||
const key = 'activations.relu.4'
|
||||
console.log(`\n%c[${key}] 3D, alpha=0.3`, styles.h3)
|
||||
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()
|
||||
activations.relu(t, { alpha: 0.3 })
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.0, 0.2, -0.15, -0.03, 1.0, 2.0, -0.009, 2.3, 0.0, 0.8, -0.09, 1.0])
|
||||
const shapeExpected = [2, 2, 3]
|
||||
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))
|
||||
})
|
||||
@@ -256,47 +269,50 @@ describe('activations', function () {
|
||||
console.log('\n%ctanh', styles.h2)
|
||||
})
|
||||
|
||||
it('should work for 1D tensor', function () {
|
||||
console.log('\n%c1D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
it('[activations.tanh.0] should work for 1D tensor', function () {
|
||||
const key = 'activations.tanh.0'
|
||||
console.log(`\n%c[${key}] 1D`, styles.h3)
|
||||
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()
|
||||
activations.tanh(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.0, 0.197375, 0.462117, -0.099668, 0.761594, 0.964028])
|
||||
const shapeExpected = [6]
|
||||
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('should work for 2D tensor', function () {
|
||||
console.log('\n%c2D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], [2, 6])
|
||||
it('[activations.tanh.1] should work for 2D tensor', function () {
|
||||
const key = 'activations.tanh.1'
|
||||
console.log(`\n%c[${key}] 2D`, styles.h3)
|
||||
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()
|
||||
activations.tanh(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.0, 0.197375, 0.462117, -0.099668, 0.761594, 0.964028, -0.029991, 0.291313, 0.0, 0.664037, -0.291313, 0.761594])
|
||||
const shapeExpected = [2, 6]
|
||||
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('should work for 3D tensor', function () {
|
||||
console.log('\n%c3D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], [2, 2, 3])
|
||||
it('[activations.tanh.2] should work for 3D tensor', function () {
|
||||
const key = 'activations.tanh.2'
|
||||
console.log(`\n%c[${key}] 3D`, styles.h3)
|
||||
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()
|
||||
activations.tanh(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.0, 0.197375, -0.462117, -0.099668, 0.761594, 0.964028, -0.029991, 0.980096, 0.0, 0.664037, -0.291313, 0.761594])
|
||||
const shapeExpected = [2, 2, 3]
|
||||
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))
|
||||
})
|
||||
@@ -311,47 +327,50 @@ describe('activations', function () {
|
||||
console.log('\n%csigmoid', styles.h2)
|
||||
})
|
||||
|
||||
it('should work for 1D tensor', function () {
|
||||
console.log('\n%c1D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
it('[activations.sigmoid.0] should work for 1D tensor', function () {
|
||||
const key = 'activations.sigmoid.0'
|
||||
console.log(`\n%c[${key}] 1D`, styles.h3)
|
||||
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()
|
||||
activations.sigmoid(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.5, 0.549834, 0.622459, 0.475021, 0.731059, 0.880797])
|
||||
const shapeExpected = [6]
|
||||
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('should work for 2D tensor', function () {
|
||||
console.log('\n%c2D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], [2, 6])
|
||||
it('[activations.sigmoid.1] should work for 2D tensor', function () {
|
||||
const key = 'activations.sigmoid.1'
|
||||
console.log(`\n%c[${key}] 2D`, styles.h3)
|
||||
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()
|
||||
activations.sigmoid(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.5, 0.549834, 0.622459, 0.475021, 0.731059, 0.880797, 0.492501, 0.574443, 0.5, 0.689974, 0.425557, 0.731059])
|
||||
const shapeExpected = [2, 6]
|
||||
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('should work for 3D tensor', function () {
|
||||
console.log('\n%c3D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], [2, 2, 3])
|
||||
it('[activations.sigmoid.2] should work for 3D tensor', function () {
|
||||
const key = 'activations.sigmoid.2'
|
||||
console.log(`\n%c[${key}] 3D`, styles.h3)
|
||||
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()
|
||||
activations.sigmoid(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.5, 0.549834, 0.377541, 0.475021, 0.731059, 0.880797, 0.492501, 0.908877, 0.5, 0.689974, 0.425557, 0.731059])
|
||||
const shapeExpected = [2, 2, 3]
|
||||
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))
|
||||
})
|
||||
@@ -366,47 +385,50 @@ describe('activations', function () {
|
||||
console.log('\n%chardSigmoid', styles.h2)
|
||||
})
|
||||
|
||||
it('should work for 1D tensor', function () {
|
||||
console.log('\n%c1D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
it('[activations.hardSigmoid.0] should work for 1D tensor', function () {
|
||||
const key = 'activations.hardSigmoid.0'
|
||||
console.log(`\n%c[${key}] 1D`, styles.h3)
|
||||
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()
|
||||
activations.hardSigmoid(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.5, 0.54, 0.6, 0.48, 0.7, 0.9])
|
||||
const shapeExpected = [6]
|
||||
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('should work for 2D tensor', function () {
|
||||
console.log('\n%c2D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], [2, 6])
|
||||
it('[activations.hardSigmoid.1] should work for 2D tensor', function () {
|
||||
const key = 'activations.hardSigmoid.1'
|
||||
console.log(`\n%c[${key}] 2D`, styles.h3)
|
||||
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()
|
||||
activations.hardSigmoid(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.5, 0.54, 0.6, 0.48, 0.7, 0.9, 0.494, 0.56, 0.5, 0.66, 0.44, 0.7])
|
||||
const shapeExpected = [2, 6]
|
||||
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('should work for 3D tensor', function () {
|
||||
console.log('\n%c3D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], [2, 2, 3])
|
||||
it('[activations.hardSigmoid.2] should work for 3D tensor', function () {
|
||||
const key = 'activations.hardSigmoid.2'
|
||||
console.log(`\n%c[${key}] 3D`, styles.h3)
|
||||
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()
|
||||
activations.hardSigmoid(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.5, 0.54, 0.4, 0.48, 0.7, 0.9, 0.494, 0.96, 0.5, 0.66, 0.44, 0.7])
|
||||
const shapeExpected = [2, 2, 3]
|
||||
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))
|
||||
})
|
||||
@@ -421,47 +443,50 @@ describe('activations', function () {
|
||||
console.log('\n%clinear', styles.h2)
|
||||
})
|
||||
|
||||
it('should work for 1D tensor', function () {
|
||||
console.log('\n%c1D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
it('[activations.linear.0] should work for 1D tensor', function () {
|
||||
const key = 'activations.linear.0'
|
||||
console.log(`\n%c[${key}] 1D`, styles.h3)
|
||||
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()
|
||||
activations.linear(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0, 0.2, 0.5, -0.1, 1, 2])
|
||||
const shapeExpected = [6]
|
||||
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('should work for 2D tensor', function () {
|
||||
console.log('\n%c2D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], [2, 6])
|
||||
it('[activations.linear.1] should work for 2D tensor', function () {
|
||||
const key = 'activations.linear.1'
|
||||
console.log(`\n%c[${key}] 2D`, styles.h3)
|
||||
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()
|
||||
activations.linear(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1])
|
||||
const shapeExpected = [2, 6]
|
||||
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('should work for 3D tensor', function () {
|
||||
console.log('\n%c3D', styles.h3)
|
||||
let t = new KerasJS.Tensor([0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], [2, 2, 3])
|
||||
it('[activations.linear.2] should work for 3D tensor', function () {
|
||||
const key = 'activations.linear.2'
|
||||
console.log(`\n%c[${key}] 3D`, styles.h3)
|
||||
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()
|
||||
activations.linear(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1])
|
||||
const shapeExpected = [2, 2, 3]
|
||||
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))
|
||||
})
|
||||
|
||||
@@ -9,7 +9,7 @@ describe('Layers: Advanced Activations', function () {
|
||||
const layers = KerasJS.layers
|
||||
|
||||
before(function () {
|
||||
console.log('\n%Layers: Advanced Activations', styles.h1)
|
||||
console.log('\n%cLayers: Advanced Activations', styles.h1)
|
||||
})
|
||||
|
||||
/*********************************************************
|
||||
@@ -21,18 +21,19 @@ describe('Layers: Advanced Activations', function () {
|
||||
console.log('\n%cLeakyReLU', styles.h2)
|
||||
})
|
||||
|
||||
it('should produce expected values', function () {
|
||||
console.log('\n%calpha=0.4', styles.h3)
|
||||
it('[advanced_activations.LeakyReLU.0] should produce expected values', function () {
|
||||
const key = 'advanced_activations.LeakyReLU.0'
|
||||
console.log(`\n%c[${key}] alpha=0.4`, styles.h3)
|
||||
let testLayer = new layers.LeakyReLU(0.4)
|
||||
let t = new KerasJS.Tensor([0, 0.2, -0.5, -0.1, 1, 2], [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()
|
||||
t = testLayer.call(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.0, 0.2, -0.2, -0.04, 1.0, 2.0])
|
||||
const shapeExpected = [6]
|
||||
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))
|
||||
})
|
||||
@@ -47,21 +48,20 @@ describe('Layers: Advanced Activations', function () {
|
||||
console.log('\n%cPReLU', styles.h2)
|
||||
})
|
||||
|
||||
it('should produce expected values', function () {
|
||||
console.log('\n%cweights: alphas', styles.h3)
|
||||
it('[advanced_activations.PReLU.0] should produce expected values', function () {
|
||||
const key = 'advanced_activations.PReLU.0'
|
||||
console.log(`\n%c[${key}] weights: alphas`, styles.h3)
|
||||
let testLayer = new layers.PReLU()
|
||||
testLayer.setWeights([
|
||||
new KerasJS.Tensor([-0.03, -0.02, 0.02, -0.03, -0.03, -0.01], [6])
|
||||
])
|
||||
let t = new KerasJS.Tensor([0, 0.2, -0.5, -0.1, 1, 2], [6])
|
||||
testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
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([0.0, 0.2, -0.01, 0.003, 1.0, 2.0])
|
||||
const shapeExpected = [6]
|
||||
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))
|
||||
})
|
||||
@@ -76,18 +76,19 @@ describe('Layers: Advanced Activations', function () {
|
||||
console.log('\n%cELU', styles.h2)
|
||||
})
|
||||
|
||||
it('should produce expected values', function () {
|
||||
console.log('\n%calpha=1.1', styles.h3)
|
||||
it('[advanced_activations.ELU.0] should produce expected values', function () {
|
||||
const key = 'advanced_activations.ELU.0'
|
||||
console.log(`\n%c[${key}] alpha=1.1`, styles.h3)
|
||||
let testLayer = new layers.ELU(1.1)
|
||||
let t = new KerasJS.Tensor([0, 0.2, -0.5, -0.1, 1, 2], [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()
|
||||
t = testLayer.call(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.0, 0.2, -0.432816, -0.104679, 1.0, 2.0])
|
||||
const shapeExpected = [6]
|
||||
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))
|
||||
})
|
||||
@@ -102,22 +103,20 @@ describe('Layers: Advanced Activations', function () {
|
||||
console.log('\n%cParametricSoftplus', styles.h2)
|
||||
})
|
||||
|
||||
it('should produce expected values', function () {
|
||||
console.log('\n%cweights: alphas, betas', styles.h3)
|
||||
it('[advanced_activations.ParametricSoftplus.0] should produce expected values', function () {
|
||||
const key = 'advanced_activations.ParametricSoftplus.0'
|
||||
console.log(`\n%c[${key}] weights: alphas, betas`, styles.h3)
|
||||
let testLayer = new layers.ParametricSoftplus()
|
||||
testLayer.setWeights([
|
||||
new KerasJS.Tensor([0.13, -0.02, 0.02, -0.03, -0.03, -0.01], [6]),
|
||||
new KerasJS.Tensor([-0.03, -0.1, 0.02, 0.5, 0.2, 0.0], [6])
|
||||
])
|
||||
let t = new KerasJS.Tensor([0, 0.2, -0.5, -0.1, 1, 2], [6])
|
||||
testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
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([0.090109, -0.013664, 0.013763, -0.020054, -0.023944, -0.006931])
|
||||
const shapeExpected = [6]
|
||||
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))
|
||||
})
|
||||
@@ -132,18 +131,19 @@ describe('Layers: Advanced Activations', function () {
|
||||
console.log('\n%cThresholdedReLU', styles.h2)
|
||||
})
|
||||
|
||||
it('should produce expected values', function () {
|
||||
console.log('\n%theta=0.9', styles.h3)
|
||||
it('[advanced_activations.ThresholdedReLU.0] should produce expected values', function () {
|
||||
const key = 'advanced_activations.ThresholdedReLU.0'
|
||||
console.log(`\n%c[${key}] theta=0.9`, styles.h3)
|
||||
let testLayer = new layers.ThresholdedReLU(0.9)
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [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()
|
||||
t = testLayer.call(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.0, 0.0, 0.0, 0.0, 1.0, 2.0])
|
||||
const shapeExpected = [6]
|
||||
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))
|
||||
})
|
||||
@@ -158,24 +158,20 @@ describe('Layers: Advanced Activations', function () {
|
||||
console.log('\n%cSReLU', styles.h2)
|
||||
})
|
||||
|
||||
it('should produce expected values', function () {
|
||||
console.log('\n%cweights: t_left, a_left, t_right, a_right', styles.h3)
|
||||
it('[advanced_activations.SReLU.0] should produce expected values', function () {
|
||||
const key = 'advanced_activations.SReLU.0'
|
||||
console.log(`\n%c[${key}] weights: t_left, a_left, t_right, a_right`, styles.h3)
|
||||
let testLayer = new layers.SReLU()
|
||||
testLayer.setWeights([
|
||||
new KerasJS.Tensor([0.13, -0.02, 0.02, -0.03, -0.03, -0.01], [6]),
|
||||
new KerasJS.Tensor([-0.03, -0.1, 0.02, 0.5, 0.2, 0.0], [6]),
|
||||
new KerasJS.Tensor([-0.9, 0.8, 0.0, -1.0, 0.7, 0.4], [6]),
|
||||
new KerasJS.Tensor([0.1, 0.2, 0.3, 0.0, 0.5, -0.2], [6])
|
||||
])
|
||||
let t = new KerasJS.Tensor([0, 0.2, -0.5, -0.1, 1, 2], [6])
|
||||
testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
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([0.1339, 0.2, 0.0096, -0.065, 0.835, 0.068])
|
||||
const shapeExpected = [6]
|
||||
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))
|
||||
})
|
||||
@@ -0,0 +1,44 @@
|
||||
/* eslint-env browser, mocha */
|
||||
|
||||
describe('Layers: Convolutional', 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%cLayers: Convolutional', styles.h1)
|
||||
})
|
||||
|
||||
/*********************************************************
|
||||
* Convolution2D
|
||||
*********************************************************/
|
||||
|
||||
describe('Convolution2D', function () {
|
||||
before(function () {
|
||||
console.log('\n%cConvolution2D', styles.h2)
|
||||
})
|
||||
|
||||
it('[convolutional.Convolution2D.0] [CPU] should produce expected values for activation=linear, borderMode=valid, subsample=[1,1], dimOrdering=tf, biase=true', function () {
|
||||
const key = 'convolutional.Convolution2D.0'
|
||||
const [nbRow, nbCol, nbFilter] = TEST_DATA[key].expected.shape
|
||||
const attrs = { activation: 'linear', borderMode: 'valid', subsample: [1, 1], dimOrdering: 'tf', bias: true }
|
||||
console.log(`\n%c[${key}] [CPU] test 1: ${nbFilter} ${nbRow}x${nbCol} filters on 5x5x2 input, activation='${attrs.activation}', border_mode='${attrs.borderMode}', subsample=${attrs.subsample}, dim_ordering='${attrs.dimOrdering}', bias=${attrs.bias}`, styles.h3)
|
||||
let testLayer = new layers.Convolution2D(nbFilter, nbRow, nbCol, attrs)
|
||||
testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
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))
|
||||
})
|
||||
})
|
||||
})
|
||||
+235
-307
@@ -9,7 +9,7 @@ describe('Layers: Core', function () {
|
||||
const layers = KerasJS.layers
|
||||
|
||||
before(function () {
|
||||
console.log('\n%Layers: Core', styles.h1)
|
||||
console.log('\n%cLayers: Core', styles.h1)
|
||||
})
|
||||
|
||||
/*********************************************************
|
||||
@@ -21,120 +21,110 @@ describe('Layers: Core', function () {
|
||||
console.log('\n%cDense', styles.h2)
|
||||
})
|
||||
|
||||
it('[CPU] should produce expected values', function () {
|
||||
console.log('\n%c[CPU] test 1', styles.h3)
|
||||
it('[core.Dense.0] [CPU] should produce expected values', function () {
|
||||
const key = 'core.Dense.0'
|
||||
console.log(`\n%c[${key}] [CPU] test 1`, styles.h3)
|
||||
let testLayer = new layers.Dense(2)
|
||||
testLayer.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2]),
|
||||
new KerasJS.Tensor([0.5, 0.7], [2])
|
||||
])
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
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([7.3, -0.21])
|
||||
const shapeExpected = [2]
|
||||
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('[CPU] should produce expected values, with sigmoid activation function', function () {
|
||||
console.log('\n%c[CPU] test 2 (with sigmoid activation)', styles.h3)
|
||||
it('[core.Dense.1] [CPU] should produce expected values, with sigmoid activation function', function () {
|
||||
const key = 'core.Dense.1'
|
||||
console.log(`\n%c[${key}] [CPU] test 2 (with sigmoid activation)`, styles.h3)
|
||||
let testLayer = new layers.Dense(2, { activation: 'sigmoid' })
|
||||
testLayer.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2]),
|
||||
new KerasJS.Tensor([0.5, 0.7], [2])
|
||||
])
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
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([0.999325, 0.447692])
|
||||
const shapeExpected = [2]
|
||||
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('[CPU] should produce expected values, with softplus activation function and no bias', function () {
|
||||
console.log('\n%c[CPU] test 3 (with softplus activation and no bias)', styles.h3)
|
||||
it('[core.Dense.2] [CPU] should produce expected values, with softplus activation function and no bias', function () {
|
||||
const key = 'core.Dense.2'
|
||||
console.log(`\n%c[${key}] [CPU] test 3 (with softplus activation and no bias)`, styles.h3)
|
||||
let testLayer = new layers.Dense(2, { activation: 'softplus', bias: false })
|
||||
testLayer.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2])
|
||||
])
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
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([6.801113, 0.338274])
|
||||
const shapeExpected = [2]
|
||||
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('[GPU] should produce expected values', function () {
|
||||
console.log('\n%c[GPU] test 1', styles.h3)
|
||||
it('[core.Dense.3] [GPU] should produce expected values', function () {
|
||||
const key = 'core.Dense.3'
|
||||
console.log(`\n%c[${key}] [GPU] test 1`, styles.h3)
|
||||
let testLayer = new layers.Dense(2)
|
||||
testLayer.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2]),
|
||||
new KerasJS.Tensor([0.5, 0.7], [2])
|
||||
])
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6], { useWeblas: true })
|
||||
testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape, { useWeblas: true })
|
||||
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([7.3, -0.21])
|
||||
const shapeExpected = [2]
|
||||
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('[GPU] should produce expected values, with sigmoid activation function', function () {
|
||||
console.log('\n%c[GPU] test 2 (with sigmoid activation)', styles.h3)
|
||||
it('[core.Dense.4] [GPU] should produce expected values, with sigmoid activation function', function () {
|
||||
const key = 'core.Dense.4'
|
||||
console.log(`\n%c[${key}] [GPU] test 2 (with sigmoid activation)`, styles.h3)
|
||||
let testLayer = new layers.Dense(2, { activation: 'sigmoid' })
|
||||
testLayer.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2]),
|
||||
new KerasJS.Tensor([0.5, 0.7], [2])
|
||||
])
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6], { useWeblas: true })
|
||||
testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape, { useWeblas: true })
|
||||
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([0.999325, 0.447692])
|
||||
const shapeExpected = [2]
|
||||
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('[GPU] should produce expected values, with softplus activation function and no bias', function () {
|
||||
console.log('\n%c[GPU] test 3 (with softplus activation and no bias)', styles.h3)
|
||||
it('[core.Dense.5] [GPU] should produce expected values, with softplus activation function and no bias', function () {
|
||||
const key = 'core.Dense.5'
|
||||
console.log(`\n%c[${key}] [GPU] test 3 (with softplus activation and no bias)`, styles.h3)
|
||||
let testLayer = new layers.Dense(2, { activation: 'softplus', bias: false })
|
||||
testLayer.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2])
|
||||
])
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6], { useWeblas: true })
|
||||
testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape, { useWeblas: true })
|
||||
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([6.801113, 0.338274])
|
||||
const shapeExpected = [2]
|
||||
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))
|
||||
})
|
||||
@@ -149,14 +139,12 @@ describe('Layers: Core', function () {
|
||||
console.log('\n%cActivation', styles.h2)
|
||||
})
|
||||
|
||||
it('should produce expected values for tanh activation following Dense layer', function () {
|
||||
console.log('\n%ctest 1 (tanh)', styles.h3)
|
||||
it('[core.Activation.0] should produce expected values for tanh activation following Dense layer', function () {
|
||||
const key = 'core.Activation.0'
|
||||
console.log(`\n%c[${key}] test 1 (tanh)`, styles.h3)
|
||||
let testLayer1 = new layers.Dense(2)
|
||||
testLayer1.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2]),
|
||||
new KerasJS.Tensor([0.5, 0.7], [2])
|
||||
])
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
testLayer1.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
t = testLayer1.call(t)
|
||||
console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
|
||||
let testLayer2 = new layers.Activation('tanh')
|
||||
@@ -165,20 +153,18 @@ describe('Layers: Core', function () {
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.999999, -0.206966])
|
||||
const shapeExpected = [2]
|
||||
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('should produce expected values for hardSigmoid activation following Dense layer', function () {
|
||||
console.log('\n%ctest 2 (hardSigmoid)', styles.h3)
|
||||
it('[core.Activation.1] should produce expected values for hardSigmoid activation following Dense layer', function () {
|
||||
const key = 'core.Activation.1'
|
||||
console.log(`\n%c[${key}] test 2 (hardSigmoid)`, styles.h3)
|
||||
let testLayer1 = new layers.Dense(2)
|
||||
testLayer1.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2]),
|
||||
new KerasJS.Tensor([0.5, 0.7], [2])
|
||||
])
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
testLayer1.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
t = testLayer1.call(t)
|
||||
console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
|
||||
let testLayer2 = new layers.Activation('hardSigmoid')
|
||||
@@ -187,8 +173,8 @@ describe('Layers: Core', function () {
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([1.0, 0.458])
|
||||
const shapeExpected = [2]
|
||||
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))
|
||||
})
|
||||
@@ -203,14 +189,12 @@ describe('Layers: Core', function () {
|
||||
console.log('\n%cDropout', styles.h2)
|
||||
})
|
||||
|
||||
it('should just pass through tensor during test time', function () {
|
||||
console.log('\n%cshould pass through', styles.h3)
|
||||
it('[core.Dropout.0] should just pass through tensor during test time', function () {
|
||||
const key = 'core.Dropout.0'
|
||||
console.log(`\n%c[${key}] should pass through`, styles.h3)
|
||||
let testLayer1 = new layers.Dense(2)
|
||||
testLayer1.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2]),
|
||||
new KerasJS.Tensor([0.5, 0.7], [2])
|
||||
])
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
testLayer1.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
t = testLayer1.call(t)
|
||||
console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
|
||||
let testLayer2 = new layers.Dropout(0.5)
|
||||
@@ -219,8 +203,8 @@ describe('Layers: Core', function () {
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([7.3, -0.21])
|
||||
const shapeExpected = [2]
|
||||
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))
|
||||
})
|
||||
@@ -235,50 +219,53 @@ describe('Layers: Core', function () {
|
||||
console.log('\n%cFlatten', styles.h2)
|
||||
})
|
||||
|
||||
it('should do nothing for 1D', function () {
|
||||
console.log('\n%c1D', styles.h3)
|
||||
it('[core.Flatten.0] should do nothing for 1D', function () {
|
||||
const key = 'core.Flatten.0'
|
||||
console.log(`\n%c[${key}] 1D`, styles.h3)
|
||||
let testLayer = new layers.Flatten()
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [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()
|
||||
t = testLayer.call(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0, 0.2, 0.5, -0.1, 1, 2])
|
||||
const shapeExpected = [6]
|
||||
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('should flatten 2D', function () {
|
||||
console.log('\n%c2D', styles.h3)
|
||||
it('[core.Flatten.1] should flatten 2D', function () {
|
||||
const key = 'core.Flatten.1'
|
||||
console.log(`\n%c[${key}] 2D`, styles.h3)
|
||||
let testLayer = new layers.Flatten()
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [3, 2])
|
||||
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([0, 0.2, 0.5, -0.1, 1, 2])
|
||||
const shapeExpected = [6]
|
||||
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('should flatten 3D', function () {
|
||||
console.log('\n%c3D', styles.h3)
|
||||
it('[core.Flatten.2] should flatten 3D', function () {
|
||||
const key = 'core.Flatten.2'
|
||||
console.log(`\n%c[${key}] 3D`, styles.h3)
|
||||
let testLayer = new layers.Flatten()
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2, 0, 0.2, 0.5, -0.1, 1, 2], [3, 2, 2])
|
||||
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([0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0])
|
||||
const shapeExpected = [12]
|
||||
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))
|
||||
})
|
||||
@@ -293,50 +280,53 @@ describe('Layers: Core', function () {
|
||||
console.log('\n%cReshape', styles.h2)
|
||||
})
|
||||
|
||||
it('should be able to go from shape [6] -> [2, 3]', function () {
|
||||
console.log('\n%cshape [6] -> [2, 3]', styles.h3)
|
||||
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([2, 3])
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [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()
|
||||
t = testLayer.call(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0, 0.2, 0.5, -0.1, 1, 2])
|
||||
const shapeExpected = [2, 3]
|
||||
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('should be able to go from shape [3, 2] -> [6]', function () {
|
||||
console.log('\n%cshape [3, 2] -> [6]', styles.h3)
|
||||
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([6])
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [3, 2])
|
||||
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([0, 0.2, 0.5, -0.1, 1, 2])
|
||||
const shapeExpected = [6]
|
||||
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('should be able to go from shape [3, 2, 2] -> [4, 3]', function () {
|
||||
console.log('\n%cshape [3, 2, 2] -> [4, 3]', styles.h3)
|
||||
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([4, 3])
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2, 0, 0.2, 0.5, -0.1, 1, 2], [3, 2, 2])
|
||||
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([0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0])
|
||||
const shapeExpected = [4, 3]
|
||||
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))
|
||||
})
|
||||
@@ -351,34 +341,36 @@ describe('Layers: Core', function () {
|
||||
console.log('\n%cPermute', styles.h2)
|
||||
})
|
||||
|
||||
it('should be able to go from shape [3, 2] -> [2, 3]', function () {
|
||||
console.log('\n%cshape [3, 2] -> [2, 3]', styles.h3)
|
||||
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([2, 1])
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [3, 2])
|
||||
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([0.0, 0.5, 1.0, 0.2, -0.1, 2.0])
|
||||
const shapeExpected = [2, 3]
|
||||
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('should be able to go from shape [2, 3, 4] -> [4, 3, 2]', function () {
|
||||
console.log('\n%cshape [2, 3, 4] -> [4, 3, 2]', styles.h3)
|
||||
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([3, 2, 1])
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2, 0, 0.2, 0.5, -0.1, 1, 2, 0, 0.2, 0.5, -0.1, 1, 2, 0, 0.2, 0.5, -0.1, 1, 2], [2, 3, 4])
|
||||
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([0.0, 0.0, 1.0, 1.0, 0.5, 0.5, 0.2, 0.2, 2.0, 2.0, -0.1, -0.1, 0.5, 0.5, 0.0, 0.0, 1.0, 1.0, -0.1, -0.1, 0.2, 0.2, 2.0, 2.0])
|
||||
const shapeExpected = [4, 3, 2]
|
||||
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))
|
||||
})
|
||||
@@ -393,18 +385,19 @@ describe('Layers: Core', function () {
|
||||
console.log('\n%cRepeatVector', styles.h2)
|
||||
})
|
||||
|
||||
it('should be able to go from shape [6] -> [7, 6]', function () {
|
||||
console.log('\n%crepeat vector, shape [6] -> [7, 6]', styles.h3)
|
||||
it('[core.RepeatVector.0] should be able to go from shape [6] -> [7, 6]', function () {
|
||||
const key = 'core.RepeatVector.0'
|
||||
console.log(`\n%c[${key}] repeat vector, shape [6] -> [7, 6]`, styles.h3)
|
||||
let testLayer = new layers.RepeatVector(7)
|
||||
let t = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [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()
|
||||
t = testLayer.call(t)
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0])
|
||||
const shapeExpected = [7, 6]
|
||||
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))
|
||||
})
|
||||
@@ -419,21 +412,16 @@ describe('Layers: Core', function () {
|
||||
console.log('\n%cMerge', styles.h2)
|
||||
})
|
||||
|
||||
it('should produce expected values in sum mode', function () {
|
||||
console.log('\n%cmode: sum', styles.h3)
|
||||
it('[core.Merge.0] should produce expected values in sum mode', function () {
|
||||
const key = 'core.Merge.0'
|
||||
console.log(`\n%c[${key}] mode: sum`, styles.h3)
|
||||
let testLayer1a = new layers.Dense(2)
|
||||
let testLayer1b = new layers.Dense(2)
|
||||
let testLayer2 = new layers.Merge({ mode: 'sum' })
|
||||
testLayer1a.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2]),
|
||||
new KerasJS.Tensor([0.5, 0.7], [2])
|
||||
])
|
||||
testLayer1b.setWeights([
|
||||
new KerasJS.Tensor([1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], [6, 2]),
|
||||
new KerasJS.Tensor([0.1, -0.2], [2])
|
||||
])
|
||||
let t1a = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
let t1b = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
testLayer1a.setWeights(TEST_DATA[key].weights.slice(0, 2).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
testLayer1b.setWeights(TEST_DATA[key].weights.slice(2, 4).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
let t1a = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
let t1b = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
t1a = testLayer1a.call(t1a)
|
||||
t1b = testLayer1b.call(t1b)
|
||||
console.log('%cin', styles.h4, stringifyCondensed([t1a.tensor, t1b.tensor]))
|
||||
@@ -442,27 +430,22 @@ describe('Layers: Core', function () {
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t2.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([4.85, 4.27])
|
||||
const shapeExpected = [2]
|
||||
const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
|
||||
const shapeExpected = TEST_DATA[key].expected.shape
|
||||
assert.deepEqual(t2.tensor.shape, shapeExpected)
|
||||
assert.isTrue(approxEquals(t2.tensor, dataExpected))
|
||||
})
|
||||
|
||||
it('should produce expected values in mul mode', function () {
|
||||
console.log('\n%cmode: mul', styles.h3)
|
||||
it('[core.Merge.1] should produce expected values in mul mode', function () {
|
||||
const key = 'core.Merge.1'
|
||||
console.log(`\n%c[${key}] mode: mul`, styles.h3)
|
||||
let testLayer1a = new layers.Dense(2)
|
||||
let testLayer1b = new layers.Dense(2)
|
||||
let testLayer2 = new layers.Merge({ mode: 'mul' })
|
||||
testLayer1a.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2]),
|
||||
new KerasJS.Tensor([0.5, 0.7], [2])
|
||||
])
|
||||
testLayer1b.setWeights([
|
||||
new KerasJS.Tensor([1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], [6, 2]),
|
||||
new KerasJS.Tensor([0.1, -0.2], [2])
|
||||
])
|
||||
let t1a = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
let t1b = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
testLayer1a.setWeights(TEST_DATA[key].weights.slice(0, 2).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
testLayer1b.setWeights(TEST_DATA[key].weights.slice(2, 4).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
let t1a = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
let t1b = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
t1a = testLayer1a.call(t1a)
|
||||
t1b = testLayer1b.call(t1b)
|
||||
console.log('%cin', styles.h4, stringifyCondensed([t1a.tensor, t1b.tensor]))
|
||||
@@ -471,27 +454,22 @@ describe('Layers: Core', function () {
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t2.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([-17.885, -0.9408])
|
||||
const shapeExpected = [2]
|
||||
const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
|
||||
const shapeExpected = TEST_DATA[key].expected.shape
|
||||
assert.deepEqual(t2.tensor.shape, shapeExpected)
|
||||
assert.isTrue(approxEquals(t2.tensor, dataExpected))
|
||||
})
|
||||
|
||||
it('should produce expected values in ave mode', function () {
|
||||
console.log('\n%cmode: ave', styles.h3)
|
||||
it('[core.Merge.2] should produce expected values in ave mode', function () {
|
||||
const key = 'core.Merge.2'
|
||||
console.log(`\n%c[${key}] mode: ave`, styles.h3)
|
||||
let testLayer1a = new layers.Dense(2)
|
||||
let testLayer1b = new layers.Dense(2)
|
||||
let testLayer2 = new layers.Merge({ mode: 'ave' })
|
||||
testLayer1a.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2]),
|
||||
new KerasJS.Tensor([0.5, 0.7], [2])
|
||||
])
|
||||
testLayer1b.setWeights([
|
||||
new KerasJS.Tensor([1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], [6, 2]),
|
||||
new KerasJS.Tensor([0.1, -0.2], [2])
|
||||
])
|
||||
let t1a = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
let t1b = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
testLayer1a.setWeights(TEST_DATA[key].weights.slice(0, 2).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
testLayer1b.setWeights(TEST_DATA[key].weights.slice(2, 4).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
let t1a = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
let t1b = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
t1a = testLayer1a.call(t1a)
|
||||
t1b = testLayer1b.call(t1b)
|
||||
console.log('%cin', styles.h4, stringifyCondensed([t1a.tensor, t1b.tensor]))
|
||||
@@ -500,27 +478,22 @@ describe('Layers: Core', function () {
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t2.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([2.425, 2.135])
|
||||
const shapeExpected = [2]
|
||||
const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
|
||||
const shapeExpected = TEST_DATA[key].expected.shape
|
||||
assert.deepEqual(t2.tensor.shape, shapeExpected)
|
||||
assert.isTrue(approxEquals(t2.tensor, dataExpected))
|
||||
})
|
||||
|
||||
it('should produce expected values in max mode', function () {
|
||||
console.log('\n%cmode: max', styles.h3)
|
||||
it('[core.Merge.3] should produce expected values in max mode', function () {
|
||||
const key = 'core.Merge.3'
|
||||
console.log(`\n%c[${key}] mode: max`, styles.h3)
|
||||
let testLayer1a = new layers.Dense(2)
|
||||
let testLayer1b = new layers.Dense(2)
|
||||
let testLayer2 = new layers.Merge({ mode: 'max' })
|
||||
testLayer1a.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2]),
|
||||
new KerasJS.Tensor([0.5, 0.7], [2])
|
||||
])
|
||||
testLayer1b.setWeights([
|
||||
new KerasJS.Tensor([1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], [6, 2]),
|
||||
new KerasJS.Tensor([0.1, -0.2], [2])
|
||||
])
|
||||
let t1a = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
let t1b = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
testLayer1a.setWeights(TEST_DATA[key].weights.slice(0, 2).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
testLayer1b.setWeights(TEST_DATA[key].weights.slice(2, 4).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
let t1a = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
let t1b = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
t1a = testLayer1a.call(t1a)
|
||||
t1b = testLayer1b.call(t1b)
|
||||
console.log('%cin', styles.h4, stringifyCondensed([t1a.tensor, t1b.tensor]))
|
||||
@@ -529,27 +502,22 @@ describe('Layers: Core', function () {
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t2.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([7.3, 4.48])
|
||||
const shapeExpected = [2]
|
||||
const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
|
||||
const shapeExpected = TEST_DATA[key].expected.shape
|
||||
assert.deepEqual(t2.tensor.shape, shapeExpected)
|
||||
assert.isTrue(approxEquals(t2.tensor, dataExpected))
|
||||
})
|
||||
|
||||
it('should produce expected values in concat mode (1D)', function () {
|
||||
console.log('\n%cmode: concat (1D)', styles.h3)
|
||||
it('[core.Merge.4] should produce expected values in concat mode (1D)', function () {
|
||||
const key = 'core.Merge.4'
|
||||
console.log(`\n%c[${key}] mode: concat (1D)`, styles.h3)
|
||||
let testLayer1a = new layers.Dense(2)
|
||||
let testLayer1b = new layers.Dense(2)
|
||||
let testLayer2 = new layers.Merge({ mode: 'concat', concatAxis: -1 })
|
||||
testLayer1a.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2]),
|
||||
new KerasJS.Tensor([0.5, 0.7], [2])
|
||||
])
|
||||
testLayer1b.setWeights([
|
||||
new KerasJS.Tensor([1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], [6, 2]),
|
||||
new KerasJS.Tensor([0.1, -0.2], [2])
|
||||
])
|
||||
let ta = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
let tb = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
testLayer1a.setWeights(TEST_DATA[key].weights.slice(0, 2).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
testLayer1b.setWeights(TEST_DATA[key].weights.slice(2, 4).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
let ta = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
let tb = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
ta = testLayer1a.call(ta)
|
||||
tb = testLayer1b.call(tb)
|
||||
console.log('%cin', styles.h4, stringifyCondensed([ta.tensor, tb.tensor]))
|
||||
@@ -558,29 +526,24 @@ describe('Layers: Core', function () {
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([7.3, -0.21, -2.45, 4.48])
|
||||
const shapeExpected = [4]
|
||||
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('should produce expected values in concat mode (2D, concatAxis=-1)', function () {
|
||||
console.log('\n%cmode: concat (2D, concatAxis=-1)', styles.h3)
|
||||
it('[core.Merge.5] should produce expected values in concat mode (2D, concatAxis=-1)', function () {
|
||||
const key = 'core.Merge.5'
|
||||
console.log(`\n%c[${key}] mode: concat (2D, concatAxis=-1)`, styles.h3)
|
||||
let testLayer1a = new layers.Dense(2)
|
||||
let testLayer2a = new layers.RepeatVector(3)
|
||||
let testLayer1b = new layers.Dense(2)
|
||||
let testLayer2b = new layers.RepeatVector(3)
|
||||
let testLayer3 = new layers.Merge({ mode: 'concat', concatAxis: -1 })
|
||||
testLayer1a.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2]),
|
||||
new KerasJS.Tensor([0.5, 0.7], [2])
|
||||
])
|
||||
testLayer1b.setWeights([
|
||||
new KerasJS.Tensor([1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], [6, 2]),
|
||||
new KerasJS.Tensor([0.1, -0.2], [2])
|
||||
])
|
||||
let ta = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
let tb = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
testLayer1a.setWeights(TEST_DATA[key].weights.slice(0, 2).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
testLayer1b.setWeights(TEST_DATA[key].weights.slice(2, 4).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
let ta = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
let tb = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
ta = testLayer1a.call(ta)
|
||||
ta = testLayer2a.call(ta)
|
||||
tb = testLayer1b.call(tb)
|
||||
@@ -591,29 +554,24 @@ describe('Layers: Core', function () {
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([7.3, -0.21, -2.45, 4.48, 7.3, -0.21, -2.45, 4.48, 7.3, -0.21, -2.45, 4.48])
|
||||
const shapeExpected = [3, 4]
|
||||
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('should produce expected values in concat mode (2D, concatAxis=-2)', function () {
|
||||
console.log('\n%cmode: concat (2D, concatAxis=-2)', styles.h3)
|
||||
it('[core.Merge.6] should produce expected values in concat mode (2D, concatAxis=-2)', function () {
|
||||
const key = 'core.Merge.6'
|
||||
console.log(`\n%c[${key}] mode: concat (2D, concatAxis=-2)`, styles.h3)
|
||||
let testLayer1a = new layers.Dense(2)
|
||||
let testLayer2a = new layers.RepeatVector(3)
|
||||
let testLayer1b = new layers.Dense(2)
|
||||
let testLayer2b = new layers.RepeatVector(3)
|
||||
let testLayer3 = new layers.Merge({ mode: 'concat', concatAxis: -2 })
|
||||
testLayer1a.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2]),
|
||||
new KerasJS.Tensor([0.5, 0.7], [2])
|
||||
])
|
||||
testLayer1b.setWeights([
|
||||
new KerasJS.Tensor([1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], [6, 2]),
|
||||
new KerasJS.Tensor([0.1, -0.2], [2])
|
||||
])
|
||||
let ta = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
let tb = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
testLayer1a.setWeights(TEST_DATA[key].weights.slice(0, 2).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
testLayer1b.setWeights(TEST_DATA[key].weights.slice(2, 4).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
let ta = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
let tb = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
ta = testLayer1a.call(ta)
|
||||
ta = testLayer2a.call(ta)
|
||||
tb = testLayer1b.call(tb)
|
||||
@@ -624,29 +582,24 @@ describe('Layers: Core', function () {
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([7.3, -0.21, 7.3, -0.21, 7.3, -0.21, -2.45, 4.48, -2.45, 4.48, -2.45, 4.48])
|
||||
const shapeExpected = [6, 2]
|
||||
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('should produce expected values in concat mode (2D, concatAxis=1)', function () {
|
||||
console.log('\n%cmode: concat (2D, concatAxis=1)', styles.h3)
|
||||
it('[core.Merge.7] should produce expected values in concat mode (2D, concatAxis=1)', function () {
|
||||
const key = 'core.Merge.7'
|
||||
console.log(`\n%c[${key}] mode: concat (2D, concatAxis=1)`, styles.h3)
|
||||
let testLayer1a = new layers.Dense(2)
|
||||
let testLayer2a = new layers.RepeatVector(3)
|
||||
let testLayer1b = new layers.Dense(2)
|
||||
let testLayer2b = new layers.RepeatVector(3)
|
||||
let testLayer3 = new layers.Merge({ mode: 'concat', concatAxis: 1 })
|
||||
testLayer1a.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2]),
|
||||
new KerasJS.Tensor([0.5, 0.7], [2])
|
||||
])
|
||||
testLayer1b.setWeights([
|
||||
new KerasJS.Tensor([1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], [6, 2]),
|
||||
new KerasJS.Tensor([0.1, -0.2], [2])
|
||||
])
|
||||
let ta = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
let tb = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
testLayer1a.setWeights(TEST_DATA[key].weights.slice(0, 2).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
testLayer1b.setWeights(TEST_DATA[key].weights.slice(2, 4).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
let ta = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
let tb = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
ta = testLayer1a.call(ta)
|
||||
ta = testLayer2a.call(ta)
|
||||
tb = testLayer1b.call(tb)
|
||||
@@ -657,29 +610,24 @@ describe('Layers: Core', function () {
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([7.3, -0.21, 7.3, -0.21, 7.3, -0.21, -2.45, 4.48, -2.45, 4.48, -2.45, 4.48])
|
||||
const shapeExpected = [6, 2]
|
||||
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('should produce expected values in concat mode (2D, concatAxis=2)', function () {
|
||||
console.log('\n%cmode: concat (2D, concatAxis=2)', styles.h3)
|
||||
it('[core.Merge.8] should produce expected values in concat mode (2D, concatAxis=2)', function () {
|
||||
const key = 'core.Merge.8'
|
||||
console.log(`\n%c[${key}] mode: concat (2D, concatAxis=2)`, styles.h3)
|
||||
let testLayer1a = new layers.Dense(2)
|
||||
let testLayer2a = new layers.RepeatVector(3)
|
||||
let testLayer1b = new layers.Dense(2)
|
||||
let testLayer2b = new layers.RepeatVector(3)
|
||||
let testLayer3 = new layers.Merge({ mode: 'concat', concatAxis: 2 })
|
||||
testLayer1a.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2]),
|
||||
new KerasJS.Tensor([0.5, 0.7], [2])
|
||||
])
|
||||
testLayer1b.setWeights([
|
||||
new KerasJS.Tensor([1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], [6, 2]),
|
||||
new KerasJS.Tensor([0.1, -0.2], [2])
|
||||
])
|
||||
let ta = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
let tb = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
testLayer1a.setWeights(TEST_DATA[key].weights.slice(0, 2).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
testLayer1b.setWeights(TEST_DATA[key].weights.slice(2, 4).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
let ta = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
let tb = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
ta = testLayer1a.call(ta)
|
||||
ta = testLayer2a.call(ta)
|
||||
tb = testLayer1b.call(tb)
|
||||
@@ -690,29 +638,24 @@ describe('Layers: Core', function () {
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([7.3, -0.21, -2.45, 4.48, 7.3, -0.21, -2.45, 4.48, 7.3, -0.21, -2.45, 4.48])
|
||||
const shapeExpected = [3, 4]
|
||||
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('should produce expected values in dot mode (2D x 2D, dotAxes=1)', function () {
|
||||
console.log('\n%cmode: dot (2D x 2D, dotAxes=1)', styles.h3)
|
||||
it('[core.Merge.9] should produce expected values in dot mode (2D x 2D, dotAxes=1)', function () {
|
||||
const key = 'core.Merge.9'
|
||||
console.log(`\n%c[${key}] mode: dot (2D x 2D, dotAxes=1)`, styles.h3)
|
||||
let testLayer1a = new layers.Dense(2)
|
||||
let testLayer2a = new layers.RepeatVector(3)
|
||||
let testLayer1b = new layers.Dense(2)
|
||||
let testLayer2b = new layers.RepeatVector(3)
|
||||
let testLayer3 = new layers.Merge({ mode: 'dot', dotAxes: 1 })
|
||||
testLayer1a.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2]),
|
||||
new KerasJS.Tensor([0.5, 0.7], [2])
|
||||
])
|
||||
testLayer1b.setWeights([
|
||||
new KerasJS.Tensor([1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], [6, 2]),
|
||||
new KerasJS.Tensor([0.1, -0.2], [2])
|
||||
])
|
||||
let ta = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
let tb = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
testLayer1a.setWeights(TEST_DATA[key].weights.slice(0, 2).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
testLayer1b.setWeights(TEST_DATA[key].weights.slice(2, 4).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
let ta = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
let tb = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
ta = testLayer1a.call(ta)
|
||||
ta = testLayer2a.call(ta)
|
||||
tb = testLayer1b.call(tb)
|
||||
@@ -723,29 +666,24 @@ describe('Layers: Core', function () {
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([-53.655003, 98.112007, 1.5435, -2.8224])
|
||||
const shapeExpected = [2, 2]
|
||||
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('should produce expected values in dot mode (2D x 2D, dotAxes=2)', function () {
|
||||
console.log('\n%cmode: dot (2D x 2D, dotAxes=2)', styles.h3)
|
||||
it('[core.Merge.10] should produce expected values in dot mode (2D x 2D, dotAxes=2)', function () {
|
||||
const key = 'core.Merge.10'
|
||||
console.log(`\n%c[${key}] mode: dot (2D x 2D, dotAxes=2)`, styles.h3)
|
||||
let testLayer1a = new layers.Dense(2)
|
||||
let testLayer2a = new layers.RepeatVector(3)
|
||||
let testLayer1b = new layers.Dense(2)
|
||||
let testLayer2b = new layers.RepeatVector(3)
|
||||
let testLayer3 = new layers.Merge({ mode: 'dot', dotAxes: 2 })
|
||||
testLayer1a.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2]),
|
||||
new KerasJS.Tensor([0.5, 0.7], [2])
|
||||
])
|
||||
testLayer1b.setWeights([
|
||||
new KerasJS.Tensor([1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], [6, 2]),
|
||||
new KerasJS.Tensor([0.1, -0.2], [2])
|
||||
])
|
||||
let ta = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
let tb = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
testLayer1a.setWeights(TEST_DATA[key].weights.slice(0, 2).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
testLayer1b.setWeights(TEST_DATA[key].weights.slice(2, 4).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
let ta = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
let tb = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
ta = testLayer1a.call(ta)
|
||||
ta = testLayer2a.call(ta)
|
||||
tb = testLayer1b.call(tb)
|
||||
@@ -756,29 +694,24 @@ describe('Layers: Core', function () {
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([-18.8258, -18.8258, -18.8258, -18.8258, -18.8258, -18.8258, -18.8258, -18.8258, -18.8258])
|
||||
const shapeExpected = [3, 3]
|
||||
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('should produce expected values in cos mode (2D x 2D, dotAxes=1)', function () {
|
||||
console.log('\n%cmode: cos (2D x 2D, dotAxes=1)', styles.h3)
|
||||
it('[core.Merge.11] should produce expected values in cos mode (2D x 2D, dotAxes=1)', function () {
|
||||
const key = 'core.Merge.11'
|
||||
console.log(`\n%c[${key}] mode: cos (2D x 2D, dotAxes=1)`, styles.h3)
|
||||
let testLayer1a = new layers.Dense(2)
|
||||
let testLayer2a = new layers.RepeatVector(3)
|
||||
let testLayer1b = new layers.Dense(2)
|
||||
let testLayer2b = new layers.RepeatVector(3)
|
||||
let testLayer3 = new layers.Merge({ mode: 'cos', dotAxes: 1 })
|
||||
testLayer1a.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2]),
|
||||
new KerasJS.Tensor([0.5, 0.7], [2])
|
||||
])
|
||||
testLayer1b.setWeights([
|
||||
new KerasJS.Tensor([1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], [6, 2]),
|
||||
new KerasJS.Tensor([0.1, -0.2], [2])
|
||||
])
|
||||
let ta = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
let tb = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
testLayer1a.setWeights(TEST_DATA[key].weights.slice(0, 2).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
testLayer1b.setWeights(TEST_DATA[key].weights.slice(2, 4).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
let ta = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
let tb = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
ta = testLayer1a.call(ta)
|
||||
ta = testLayer2a.call(ta)
|
||||
tb = testLayer1b.call(tb)
|
||||
@@ -789,29 +722,24 @@ describe('Layers: Core', function () {
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([-1.0, 7.972744, 0.125427, -1.0])
|
||||
const shapeExpected = [1, 2, 2]
|
||||
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('should produce expected values in cos mode (2D x 2D, dotAxes=2)', function () {
|
||||
console.log('\n%cmode: cos (2D x 2D, dotAxes=2)', styles.h3)
|
||||
it('[core.Merge.12] should produce expected values in cos mode (2D x 2D, dotAxes=2)', function () {
|
||||
const key = 'core.Merge.12'
|
||||
console.log(`\n%c[${key}] mode: cos (2D x 2D, dotAxes=2)`, styles.h3)
|
||||
let testLayer1a = new layers.Dense(2)
|
||||
let testLayer2a = new layers.RepeatVector(3)
|
||||
let testLayer1b = new layers.Dense(2)
|
||||
let testLayer2b = new layers.RepeatVector(3)
|
||||
let testLayer3 = new layers.Merge({ mode: 'cos', dotAxes: 2 })
|
||||
testLayer1a.setWeights([
|
||||
new KerasJS.Tensor([0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], [6, 2]),
|
||||
new KerasJS.Tensor([0.5, 0.7], [2])
|
||||
])
|
||||
testLayer1b.setWeights([
|
||||
new KerasJS.Tensor([1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], [6, 2]),
|
||||
new KerasJS.Tensor([0.1, -0.2], [2])
|
||||
])
|
||||
let ta = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
let tb = new KerasJS.Tensor([0, 0.2, 0.5, -0.1, 1, 2], [6])
|
||||
testLayer1a.setWeights(TEST_DATA[key].weights.slice(0, 2).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
testLayer1b.setWeights(TEST_DATA[key].weights.slice(2, 4).map(w => new KerasJS.Tensor(w.data, w.shape)))
|
||||
let ta = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
let tb = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
|
||||
ta = testLayer1a.call(ta)
|
||||
ta = testLayer2a.call(ta)
|
||||
tb = testLayer1b.call(tb)
|
||||
@@ -822,8 +750,8 @@ describe('Layers: Core', function () {
|
||||
const endTime = performance.now()
|
||||
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
|
||||
logTime(startTime, endTime)
|
||||
const dataExpected = new Float32Array([-0.504843, -0.504843, -0.504843, -0.504843, -0.504843, -0.504843, -0.504843, -0.504843, -0.504843])
|
||||
const shapeExpected = [1, 3, 3]
|
||||
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))
|
||||
})
|
||||
@@ -0,0 +1,110 @@
|
||||
// TEST DATA
|
||||
// Keyed by mocha test ID
|
||||
// Python code for generating test data can be found in the matching jupyter notebook in folder `notebooks/`.
|
||||
|
||||
(function () {
|
||||
var DATA = {
|
||||
'activations.softmax.0': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
expected: { data: [0.067194, 0.082071, 0.110784, 0.0608, 0.182652, 0.4965], shape: [6] }
|
||||
},
|
||||
'activations.softmax.1': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], shape: [2, 6] },
|
||||
expected: { data: [0.067194, 0.082071, 0.110784, 0.0608, 0.182652, 0.4965, 0.107768, 0.149902, 0.11105, 0.247147, 0.082268, 0.301865], shape: [2, 6] }
|
||||
},
|
||||
'activations.softplus.0': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
expected: { data: [0.693147, 0.798139, 0.974077, 0.644397, 1.313262, 2.126928], shape: [6] }
|
||||
},
|
||||
'activations.softplus.1': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], shape: [2, 6] },
|
||||
expected: { data: [0.693147, 0.798139, 0.974077, 0.644397, 1.313262, 2.126928, 0.67826, 0.854355, 0.693147, 1.171101, 0.554355, 1.313262], shape: [2, 6] }
|
||||
},
|
||||
'activations.softplus.2': {
|
||||
input: { data: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], shape: [2, 2, 3] },
|
||||
expected: { data: [0.693147, 0.798139, 0.474077, 0.644397, 1.313262, 2.126928, 0.67826, 2.395545, 0.693147, 1.171101, 0.554355, 1.313262], shape: [2, 2, 3] }
|
||||
},
|
||||
'activations.softsign.0': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
expected: { data: [0.0, 0.166667, 0.333333, -0.090909, 0.5, 0.666667], shape: [6] }
|
||||
},
|
||||
'activations.softsign.1': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], shape: [2, 6] },
|
||||
expected: { data: [0.0, 0.166667, 0.333333, -0.090909, 0.5, 0.666667, -0.029126, 0.230769, 0.0, 0.444444, -0.230769, 0.5], shape: [2, 6] }
|
||||
},
|
||||
'activations.softsign.2': {
|
||||
input: { data: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], shape: [2, 2, 3] },
|
||||
expected: { data: [0.0, 0.166667, -0.333333, -0.090909, 0.5, 0.666667, -0.029126, 0.69697, 0.0, 0.444444, -0.230769, 0.5], shape: [2, 2, 3] }
|
||||
},
|
||||
'activations.relu.0': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
expected: { data: [0.0, 0.2, 0.5, 0.0, 1.0, 2.0], shape: [6] }
|
||||
},
|
||||
'activations.relu.1': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], shape: [2, 6] },
|
||||
expected: { data: [0.0, 0.2, 0.5, 0.0, 1.0, 2.0, 0.0, 0.3, 0.0, 0.8, 0.0, 1.0], shape: [2, 6] }
|
||||
},
|
||||
'activations.relu.2': {
|
||||
input: { data: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], shape: [2, 2, 3] },
|
||||
expected: { data: [0.0, 0.2, 0.0, 0.0, 1.0, 2.0, 0.0, 2.3, 0.0, 0.8, 0.0, 1.0], shape: [2, 2, 3] }
|
||||
},
|
||||
'activations.relu.3': {
|
||||
input: { data: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], shape: [2, 2, 3] },
|
||||
expected: { data: [0.0, 0.2, 0.0, 0.0, 0.5, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5], shape: [2, 2, 3] }
|
||||
},
|
||||
'activations.relu.4': {
|
||||
input: { data: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], shape: [2, 2, 3] },
|
||||
expected: { data: [0.0, 0.2, -0.15, -0.03, 1.0, 2.0, -0.009, 2.3, 0.0, 0.8, -0.09, 1.0], shape: [2, 2, 3] }
|
||||
},
|
||||
'activations.tanh.0': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
expected: { data: [0.0, 0.197375, 0.462117, -0.099668, 0.761594, 0.964028], shape: [6] }
|
||||
},
|
||||
'activations.tanh.1': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], shape: [2, 6] },
|
||||
expected: { data: [0.0, 0.197375, 0.462117, -0.099668, 0.761594, 0.964028, -0.029991, 0.291313, 0.0, 0.664037, -0.291313, 0.761594], shape: [2, 6] }
|
||||
},
|
||||
'activations.tanh.2': {
|
||||
input: { data: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], shape: [2, 2, 3] },
|
||||
expected: { data: [0.0, 0.197375, -0.462117, -0.099668, 0.761594, 0.964028, -0.029991, 0.980096, 0.0, 0.664037, -0.291313, 0.761594], shape: [2, 2, 3] }
|
||||
},
|
||||
'activations.sigmoid.0': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
expected: { data: [0.5, 0.549834, 0.622459, 0.475021, 0.731059, 0.880797], shape: [6] }
|
||||
},
|
||||
'activations.sigmoid.1': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], shape: [2, 6] },
|
||||
expected: { data: [0.5, 0.549834, 0.622459, 0.475021, 0.731059, 0.880797, 0.492501, 0.574443, 0.5, 0.689974, 0.425557, 0.731059], shape: [2, 6] }
|
||||
},
|
||||
'activations.sigmoid.2': {
|
||||
input: { data: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], shape: [2, 2, 3] },
|
||||
expected: { data: [0.5, 0.549834, 0.377541, 0.475021, 0.731059, 0.880797, 0.492501, 0.908877, 0.5, 0.689974, 0.425557, 0.731059], shape: [2, 2, 3] }
|
||||
},
|
||||
'activations.hardSigmoid.0': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
expected: { data: [0.5, 0.54, 0.6, 0.48, 0.7, 0.9], shape: [6] }
|
||||
},
|
||||
'activations.hardSigmoid.1': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], shape: [2, 6] },
|
||||
expected: { data: [0.5, 0.54, 0.6, 0.48, 0.7, 0.9, 0.494, 0.56, 0.5, 0.66, 0.44, 0.7], shape: [2, 6] }
|
||||
},
|
||||
'activations.hardSigmoid.2': {
|
||||
input: { data: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], shape: [2, 2, 3] },
|
||||
expected: { data: [0.5, 0.54, 0.4, 0.48, 0.7, 0.9, 0.494, 0.96, 0.5, 0.66, 0.44, 0.7], shape: [2, 2, 3] }
|
||||
},
|
||||
'activations.linear.0': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
expected: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] }
|
||||
},
|
||||
'activations.linear.1': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], shape: [2, 6] },
|
||||
expected: { data: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], shape: [2, 6] }
|
||||
},
|
||||
'activations.linear.2': {
|
||||
input: { data: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], shape: [2, 2, 3] },
|
||||
expected: { data: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], shape: [2, 2, 3] }
|
||||
}
|
||||
}
|
||||
|
||||
window.TEST_DATA = Object.assign({}, window.TEST_DATA, DATA)
|
||||
})()
|
||||
@@ -0,0 +1,47 @@
|
||||
// TEST DATA
|
||||
// Keyed by mocha test ID
|
||||
// Python code for generating test data can be found in the matching jupyter notebook in folder `notebooks/`.
|
||||
|
||||
(function () {
|
||||
var DATA = {
|
||||
'advanced_activations.LeakyReLU.0': {
|
||||
input: { data: [0, 0.2, -0.5, -0.1, 1, 2], shape: [6] },
|
||||
expected: { data: [0.0, 0.2, -0.2, -0.04, 1.0, 2.0], shape: [6] }
|
||||
},
|
||||
'advanced_activations.PReLU.0': {
|
||||
input: { data: [0, 0.2, -0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [-0.03, -0.02, 0.02, -0.03, -0.03, -0.01], shape: [6] }
|
||||
],
|
||||
expected: { data: [0.0, 0.2, -0.01, 0.003, 1.0, 2.0], shape: [6] }
|
||||
},
|
||||
'advanced_activations.ELU.0': {
|
||||
input: { data: [0, 0.2, -0.5, -0.1, 1, 2], shape: [6] },
|
||||
expected: { data: [0.0, 0.2, -0.432816, -0.104679, 1.0, 2.0], shape: [6] }
|
||||
},
|
||||
'advanced_activations.ParametricSoftplus.0': {
|
||||
input: { data: [0, 0.2, -0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.13, -0.02, 0.02, -0.03, -0.03, -0.01], shape: [6] },
|
||||
{ data: [-0.03, -0.1, 0.02, 0.5, 0.2, 0.0], shape: [6] }
|
||||
],
|
||||
expected: { data: [0.090109, -0.013664, 0.013763, -0.020054, -0.023944, -0.006931], shape: [6] }
|
||||
},
|
||||
'advanced_activations.ThresholdedReLU.0': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
expected: { data: [0.0, 0.0, 0.0, 0.0, 1.0, 2.0], shape: [6] }
|
||||
},
|
||||
'advanced_activations.SReLU.0': {
|
||||
input: { data: [0, 0.2, -0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.13, -0.02, 0.02, -0.03, -0.03, -0.01], shape: [6] },
|
||||
{ data: [-0.03, -0.1, 0.02, 0.5, 0.2, 0.0], shape: [6] },
|
||||
{ data: [-0.9, 0.8, 0.0, -1.0, 0.7, 0.4], shape: [6] },
|
||||
{ data: [0.1, 0.2, 0.3, 0.0, 0.5, -0.2], shape: [6] }
|
||||
],
|
||||
expected: { data: [0.1339, 0.2, 0.0096, -0.065, 0.835, 0.068], shape: [6] }
|
||||
}
|
||||
}
|
||||
|
||||
window.TEST_DATA = Object.assign({}, window.TEST_DATA, DATA)
|
||||
})()
|
||||
@@ -0,0 +1,30 @@
|
||||
// TEST DATA
|
||||
// Keyed by mocha test ID
|
||||
// Python code for generating test data can be found in the matching jupyter notebook in folder `notebooks/`.
|
||||
|
||||
(function () {
|
||||
var DATA = {
|
||||
'convolutional.Convolution2D.0': {
|
||||
input: {
|
||||
data: [0.370554, 0.667794, -0.386068, 0.787226, 0.443088, -0.620122, 0.108455, -0.295736, -0.636215, 0.571204, 0.930966, -0.535293, -0.832877, 0.207097, 0.457986, -0.447522, 0.370613, 0.035735, -0.903031, -0.724262, -0.626065, 0.988636, 0.041331, 0.157579, 0.469638, 0.083924, 0.826307, 0.61584, -0.194004, -0.285551, 0.905753, -0.312737, 0.7302, 0.660555, 0.076323, 0.844939, -0.805707, -0.794305, 0.403015, 0.78096, -0.680879, -0.448855, 0.344983, -0.671394, 0.402742, -0.02473, 0.361356, 0.043096, -0.913207, -0.552127],
|
||||
shape: [5, 5, 2]
|
||||
},
|
||||
weights: [
|
||||
{
|
||||
data: [0.032797, 0.141335, -0.943052, -0.656957, 0.370554, 0.667794, -0.386068, 0.787226, 0.443088, -0.620122, 0.108455, -0.295736, -0.636215, 0.571204, 0.930966, -0.535293, -0.832877, 0.207097, 0.457986, -0.447522, 0.370613, 0.035735, -0.903031, -0.724262, -0.626065, 0.988636, 0.041331, 0.157579, 0.469638, 0.083924, 0.826307, 0.61584, -0.194004, -0.285551, 0.905753, -0.312737, 0.7302, 0.660555, 0.076323, 0.844939, -0.805707, -0.794305, 0.403015, 0.78096, -0.680879, -0.448855, 0.344983, -0.671394, 0.402742, -0.02473, 0.361356, 0.043096, -0.913207, -0.552127, 0.15041, -0.759133, 0.000233, -0.723981, -0.894383, -0.643446, -0.115264, 0.755175, 0.898528, -0.043665, -0.077761, 0.274578, -0.350784, -0.764844, -0.897798, 0.275317, 0.624532, 0.340521],
|
||||
shape: [3, 3, 2, 4]
|
||||
},
|
||||
{
|
||||
data: [0.032797, 0.141335, -0.943052, -0.656957],
|
||||
shape: [4]
|
||||
}
|
||||
],
|
||||
expected: {
|
||||
data: [-2.849086, 2.196282, -1.293852, -0.662024, -0.171078, -1.51568, -0.627598, -0.522643, 1.786502, 0.494687, -2.932128, -2.497979, -0.84546, 0.148724, 0.88236, -0.48741, -0.423073, -1.496895, 1.482832, 0.014826, -0.489317, 0.250107, 0.327165, -0.209687, -0.869405, 1.146511, -1.012856, -0.260411, 2.120708, 2.675417, -1.439192, -0.438936, -0.075127, -1.3943, -0.41075, -0.964009],
|
||||
shape: [3, 3, 4]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.TEST_DATA = Object.assign({}, window.TEST_DATA, DATA)
|
||||
})()
|
||||
@@ -0,0 +1,255 @@
|
||||
// TEST DATA
|
||||
// Keyed by mocha test ID
|
||||
// Python code for generating test data can be found in the matching jupyter notebook in folder `notebooks/`.
|
||||
|
||||
(function () {
|
||||
var DATA = {
|
||||
'core.Dense.0': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
|
||||
{ data: [0.5, 0.7], shape: [2] }
|
||||
],
|
||||
expected: { data: [7.3, -0.21], shape: [2] }
|
||||
},
|
||||
'core.Dense.1': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
|
||||
{ data: [0.5, 0.7], shape: [2] }
|
||||
],
|
||||
expected: { data: [0.999325, 0.447692], shape: [2] }
|
||||
},
|
||||
'core.Dense.2': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] }
|
||||
],
|
||||
expected: { data: [6.801113, 0.338274], shape: [2] }
|
||||
},
|
||||
'core.Dense.3': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
|
||||
{ data: [0.5, 0.7], shape: [2] }
|
||||
],
|
||||
expected: { data: [7.3, -0.21], shape: [2] }
|
||||
},
|
||||
'core.Dense.4': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
|
||||
{ data: [0.5, 0.7], shape: [2] }
|
||||
],
|
||||
expected: { data: [0.999325, 0.447692], shape: [2] }
|
||||
},
|
||||
'core.Dense.5': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] }
|
||||
],
|
||||
expected: { data: [6.801113, 0.338274], shape: [2] }
|
||||
},
|
||||
'core.Activation.0': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
|
||||
{ data: [0.5, 0.7], shape: [2] }
|
||||
],
|
||||
expected: { data: [0.999999, -0.206966], shape: [2] }
|
||||
},
|
||||
'core.Activation.1': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
|
||||
{ data: [0.5, 0.7], shape: [2] }
|
||||
],
|
||||
expected: { data: [1.0, 0.458], shape: [2] }
|
||||
},
|
||||
'core.Dropout.0': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
|
||||
{ data: [0.5, 0.7], shape: [2] }
|
||||
],
|
||||
expected: { data: [7.3, -0.21], shape: [2] }
|
||||
},
|
||||
'core.Flatten.0': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
expected: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] }
|
||||
},
|
||||
'core.Flatten.1': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [3, 2] },
|
||||
expected: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] }
|
||||
},
|
||||
'core.Flatten.2': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2, 0, 0.2, 0.5, -0.1, 1, 2], shape: [3, 2, 2] },
|
||||
expected: { data: [0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0], shape: [12] }
|
||||
},
|
||||
'core.Reshape.0': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
expected: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [2, 3] }
|
||||
},
|
||||
'core.Reshape.1': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [3, 2] },
|
||||
expected: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] }
|
||||
},
|
||||
'core.Reshape.2': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2, 0, 0.2, 0.5, -0.1, 1, 2], shape: [3, 2, 2] },
|
||||
expected: { data: [0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0], shape: [4, 3] }
|
||||
},
|
||||
'core.Permute.0': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [3, 2] },
|
||||
expected: { data: [0.0, 0.5, 1.0, 0.2, -0.1, 2.0], shape: [2, 3] }
|
||||
},
|
||||
'core.Permute.1': {
|
||||
input: {
|
||||
data: [0, 0.2, 0.5, -0.1, 1, 2, 0, 0.2, 0.5, -0.1, 1, 2, 0, 0.2, 0.5, -0.1, 1, 2, 0, 0.2, 0.5, -0.1, 1, 2],
|
||||
shape: [2, 3, 4]
|
||||
},
|
||||
expected: {
|
||||
data: [0.0, 0.0, 1.0, 1.0, 0.5, 0.5, 0.2, 0.2, 2.0, 2.0, -0.1, -0.1, 0.5, 0.5, 0.0, 0.0, 1.0, 1.0, -0.1, -0.1, 0.2, 0.2, 2.0, 2.0],
|
||||
shape: [4, 3, 2]
|
||||
}
|
||||
},
|
||||
'core.RepeatVector.0': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
expected: {
|
||||
data: [0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0],
|
||||
shape: [7, 6]
|
||||
}
|
||||
},
|
||||
'core.Merge.0': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
|
||||
{ data: [0.5, 0.7], shape: [2] },
|
||||
{ data: [1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], shape: [6, 2] },
|
||||
{ data: [0.1, -0.2], shape: [2] }
|
||||
],
|
||||
expected: { data: [4.85, 4.27], shape: [2] }
|
||||
},
|
||||
'core.Merge.1': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
|
||||
{ data: [0.5, 0.7], shape: [2] },
|
||||
{ data: [1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], shape: [6, 2] },
|
||||
{ data: [0.1, -0.2], shape: [2] }
|
||||
],
|
||||
expected: { data: [-17.885, -0.9408], shape: [2] }
|
||||
},
|
||||
'core.Merge.2': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
|
||||
{ data: [0.5, 0.7], shape: [2] },
|
||||
{ data: [1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], shape: [6, 2] },
|
||||
{ data: [0.1, -0.2], shape: [2] }
|
||||
],
|
||||
expected: { data: [2.425, 2.135], shape: [2] }
|
||||
},
|
||||
'core.Merge.3': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
|
||||
{ data: [0.5, 0.7], shape: [2] },
|
||||
{ data: [1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], shape: [6, 2] },
|
||||
{ data: [0.1, -0.2], shape: [2] }
|
||||
],
|
||||
expected: { data: [7.3, 4.48], shape: [2] }
|
||||
},
|
||||
'core.Merge.4': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
|
||||
{ data: [0.5, 0.7], shape: [2] },
|
||||
{ data: [1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], shape: [6, 2] },
|
||||
{ data: [0.1, -0.2], shape: [2] }
|
||||
],
|
||||
expected: { data: [7.3, -0.21, -2.45, 4.48], shape: [4] }
|
||||
},
|
||||
'core.Merge.5': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
|
||||
{ data: [0.5, 0.7], shape: [2] },
|
||||
{ data: [1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], shape: [6, 2] },
|
||||
{ data: [0.1, -0.2], shape: [2] }
|
||||
],
|
||||
expected: { data: [7.3, -0.21, -2.45, 4.48, 7.3, -0.21, -2.45, 4.48, 7.3, -0.21, -2.45, 4.48], shape: [3, 4] }
|
||||
},
|
||||
'core.Merge.6': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
|
||||
{ data: [0.5, 0.7], shape: [2] },
|
||||
{ data: [1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], shape: [6, 2] },
|
||||
{ data: [0.1, -0.2], shape: [2] }
|
||||
],
|
||||
expected: { data: [7.3, -0.21, 7.3, -0.21, 7.3, -0.21, -2.45, 4.48, -2.45, 4.48, -2.45, 4.48], shape: [6, 2] }
|
||||
},
|
||||
'core.Merge.7': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
|
||||
{ data: [0.5, 0.7], shape: [2] },
|
||||
{ data: [1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], shape: [6, 2] },
|
||||
{ data: [0.1, -0.2], shape: [2] }
|
||||
],
|
||||
expected: { data: [7.3, -0.21, 7.3, -0.21, 7.3, -0.21, -2.45, 4.48, -2.45, 4.48, -2.45, 4.48], shape: [6, 2] }
|
||||
},
|
||||
'core.Merge.8': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
|
||||
{ data: [0.5, 0.7], shape: [2] },
|
||||
{ data: [1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], shape: [6, 2] },
|
||||
{ data: [0.1, -0.2], shape: [2] }
|
||||
],
|
||||
expected: { data: [7.3, -0.21, -2.45, 4.48, 7.3, -0.21, -2.45, 4.48, 7.3, -0.21, -2.45, 4.48], shape: [3, 4] }
|
||||
},
|
||||
'core.Merge.9': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
|
||||
{ data: [0.5, 0.7], shape: [2] },
|
||||
{ data: [1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], shape: [6, 2] },
|
||||
{ data: [0.1, -0.2], shape: [2] }
|
||||
],
|
||||
expected: { data: [-53.655003, 98.112007, 1.5435, -2.8224], shape: [2, 2] }
|
||||
},
|
||||
'core.Merge.10': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
|
||||
{ data: [0.5, 0.7], shape: [2] },
|
||||
{ data: [1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], shape: [6, 2] },
|
||||
{ data: [0.1, -0.2], shape: [2] }
|
||||
],
|
||||
expected: { data: [-18.8258, -18.8258, -18.8258, -18.8258, -18.8258, -18.8258, -18.8258, -18.8258, -18.8258], shape: [3, 3] }
|
||||
},
|
||||
'core.Merge.11': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
|
||||
{ data: [0.5, 0.7], shape: [2] },
|
||||
{ data: [1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], shape: [6, 2] },
|
||||
{ data: [0.1, -0.2], shape: [2] }
|
||||
],
|
||||
expected: { data: [-1.0, 7.972744, 0.125427, -1.0], shape: [1, 2, 2] }
|
||||
},
|
||||
'core.Merge.12': {
|
||||
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
|
||||
weights: [
|
||||
{ data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
|
||||
{ data: [0.5, 0.7], shape: [2] },
|
||||
{ data: [1, 0, -0.9, 0.6, -0.7, 0, 0.2, 0.4, 0, 0, -1, 2.3], shape: [6, 2] },
|
||||
{ data: [0.1, -0.2], shape: [2] }
|
||||
],
|
||||
expected: { data: [-0.504843, -0.504843, -0.504843, -0.504843, -0.504843, -0.504843, -0.504843, -0.504843, -0.504843], shape: [1, 3, 3] }
|
||||
}
|
||||
}
|
||||
|
||||
window.TEST_DATA = Object.assign({}, window.TEST_DATA, DATA)
|
||||
})()
|
||||
Reference in New Issue
Block a user