add ZeroPadding1D/2D/3D layers, with tests

This commit is contained in:
Leon Chen
2016-08-27 00:45:42 -04:00
parent 739b30dd92
commit b22cc1d295
14 changed files with 1185 additions and 1 deletions
+6
View File
@@ -56,6 +56,12 @@
<script src="/test/convolutional/UpSampling2D.js"></script>
<script src="/test/convolutional/data_UpSampling3D.js"></script>
<script src="/test/convolutional/UpSampling3D.js"></script>
<script src="/test/convolutional/data_ZeroPadding1D.js"></script>
<script src="/test/convolutional/ZeroPadding1D.js"></script>
<script src="/test/convolutional/data_ZeroPadding2D.js"></script>
<script src="/test/convolutional/ZeroPadding2D.js"></script>
<script src="/test/convolutional/data_ZeroPadding3D.js"></script>
<script src="/test/convolutional/ZeroPadding3D.js"></script>
<script>
// mocha.checkLeaks();
+166
View File
@@ -0,0 +1,166 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Using TensorFlow backend.\n"
]
}
],
"source": [
"import numpy as np\n",
"from keras.models import Model\n",
"from keras.layers import Input\n",
"from keras.layers.convolutional import ZeroPadding1D\n",
"from keras import backend as K"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def format_decimal(arr, places=6):\n",
" return [round(x * 10**places) / 10**places for x in arr]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### ZeroPadding1D"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**[convolutional.ZeroPadding1D.0] padding 1 on 3x5 input**"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"in shape: (3, 5)\n",
"in: [-0.412987, -0.139246, 0.567466, -0.512174, -0.33603, 0.585584, 0.453472, 0.942013, -0.609538, -0.894302, 0.711927, -0.126057, 0.677549, 0.676991, 0.471487]\n",
"out shape: (5, 5)\n",
"out: [0.0, 0.0, 0.0, 0.0, 0.0, -0.412987, -0.139246, 0.567466, -0.512174, -0.33603, 0.585584, 0.453472, 0.942013, -0.609538, -0.894302, 0.711927, -0.126057, 0.677549, 0.676991, 0.471487, 0.0, 0.0, 0.0, 0.0, 0.0]\n"
]
}
],
"source": [
"data_in_shape = (3, 5)\n",
"L = ZeroPadding1D(padding=1)\n",
"\n",
"layer_0 = Input(shape=data_in_shape)\n",
"layer_1 = L(layer_0)\n",
"model = Model(input=layer_0, output=layer_1)\n",
"\n",
"# set weights to random (use seed for reproducibility)\n",
"np.random.seed(240)\n",
"data_in = 2 * np.random.random(data_in_shape) - 1\n",
"print('')\n",
"print('in shape:', data_in_shape)\n",
"print('in:', format_decimal(data_in.ravel().tolist()))\n",
"result = model.predict(np.array([data_in]))\n",
"print('out shape:', result[0].shape)\n",
"print('out:', format_decimal(result[0].ravel().tolist()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**[convolutional.ZeroPadding1D.0] padding 3 on 4x4 input**"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"in shape: (4, 4)\n",
"in: [0.229895, 0.156613, -0.66952, -0.996975, 0.45773, 0.684298, -0.999213, 0.276751, -0.484373, -0.506163, 0.353904, 0.513668, -0.981594, 0.78914, 0.603978, 0.204066]\n",
"out shape: (10, 4)\n",
"out: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.229895, 0.156613, -0.66952, -0.996975, 0.45773, 0.684298, -0.999213, 0.276751, -0.484373, -0.506163, 0.353904, 0.513668, -0.981594, 0.78914, 0.603978, 0.204066, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n"
]
}
],
"source": [
"data_in_shape = (4, 4)\n",
"L = ZeroPadding1D(padding=3)\n",
"\n",
"layer_0 = Input(shape=data_in_shape)\n",
"layer_1 = L(layer_0)\n",
"model = Model(input=layer_0, output=layer_1)\n",
"\n",
"# set weights to random (use seed for reproducibility)\n",
"np.random.seed(241)\n",
"data_in = 2 * np.random.random(data_in_shape) - 1\n",
"print('')\n",
"print('in shape:', data_in_shape)\n",
"print('in:', format_decimal(data_in.ravel().tolist()))\n",
"result = model.predict(np.array([data_in]))\n",
"print('out shape:', result[0].shape)\n",
"print('out:', format_decimal(result[0].ravel().tolist()))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
+256
View File
@@ -0,0 +1,256 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Using TensorFlow backend.\n"
]
}
],
"source": [
"import numpy as np\n",
"from keras.models import Model\n",
"from keras.layers import Input\n",
"from keras.layers.convolutional import ZeroPadding2D\n",
"from keras import backend as K"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def format_decimal(arr, places=6):\n",
" return [round(x * 10**places) / 10**places for x in arr]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### ZeroPadding2D"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**[convolutional.ZeroPadding2D.0] padding (1,1) on 3x5x2 input, dim_ordering=tf**"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"in shape: (3, 5, 2)\n",
"in: [-0.570441, -0.454673, -0.285321, 0.237249, 0.282682, 0.428035, 0.160547, -0.332203, 0.546391, 0.272735, 0.010827, -0.763164, -0.442696, 0.381948, -0.676994, 0.753553, -0.031788, 0.915329, -0.738844, 0.269075, 0.434091, 0.991585, -0.944288, 0.258834, 0.162138, 0.565201, -0.492094, 0.170854, -0.139788, -0.710674]\n",
"out shape: (5, 7, 2)\n",
"out: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.570441, -0.454673, -0.285321, 0.237249, 0.282682, 0.428035, 0.160547, -0.332203, 0.546391, 0.272735, 0.0, 0.0, 0.0, 0.0, 0.010827, -0.763164, -0.442696, 0.381948, -0.676994, 0.753553, -0.031788, 0.915329, -0.738844, 0.269075, 0.0, 0.0, 0.0, 0.0, 0.434091, 0.991585, -0.944288, 0.258834, 0.162138, 0.565201, -0.492094, 0.170854, -0.139788, -0.710674, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n"
]
}
],
"source": [
"data_in_shape = (3, 5, 2)\n",
"L = ZeroPadding2D(padding=(1, 1), dim_ordering='tf')\n",
"\n",
"layer_0 = Input(shape=data_in_shape)\n",
"layer_1 = L(layer_0)\n",
"model = Model(input=layer_0, output=layer_1)\n",
"\n",
"# set weights to random (use seed for reproducibility)\n",
"np.random.seed(250)\n",
"data_in = 2 * np.random.random(data_in_shape) - 1\n",
"print('')\n",
"print('in shape:', data_in_shape)\n",
"print('in:', format_decimal(data_in.ravel().tolist()))\n",
"result = model.predict(np.array([data_in]))\n",
"print('out shape:', result[0].shape)\n",
"print('out:', format_decimal(result[0].ravel().tolist()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**[convolutional.ZeroPadding2D.1] padding (1,1) on 3x5x2 input, dim_ordering=th**"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"in shape: (3, 5, 2)\n",
"in: [-0.570441, -0.454673, -0.285321, 0.237249, 0.282682, 0.428035, 0.160547, -0.332203, 0.546391, 0.272735, 0.010827, -0.763164, -0.442696, 0.381948, -0.676994, 0.753553, -0.031788, 0.915329, -0.738844, 0.269075, 0.434091, 0.991585, -0.944288, 0.258834, 0.162138, 0.565201, -0.492094, 0.170854, -0.139788, -0.710674]\n",
"out shape: (3, 7, 4)\n",
"out: [0.0, 0.0, 0.0, 0.0, 0.0, -0.570441, -0.454673, 0.0, 0.0, -0.285321, 0.237249, 0.0, 0.0, 0.282682, 0.428035, 0.0, 0.0, 0.160547, -0.332203, 0.0, 0.0, 0.546391, 0.272735, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.010827, -0.763164, 0.0, 0.0, -0.442696, 0.381948, 0.0, 0.0, -0.676994, 0.753553, 0.0, 0.0, -0.031788, 0.915329, 0.0, 0.0, -0.738844, 0.269075, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.434091, 0.991585, 0.0, 0.0, -0.944288, 0.258834, 0.0, 0.0, 0.162138, 0.565201, 0.0, 0.0, -0.492094, 0.170854, 0.0, 0.0, -0.139788, -0.710674, 0.0, 0.0, 0.0, 0.0, 0.0]\n"
]
}
],
"source": [
"data_in_shape = (3, 5, 2)\n",
"L = ZeroPadding2D(padding=(1, 1), dim_ordering='th')\n",
"\n",
"layer_0 = Input(shape=data_in_shape)\n",
"layer_1 = L(layer_0)\n",
"model = Model(input=layer_0, output=layer_1)\n",
"\n",
"# set weights to random (use seed for reproducibility)\n",
"np.random.seed(250)\n",
"data_in = 2 * np.random.random(data_in_shape) - 1\n",
"print('')\n",
"print('in shape:', data_in_shape)\n",
"print('in:', format_decimal(data_in.ravel().tolist()))\n",
"result = model.predict(np.array([data_in]))\n",
"print('out shape:', result[0].shape)\n",
"print('out:', format_decimal(result[0].ravel().tolist()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**[convolutional.ZeroPadding2D.2] padding (3,2) on 2x6x4 input, dim_ordering=tf**"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"in shape: (2, 6, 4)\n",
"in: [-0.989173, -0.133618, -0.505338, 0.023259, 0.503982, -0.303769, -0.436321, 0.793911, 0.416102, 0.806405, -0.098342, -0.738022, -0.982676, 0.805073, 0.741244, -0.941634, -0.253526, -0.136544, -0.295772, 0.207565, -0.517246, -0.686963, -0.176235, -0.354111, -0.862411, -0.969822, 0.200074, 0.290718, -0.038623, 0.294839, 0.247968, 0.557946, -0.455596, 0.6624, 0.879529, -0.466772, 0.40423, 0.213794, 0.645662, -0.044634, -0.552595, 0.771242, -0.131944, -0.172725, 0.700856, -0.001994, 0.606737, -0.593306]\n",
"out shape: (8, 10, 4)\n",
"out: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.989173, -0.133618, -0.505338, 0.023259, 0.503982, -0.303769, -0.436321, 0.793911, 0.416102, 0.806405, -0.098342, -0.738022, -0.982676, 0.805073, 0.741244, -0.941634, -0.253526, -0.136544, -0.295772, 0.207565, -0.517246, -0.686963, -0.176235, -0.354111, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.862411, -0.969822, 0.200074, 0.290718, -0.038623, 0.294839, 0.247968, 0.557946, -0.455596, 0.6624, 0.879529, -0.466772, 0.40423, 0.213794, 0.645662, -0.044634, -0.552595, 0.771242, -0.131944, -0.172725, 0.700856, -0.001994, 0.606737, -0.593306, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n"
]
}
],
"source": [
"data_in_shape = (2, 6, 4)\n",
"L = ZeroPadding2D(padding=(3, 2), dim_ordering='tf')\n",
"\n",
"layer_0 = Input(shape=data_in_shape)\n",
"layer_1 = L(layer_0)\n",
"model = Model(input=layer_0, output=layer_1)\n",
"\n",
"# set weights to random (use seed for reproducibility)\n",
"np.random.seed(252)\n",
"data_in = 2 * np.random.random(data_in_shape) - 1\n",
"print('')\n",
"print('in shape:', data_in_shape)\n",
"print('in:', format_decimal(data_in.ravel().tolist()))\n",
"result = model.predict(np.array([data_in]))\n",
"print('out shape:', result[0].shape)\n",
"print('out:', format_decimal(result[0].ravel().tolist()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**[convolutional.ZeroPadding2D.3] padding (3,2) on 2x6x4 input, dim_ordering=th**"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"in shape: (2, 6, 4)\n",
"in: [-0.989173, -0.133618, -0.505338, 0.023259, 0.503982, -0.303769, -0.436321, 0.793911, 0.416102, 0.806405, -0.098342, -0.738022, -0.982676, 0.805073, 0.741244, -0.941634, -0.253526, -0.136544, -0.295772, 0.207565, -0.517246, -0.686963, -0.176235, -0.354111, -0.862411, -0.969822, 0.200074, 0.290718, -0.038623, 0.294839, 0.247968, 0.557946, -0.455596, 0.6624, 0.879529, -0.466772, 0.40423, 0.213794, 0.645662, -0.044634, -0.552595, 0.771242, -0.131944, -0.172725, 0.700856, -0.001994, 0.606737, -0.593306]\n",
"out shape: (2, 12, 8)\n",
"out: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.989173, -0.133618, -0.505338, 0.023259, 0.0, 0.0, 0.0, 0.0, 0.503982, -0.303769, -0.436321, 0.793911, 0.0, 0.0, 0.0, 0.0, 0.416102, 0.806405, -0.098342, -0.738022, 0.0, 0.0, 0.0, 0.0, -0.982676, 0.805073, 0.741244, -0.941634, 0.0, 0.0, 0.0, 0.0, -0.253526, -0.136544, -0.295772, 0.207565, 0.0, 0.0, 0.0, 0.0, -0.517246, -0.686963, -0.176235, -0.354111, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.862411, -0.969822, 0.200074, 0.290718, 0.0, 0.0, 0.0, 0.0, -0.038623, 0.294839, 0.247968, 0.557946, 0.0, 0.0, 0.0, 0.0, -0.455596, 0.6624, 0.879529, -0.466772, 0.0, 0.0, 0.0, 0.0, 0.40423, 0.213794, 0.645662, -0.044634, 0.0, 0.0, 0.0, 0.0, -0.552595, 0.771242, -0.131944, -0.172725, 0.0, 0.0, 0.0, 0.0, 0.700856, -0.001994, 0.606737, -0.593306, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n"
]
}
],
"source": [
"data_in_shape = (2, 6, 4)\n",
"L = ZeroPadding2D(padding=(3, 2), dim_ordering='th')\n",
"\n",
"layer_0 = Input(shape=data_in_shape)\n",
"layer_1 = L(layer_0)\n",
"model = Model(input=layer_0, output=layer_1)\n",
"\n",
"# set weights to random (use seed for reproducibility)\n",
"np.random.seed(252)\n",
"data_in = 2 * np.random.random(data_in_shape) - 1\n",
"print('')\n",
"print('in shape:', data_in_shape)\n",
"print('in:', format_decimal(data_in.ravel().tolist()))\n",
"result = model.predict(np.array([data_in]))\n",
"print('out shape:', result[0].shape)\n",
"print('out:', format_decimal(result[0].ravel().tolist()))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
File diff suppressed because one or more lines are too long
+34
View File
@@ -0,0 +1,34 @@
import Layer from '../../engine/Layer'
import Tensor from '../../Tensor'
import ops from 'ndarray-ops'
/**
* ZeroPadding1D layer class
*/
export default class ZeroPadding1D extends Layer {
/**
* Creates a ZeroPadding1D activation layer
* @param {number} padding - length of padding
*/
constructor (padding = 1, attrs = {}) {
super(attrs)
this.padding = padding
}
/**
* Method for layer computational logic
* @param {Tensor} x
* @returns {Tensor} x
*/
call = x => {
const inputShape = x.tensor.shape
const outputShape = [inputShape[0] + this.padding * 2, inputShape[1]]
let y = new Tensor([], outputShape)
ops.assign(
y.tensor.hi(inputShape[0] + this.padding, inputShape[1]).lo(this.padding, 0),
x.tensor
)
x.tensor = y.tensor
return x
}
}
+56
View File
@@ -0,0 +1,56 @@
import Layer from '../../engine/Layer'
import Tensor from '../../Tensor'
import ops from 'ndarray-ops'
/**
* ZeroPadding2D layer class
*/
export default class ZeroPadding2D extends Layer {
/**
* Creates a ZeroPadding2D activation layer
* @param {number} padding - size of padding
*/
constructor (padding = [1, 1], attrs = {}) {
super(attrs)
const {
dimOrdering = 'tf'
} = attrs
this.padding = padding
this.dimOrdering = dimOrdering
}
/**
* Method for layer computational logic
* @param {Tensor} x
* @returns {Tensor} x
*/
call = x => {
// convert to tf ordering
if (this.dimOrdering === 'th') {
x.tensor = x.tensor.transpose(1, 2, 0)
}
const inputShape = x.tensor.shape
const outputShape = [
inputShape[0] + this.padding[0] * 2,
inputShape[1] + this.padding[1] * 2,
inputShape[2]
]
let y = new Tensor([], outputShape)
ops.assign(
y.tensor
.hi(inputShape[0] + this.padding[0], inputShape[1] + this.padding[1], inputShape[2])
.lo(this.padding[0], this.padding[1], 0),
x.tensor
)
x.tensor = y.tensor
// convert back to th ordering if necessary
if (this.dimOrdering === 'th') {
x.tensor = x.tensor.transpose(2, 0, 1)
}
return x
}
}
+62
View File
@@ -0,0 +1,62 @@
import Layer from '../../engine/Layer'
import Tensor from '../../Tensor'
import ops from 'ndarray-ops'
/**
* ZeroPadding3D layer class
*/
export default class ZeroPadding3D extends Layer {
/**
* Creates a ZeroPadding3D activation layer
* @param {number} padding - size of padding
*/
constructor (padding = [1, 1, 1], attrs = {}) {
super(attrs)
const {
dimOrdering = 'tf'
} = attrs
this.padding = padding
this.dimOrdering = dimOrdering
}
/**
* Method for layer computational logic
* @param {Tensor} x
* @returns {Tensor} x
*/
call = x => {
// convert to tf ordering
if (this.dimOrdering === 'th') {
x.tensor = x.tensor.transpose(1, 2, 3, 0)
}
const inputShape = x.tensor.shape
const outputShape = [
inputShape[0] + this.padding[0] * 2,
inputShape[1] + this.padding[1] * 2,
inputShape[2] + this.padding[2] * 2,
inputShape[3]
]
let y = new Tensor([], outputShape)
ops.assign(
y.tensor
.hi(
inputShape[0] + this.padding[0],
inputShape[1] + this.padding[1],
inputShape[2] + this.padding[2],
inputShape[3]
)
.lo(this.padding[0], this.padding[1], this.padding[2], 0),
x.tensor
)
x.tensor = y.tensor
// convert back to th ordering if necessary
if (this.dimOrdering === 'th') {
x.tensor = x.tensor.transpose(3, 0, 1, 2)
}
return x
}
}
+7 -1
View File
@@ -4,6 +4,9 @@ import Convolution3D from './Convolution3D'
import UpSampling1D from './UpSampling1D'
import UpSampling2D from './UpSampling2D'
import UpSampling3D from './UpSampling3D'
import ZeroPadding1D from './ZeroPadding1D'
import ZeroPadding2D from './ZeroPadding2D'
import ZeroPadding3D from './ZeroPadding3D'
export {
Convolution1D,
@@ -11,5 +14,8 @@ export {
Convolution3D,
UpSampling1D,
UpSampling2D,
UpSampling3D
UpSampling3D,
ZeroPadding1D,
ZeroPadding2D,
ZeroPadding3D
}
+48
View File
@@ -0,0 +1,48 @@
/* eslint-env browser, mocha */
describe('convolutional layer: ZeroPadding1D', 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%cconvolutional layer: ZeroPadding1D', styles.h1)
})
it(`[convolutional.ZeroPadding1D.0] padding 1 on 3x5 input`, function () {
const key = `convolutional.ZeroPadding1D.0`
console.log(`\n%c[${key}] padding 1 on 3x5 input`, styles.h3)
let testLayer = new layers.ZeroPadding1D(1)
let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
const startTime = performance.now()
t = testLayer.call(t)
const endTime = performance.now()
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
logTime(startTime, endTime)
const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
const shapeExpected = TEST_DATA[key].expected.shape
assert.deepEqual(t.tensor.shape, shapeExpected)
assert.isTrue(approxEquals(t.tensor, dataExpected))
})
it(`[convolutional.ZeroPadding1D.1] padding 3 on 4x4 input`, function () {
const key = `convolutional.ZeroPadding1D.1`
console.log(`\n%c[${key}] padding 3 on 4x4 input`, styles.h3)
let testLayer = new layers.ZeroPadding1D(3)
let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
const startTime = performance.now()
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))
})
})
+82
View File
@@ -0,0 +1,82 @@
/* eslint-env browser, mocha */
describe('convolutional layer: ZeroPadding2D', 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%cconvolutional layer: ZeroPadding2D', styles.h1)
})
it(`[convolutional.ZeroPadding2D.0] padding 1,1 on 3x5x2 input, dimOrdering=tf`, function () {
const key = `convolutional.ZeroPadding2D.0`
console.log(`\n%c[${key}] padding 1,1 on 3x5x2 input, dimOrdering=tf`, styles.h3)
let testLayer = new layers.ZeroPadding2D([1, 1], { dimOrdering: 'tf' })
let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
const startTime = performance.now()
t = testLayer.call(t)
const endTime = performance.now()
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
logTime(startTime, endTime)
const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
const shapeExpected = TEST_DATA[key].expected.shape
assert.deepEqual(t.tensor.shape, shapeExpected)
assert.isTrue(approxEquals(t.tensor, dataExpected))
})
it(`[convolutional.ZeroPadding2D.1] padding 1,1 on 3x5x2 input, dimOrdering=th`, function () {
const key = `convolutional.ZeroPadding2D.1`
console.log(`\n%c[${key}] padding 1,1 on 3x5x2 input, dimOrdering=th`, styles.h3)
let testLayer = new layers.ZeroPadding2D([1, 1], { dimOrdering: 'th' })
let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
const startTime = performance.now()
t = testLayer.call(t)
const endTime = performance.now()
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
logTime(startTime, endTime)
const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
const shapeExpected = TEST_DATA[key].expected.shape
assert.deepEqual(t.tensor.shape, shapeExpected)
assert.isTrue(approxEquals(t.tensor, dataExpected))
})
it(`[convolutional.ZeroPadding2D.2] padding 3,2 on 2x6x4 input, dimOrdering=tf`, function () {
const key = `convolutional.ZeroPadding2D.2`
console.log(`\n%c[${key}] padding 3,2 on 2x6x4 input, dimOrdering=tf`, styles.h3)
let testLayer = new layers.ZeroPadding2D([3, 2], { dimOrdering: 'tf' })
let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
const startTime = performance.now()
t = testLayer.call(t)
const endTime = performance.now()
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
logTime(startTime, endTime)
const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
const shapeExpected = TEST_DATA[key].expected.shape
assert.deepEqual(t.tensor.shape, shapeExpected)
assert.isTrue(approxEquals(t.tensor, dataExpected))
})
it(`[convolutional.ZeroPadding2D.3] padding 3,2 on 2x6x4 input, dimOrdering=th`, function () {
const key = `convolutional.ZeroPadding2D.3`
console.log(`\n%c[${key}] padding 3,2 on 2x6x4 input, dimOrdering=th`, styles.h3)
let testLayer = new layers.ZeroPadding2D([3, 2], { dimOrdering: 'th' })
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))
})
})
+82
View File
@@ -0,0 +1,82 @@
/* eslint-env browser, mocha */
describe('convolutional layer: ZeroPadding3D', 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%cconvolutional layer: ZeroPadding3D', styles.h1)
})
it(`[convolutional.ZeroPadding3D.0] padding 1,1,1 on 3x5x2x2 input, dimOrdering=tf`, function () {
const key = `convolutional.ZeroPadding3D.0`
console.log(`\n%c[${key}] padding 1,1,1 on 3x5x2x2 input, dimOrdering=tf`, styles.h3)
let testLayer = new layers.ZeroPadding3D([1, 1, 1], { dimOrdering: 'tf' })
let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
const startTime = performance.now()
t = testLayer.call(t)
const endTime = performance.now()
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
logTime(startTime, endTime)
const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
const shapeExpected = TEST_DATA[key].expected.shape
assert.deepEqual(t.tensor.shape, shapeExpected)
assert.isTrue(approxEquals(t.tensor, dataExpected))
})
it(`[convolutional.ZeroPadding3D.1] padding 1,1,1 on 3x5x2x2 input, dimOrdering=th`, function () {
const key = `convolutional.ZeroPadding3D.1`
console.log(`\n%c[${key}] padding 1,1,1 on 3x5x2x2 input, dimOrdering=th`, styles.h3)
let testLayer = new layers.ZeroPadding3D([1, 1, 1], { dimOrdering: 'th' })
let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
const startTime = performance.now()
t = testLayer.call(t)
const endTime = performance.now()
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
logTime(startTime, endTime)
const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
const shapeExpected = TEST_DATA[key].expected.shape
assert.deepEqual(t.tensor.shape, shapeExpected)
assert.isTrue(approxEquals(t.tensor, dataExpected))
})
it(`[convolutional.ZeroPadding3D.2] padding 3,2,2 on 3x2x1x4 input, dimOrdering=tf`, function () {
const key = `convolutional.ZeroPadding3D.2`
console.log(`\n%c[${key}] padding 3,2,2 on 3x2x1x4 input, dimOrdering=tf`, styles.h3)
let testLayer = new layers.ZeroPadding3D([3, 2, 2], { dimOrdering: 'tf' })
let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
const startTime = performance.now()
t = testLayer.call(t)
const endTime = performance.now()
console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
logTime(startTime, endTime)
const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
const shapeExpected = TEST_DATA[key].expected.shape
assert.deepEqual(t.tensor.shape, shapeExpected)
assert.isTrue(approxEquals(t.tensor, dataExpected))
})
it(`[convolutional.ZeroPadding3D.3] padding 3,2,2 on 3x2x1x4 input, dimOrdering=th`, function () {
const key = `convolutional.ZeroPadding3D.3`
console.log(`\n%c[${key}] padding 3,2,2 on 3x2x1x4 input, dimOrdering=th`, styles.h3)
let testLayer = new layers.ZeroPadding3D([3, 2, 2], { dimOrdering: 'th' })
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))
})
})
+30
View File
@@ -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.ZeroPadding1D.0': {
input: {
data: [-0.412987, -0.139246, 0.567466, -0.512174, -0.33603, 0.585584, 0.453472, 0.942013, -0.609538, -0.894302, 0.711927, -0.126057, 0.677549, 0.676991, 0.471487],
shape: [3, 5]
},
expected: {
data: [0.0, 0.0, 0.0, 0.0, 0.0, -0.412987, -0.139246, 0.567466, -0.512174, -0.33603, 0.585584, 0.453472, 0.942013, -0.609538, -0.894302, 0.711927, -0.126057, 0.677549, 0.676991, 0.471487, 0.0, 0.0, 0.0, 0.0, 0.0],
shape: [5, 5]
}
},
'convolutional.ZeroPadding1D.1': {
input: {
data: [0.229895, 0.156613, -0.66952, -0.996975, 0.45773, 0.684298, -0.999213, 0.276751, -0.484373, -0.506163, 0.353904, 0.513668, -0.981594, 0.78914, 0.603978, 0.204066],
shape: [4, 4]
},
expected: {
data: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.229895, 0.156613, -0.66952, -0.996975, 0.45773, 0.684298, -0.999213, 0.276751, -0.484373, -0.506163, 0.353904, 0.513668, -0.981594, 0.78914, 0.603978, 0.204066, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
shape: [10, 4]
}
}
}
window.TEST_DATA = Object.assign({}, window.TEST_DATA, DATA)
})()
+50
View File
@@ -0,0 +1,50 @@
// 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.ZeroPadding2D.0': {
input: {
data: [-0.570441, -0.454673, -0.285321, 0.237249, 0.282682, 0.428035, 0.160547, -0.332203, 0.546391, 0.272735, 0.010827, -0.763164, -0.442696, 0.381948, -0.676994, 0.753553, -0.031788, 0.915329, -0.738844, 0.269075, 0.434091, 0.991585, -0.944288, 0.258834, 0.162138, 0.565201, -0.492094, 0.170854, -0.139788, -0.710674],
shape: [3, 5, 2]
},
expected: {
data: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.570441, -0.454673, -0.285321, 0.237249, 0.282682, 0.428035, 0.160547, -0.332203, 0.546391, 0.272735, 0.0, 0.0, 0.0, 0.0, 0.010827, -0.763164, -0.442696, 0.381948, -0.676994, 0.753553, -0.031788, 0.915329, -0.738844, 0.269075, 0.0, 0.0, 0.0, 0.0, 0.434091, 0.991585, -0.944288, 0.258834, 0.162138, 0.565201, -0.492094, 0.170854, -0.139788, -0.710674, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
shape: [5, 7, 2]
}
},
'convolutional.ZeroPadding2D.1': {
input: {
data: [-0.570441, -0.454673, -0.285321, 0.237249, 0.282682, 0.428035, 0.160547, -0.332203, 0.546391, 0.272735, 0.010827, -0.763164, -0.442696, 0.381948, -0.676994, 0.753553, -0.031788, 0.915329, -0.738844, 0.269075, 0.434091, 0.991585, -0.944288, 0.258834, 0.162138, 0.565201, -0.492094, 0.170854, -0.139788, -0.710674],
shape: [3, 5, 2]
},
expected: {
data: [0.0, 0.0, 0.0, 0.0, 0.0, -0.570441, -0.454673, 0.0, 0.0, -0.285321, 0.237249, 0.0, 0.0, 0.282682, 0.428035, 0.0, 0.0, 0.160547, -0.332203, 0.0, 0.0, 0.546391, 0.272735, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.010827, -0.763164, 0.0, 0.0, -0.442696, 0.381948, 0.0, 0.0, -0.676994, 0.753553, 0.0, 0.0, -0.031788, 0.915329, 0.0, 0.0, -0.738844, 0.269075, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.434091, 0.991585, 0.0, 0.0, -0.944288, 0.258834, 0.0, 0.0, 0.162138, 0.565201, 0.0, 0.0, -0.492094, 0.170854, 0.0, 0.0, -0.139788, -0.710674, 0.0, 0.0, 0.0, 0.0, 0.0],
shape: [3, 7, 4]
}
},
'convolutional.ZeroPadding2D.2': {
input: {
data: [-0.989173, -0.133618, -0.505338, 0.023259, 0.503982, -0.303769, -0.436321, 0.793911, 0.416102, 0.806405, -0.098342, -0.738022, -0.982676, 0.805073, 0.741244, -0.941634, -0.253526, -0.136544, -0.295772, 0.207565, -0.517246, -0.686963, -0.176235, -0.354111, -0.862411, -0.969822, 0.200074, 0.290718, -0.038623, 0.294839, 0.247968, 0.557946, -0.455596, 0.6624, 0.879529, -0.466772, 0.40423, 0.213794, 0.645662, -0.044634, -0.552595, 0.771242, -0.131944, -0.172725, 0.700856, -0.001994, 0.606737, -0.593306],
shape: [2, 6, 4]
},
expected: {
data: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.989173, -0.133618, -0.505338, 0.023259, 0.503982, -0.303769, -0.436321, 0.793911, 0.416102, 0.806405, -0.098342, -0.738022, -0.982676, 0.805073, 0.741244, -0.941634, -0.253526, -0.136544, -0.295772, 0.207565, -0.517246, -0.686963, -0.176235, -0.354111, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.862411, -0.969822, 0.200074, 0.290718, -0.038623, 0.294839, 0.247968, 0.557946, -0.455596, 0.6624, 0.879529, -0.466772, 0.40423, 0.213794, 0.645662, -0.044634, -0.552595, 0.771242, -0.131944, -0.172725, 0.700856, -0.001994, 0.606737, -0.593306, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
shape: [8, 10, 4]
}
},
'convolutional.ZeroPadding2D.3': {
input: {
data: [-0.989173, -0.133618, -0.505338, 0.023259, 0.503982, -0.303769, -0.436321, 0.793911, 0.416102, 0.806405, -0.098342, -0.738022, -0.982676, 0.805073, 0.741244, -0.941634, -0.253526, -0.136544, -0.295772, 0.207565, -0.517246, -0.686963, -0.176235, -0.354111, -0.862411, -0.969822, 0.200074, 0.290718, -0.038623, 0.294839, 0.247968, 0.557946, -0.455596, 0.6624, 0.879529, -0.466772, 0.40423, 0.213794, 0.645662, -0.044634, -0.552595, 0.771242, -0.131944, -0.172725, 0.700856, -0.001994, 0.606737, -0.593306],
shape: [2, 6, 4]
},
expected: {
data: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.989173, -0.133618, -0.505338, 0.023259, 0.0, 0.0, 0.0, 0.0, 0.503982, -0.303769, -0.436321, 0.793911, 0.0, 0.0, 0.0, 0.0, 0.416102, 0.806405, -0.098342, -0.738022, 0.0, 0.0, 0.0, 0.0, -0.982676, 0.805073, 0.741244, -0.941634, 0.0, 0.0, 0.0, 0.0, -0.253526, -0.136544, -0.295772, 0.207565, 0.0, 0.0, 0.0, 0.0, -0.517246, -0.686963, -0.176235, -0.354111, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.862411, -0.969822, 0.200074, 0.290718, 0.0, 0.0, 0.0, 0.0, -0.038623, 0.294839, 0.247968, 0.557946, 0.0, 0.0, 0.0, 0.0, -0.455596, 0.6624, 0.879529, -0.466772, 0.0, 0.0, 0.0, 0.0, 0.40423, 0.213794, 0.645662, -0.044634, 0.0, 0.0, 0.0, 0.0, -0.552595, 0.771242, -0.131944, -0.172725, 0.0, 0.0, 0.0, 0.0, 0.700856, -0.001994, 0.606737, -0.593306, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
shape: [2, 12, 8]
}
}
}
window.TEST_DATA = Object.assign({}, window.TEST_DATA, DATA)
})()
File diff suppressed because one or more lines are too long