Add Cropping1D,2D,3D

This commit is contained in:
2016-11-15 10:43:49 +08:00
parent e76961221d
commit 1b9db86a9a
14 changed files with 1275 additions and 1 deletions
+174
View File
@@ -0,0 +1,174 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"ExecuteTime": {
"end_time": "2016-11-15T10:17:41.918185",
"start_time": "2016-11-15T10:17:41.915648"
},
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\n",
"from keras.models import Model\n",
"from keras.layers import Input\n",
"from keras.layers.convolutional import Cropping1D\n",
"from keras import backend as K"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"ExecuteTime": {
"end_time": "2016-11-15T10:17:42.093433",
"start_time": "2016-11-15T10:17:42.091041"
},
"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": [
"### Cropping1D"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**[convolutional.Cropping1D.0] cropping (1,1) on 6x4 input**"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"ExecuteTime": {
"end_time": "2016-11-15T10:20:10.543929",
"start_time": "2016-11-15T10:20:10.526160"
},
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"in shape: (6, 4)\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, 0.752844, 0.218213, 0.37408, 0.09404, -0.786108, -0.1961, -0.031679, -0.188902, 0.846634]\n",
"out shape: (4, 4)\n",
"out: [-0.33603, 0.585584, 0.453472, 0.942013, -0.609538, -0.894302, 0.711927, -0.126057, 0.677549, 0.676991, 0.471487, 0.752844, 0.218213, 0.37408, 0.09404, -0.786108]\n"
]
}
],
"source": [
"data_in_shape = (6, 4)\n",
"L = Cropping1D(cropping=(1,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.Cropping1D.1] cropping (2,3) on 6x4 input**"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"ExecuteTime": {
"end_time": "2016-11-15T10:19:26.401100",
"start_time": "2016-11-15T10:19:26.382981"
},
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"in shape: (6, 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, 0.532874, 0.866766, -0.544852, 0.876693, -0.523052, -0.716556, 0.875262, 0.544879]\n",
"out shape: (1, 4)\n",
"out: [-0.484373, -0.506163, 0.353904, 0.513668]\n"
]
}
],
"source": [
"data_in_shape = (6, 4)\n",
"L = Cropping1D(cropping=(2,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 (with sys packages)",
"language": "python",
"name": "py3syspck"
},
"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.4.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
+289
View File
@@ -0,0 +1,289 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2016-11-15T10:05:43.575560",
"start_time": "2016-11-15T10:05:42.736839"
},
"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 Cropping2D\n",
"from keras import backend as K"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2016-11-15T10:05:43.681603",
"start_time": "2016-11-15T10:05:43.678284"
},
"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": [
"### Cropping2D"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**[convolutional.Cropping2D.0] cropping (1,1),(1, 1) on 3x5x4 input, dim_ordering=tf**"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"ExecuteTime": {
"end_time": "2016-11-15T10:06:18.618446",
"start_time": "2016-11-15T10:06:18.599690"
},
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"in shape: (3, 5, 4)\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, 0.406968, 0.705926, -0.094137, -0.793497, -0.040684, 0.522292, 0.490496, -0.651771, 0.293113, -0.580922, -0.396436, 0.864522, -0.411659, 0.317379, 0.771844, 0.507235, 0.067782, 0.922641, -0.944205, 0.383713, -0.380187, -0.875176, 0.799314, -0.681818, -0.761323, 0.768315, -0.298568, -0.611688, -0.768656, 0.525693]\n",
"out shape: (1, 3, 4)\n",
"out: [0.162138, 0.565201, -0.492094, 0.170854, -0.139788, -0.710674, 0.406968, 0.705926, -0.094137, -0.793497, -0.040684, 0.522292]\n"
]
}
],
"source": [
"data_in_shape = (3, 5, 4)\n",
"L = Cropping2D(cropping=((1,1),(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.Cropping2D.1] cropping (1,1),(1, 1) on 3x5x4 input, dim_ordering=th**"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"ExecuteTime": {
"end_time": "2016-11-15T10:06:23.116129",
"start_time": "2016-11-15T10:06:23.092950"
},
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"in shape: (3, 5, 4)\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, 0.406968, 0.705926, -0.094137, -0.793497, -0.040684, 0.522292, 0.490496, -0.651771, 0.293113, -0.580922, -0.396436, 0.864522, -0.411659, 0.317379, 0.771844, 0.507235, 0.067782, 0.922641, -0.944205, 0.383713, -0.380187, -0.875176, 0.799314, -0.681818, -0.761323, 0.768315, -0.298568, -0.611688, -0.768656, 0.525693]\n",
"out shape: (3, 3, 2)\n",
"out: [0.428035, 0.160547, 0.272735, 0.010827, 0.381948, -0.676994, 0.565201, -0.492094, -0.710674, 0.406968, -0.793497, -0.040684, 0.507235, 0.067782, 0.383713, -0.380187, -0.681818, -0.761323]\n"
]
}
],
"source": [
"data_in_shape = (3, 5, 4)\n",
"L = Cropping2D(cropping=((1,1),(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.Cropping2D.2] cropping (4,2),(3,1) on 8x7x6 input, dim_ordering=tf**"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"ExecuteTime": {
"end_time": "2016-11-15T10:06:23.525520",
"start_time": "2016-11-15T10:06:23.501122"
},
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"in shape: (8, 7, 6)\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, 0.898062, -0.203771, 0.645788, 0.596358, -0.571654, -0.636819, -0.367376, -0.892607, -0.123297, 0.748404, -0.783012, 0.061963, -0.908546, -0.988517, 0.97308, 0.483845, 0.967956, 0.95863, 0.633963, -0.109138, -0.615821, -0.479821, 0.42827, 0.761351, 0.108265, -0.835679, -0.200177, 0.556308, -0.346135, -0.591775, 0.888818, 0.088756, 0.887542, 0.231398, -0.062874, 0.379803, 0.248259, -0.004909, -0.694836, 0.246241, 0.576698, 0.877474, 0.353439, 0.528707, 0.585634, -0.985339, 0.438776, -0.314863, 0.784171, 0.12525, 0.889265, -0.644213, 0.052514, 0.733269, 0.099278, -0.141949, 0.498542, 0.735955, 0.760313, -0.660278, -0.604273, 0.199522, 0.346309, -0.488666, 0.706332, 0.995574, 0.234642, 0.042779, 0.583139, 0.159919, 0.104808, 0.232585, 0.625624, 0.748204, -0.878399, 0.514601, -0.392989, -0.835864, 0.247256, -0.889704, -0.776558, 0.069902, -0.982291, 0.139565, 0.559765, 0.364254, -0.167329, -0.027032, -0.396669, 0.887928, 0.24142, -0.950083, -0.354758, 0.815999, -0.533224, 0.001955, -0.997966, -0.716888, 0.861882, -0.883, 0.797625, 0.602008, -0.633245, -0.710132, 0.608369, -0.784398, 0.576564, 0.633279, 0.542795, 0.90345, 0.457414, 0.242734, 0.310622, -0.82517, 0.262998, -0.571046, 0.936527, 0.878469, -0.347791, -0.859749, -0.952931, -0.129702, 0.685477, -0.796418, 0.377681, 0.858414, -0.835134, 0.014816, 0.103085, 0.850919, -0.005764, 0.715943, 0.003942, 0.746505, -0.422674, 0.819656, 0.037147, 0.078259, 0.609219, 0.240121, -0.457013, -0.947625, -0.598543, 0.754378, 0.694688, 0.001741, -0.731877, -0.442437, 0.116966, 0.360755, 0.396709, 0.018889, -0.243222, 0.03233, 0.154516, 0.04915, 0.942633, -0.225662, 0.778155, 0.927135, -0.298936, -0.73013, -0.978144, -0.838932, 0.085808, -0.636771, -0.209125, 0.739682, 0.447976, -0.737185, 0.645007, -0.038338, -0.031764, -0.667117, -0.075763, 0.701876, 0.505738, 0.997181, -0.554428, -0.862689, 0.966555, 0.401094, -0.489316, 0.197598, 0.440944, 0.437652, -0.078096, 0.271921, 0.702964, -0.154695, 0.964746, 0.089738, -0.530063, -0.374368, -0.501949, -0.435823, -0.059041, 0.059762, 0.18368, -0.879219, -0.853283, 0.463376, 0.790678, -0.906068, -0.772338, 0.117419, 0.409168, 0.219139, -0.017059, 0.552391, 0.835856, -0.710045, 0.404615, -0.182959, -0.331881, -0.395508, -0.730692, 0.252354, 0.915251, -0.79357, 0.70079, -0.011832, -0.18324, 0.070365, 0.769189, 0.383026, -0.868293, 0.800455, 0.727587, -0.62417, -0.300598, -0.63724, -0.08886, 0.176103, 0.086305, -0.782202, -0.719459, -0.153585, -0.037527, 0.923902, 0.043134, -0.500307, -0.862448, -0.591515, 0.803712, 0.066251, -0.016947, 0.412293, -0.004009, 0.370996, -0.556311, -0.286518, -0.454324, 0.069928, -0.002182, -0.425322, 0.99516, 0.537532, 0.054711, 0.22533, -0.238724, 0.495853, 0.901436, 0.405811, -0.430268, -0.542533, -0.663813, -0.007121, 0.462074, -0.349408, 0.257701, 0.493632, -0.674434, -0.235252, 0.039342, 0.166896, 0.724501, 0.41962, -0.566634, 0.811497, 0.614648, -0.109631, -0.830493, -0.022923, -0.890479, 0.487839, 0.967617, 0.629215]\n",
"out shape: (2, 3, 6)\n",
"out: [0.609218, 0.240121, -0.457013, -0.947625, -0.598543, 0.754378, 0.694688, 0.001741, -0.731877, -0.442437, 0.116966, 0.360755, 0.396709, 0.018889, -0.243222, 0.03233, 0.154516, 0.04915, 0.966555, 0.401094, -0.489316, 0.197598, 0.440944, 0.437652, -0.078096, 0.271921, 0.702964, -0.154695, 0.964746, 0.089738, -0.530063, -0.374368, -0.501949, -0.435823, -0.059041, 0.059762]\n"
]
}
],
"source": [
"data_in_shape = (8, 7, 6)\n",
"L = Cropping2D(cropping=((4,2),(3,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(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.Cropping2D.3] cropping (4,2),(3,1) on 8x7x6 input, dim_ordering=th**"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"ExecuteTime": {
"end_time": "2016-11-15T10:06:23.828740",
"start_time": "2016-11-15T10:06:23.813107"
},
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"in shape: (8, 7, 6)\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, 0.898062, -0.203771, 0.645788, 0.596358, -0.571654, -0.636819, -0.367376, -0.892607, -0.123297, 0.748404, -0.783012, 0.061963, -0.908546, -0.988517, 0.97308, 0.483845, 0.967956, 0.95863, 0.633963, -0.109138, -0.615821, -0.479821, 0.42827, 0.761351, 0.108265, -0.835679, -0.200177, 0.556308, -0.346135, -0.591775, 0.888818, 0.088756, 0.887542, 0.231398, -0.062874, 0.379803, 0.248259, -0.004909, -0.694836, 0.246241, 0.576698, 0.877474, 0.353439, 0.528707, 0.585634, -0.985339, 0.438776, -0.314863, 0.784171, 0.12525, 0.889265, -0.644213, 0.052514, 0.733269, 0.099278, -0.141949, 0.498542, 0.735955, 0.760313, -0.660278, -0.604273, 0.199522, 0.346309, -0.488666, 0.706332, 0.995574, 0.234642, 0.042779, 0.583139, 0.159919, 0.104808, 0.232585, 0.625624, 0.748204, -0.878399, 0.514601, -0.392989, -0.835864, 0.247256, -0.889704, -0.776558, 0.069902, -0.982291, 0.139565, 0.559765, 0.364254, -0.167329, -0.027032, -0.396669, 0.887928, 0.24142, -0.950083, -0.354758, 0.815999, -0.533224, 0.001955, -0.997966, -0.716888, 0.861882, -0.883, 0.797625, 0.602008, -0.633245, -0.710132, 0.608369, -0.784398, 0.576564, 0.633279, 0.542795, 0.90345, 0.457414, 0.242734, 0.310622, -0.82517, 0.262998, -0.571046, 0.936527, 0.878469, -0.347791, -0.859749, -0.952931, -0.129702, 0.685477, -0.796418, 0.377681, 0.858414, -0.835134, 0.014816, 0.103085, 0.850919, -0.005764, 0.715943, 0.003942, 0.746505, -0.422674, 0.819656, 0.037147, 0.078259, 0.609219, 0.240121, -0.457013, -0.947625, -0.598543, 0.754378, 0.694688, 0.001741, -0.731877, -0.442437, 0.116966, 0.360755, 0.396709, 0.018889, -0.243222, 0.03233, 0.154516, 0.04915, 0.942633, -0.225662, 0.778155, 0.927135, -0.298936, -0.73013, -0.978144, -0.838932, 0.085808, -0.636771, -0.209125, 0.739682, 0.447976, -0.737185, 0.645007, -0.038338, -0.031764, -0.667117, -0.075763, 0.701876, 0.505738, 0.997181, -0.554428, -0.862689, 0.966555, 0.401094, -0.489316, 0.197598, 0.440944, 0.437652, -0.078096, 0.271921, 0.702964, -0.154695, 0.964746, 0.089738, -0.530063, -0.374368, -0.501949, -0.435823, -0.059041, 0.059762, 0.18368, -0.879219, -0.853283, 0.463376, 0.790678, -0.906068, -0.772338, 0.117419, 0.409168, 0.219139, -0.017059, 0.552391, 0.835856, -0.710045, 0.404615, -0.182959, -0.331881, -0.395508, -0.730692, 0.252354, 0.915251, -0.79357, 0.70079, -0.011832, -0.18324, 0.070365, 0.769189, 0.383026, -0.868293, 0.800455, 0.727587, -0.62417, -0.300598, -0.63724, -0.08886, 0.176103, 0.086305, -0.782202, -0.719459, -0.153585, -0.037527, 0.923902, 0.043134, -0.500307, -0.862448, -0.591515, 0.803712, 0.066251, -0.016947, 0.412293, -0.004009, 0.370996, -0.556311, -0.286518, -0.454324, 0.069928, -0.002182, -0.425322, 0.99516, 0.537532, 0.054711, 0.22533, -0.238724, 0.495853, 0.901436, 0.405811, -0.430268, -0.542533, -0.663813, -0.007121, 0.462074, -0.349408, 0.257701, 0.493632, -0.674434, -0.235252, 0.039342, 0.166896, 0.724501, 0.41962, -0.566634, 0.811497, 0.614648, -0.109631, -0.830493, -0.022923, -0.890479, 0.487839, 0.967617, 0.629215]\n",
"out shape: (8, 1, 2)\n",
"out: [0.290718, -0.038623, -0.479821, 0.42827, -0.488666, 0.706332, -0.784398, 0.576564, -0.442437, 0.116966, -0.154695, 0.964746, -0.63724, -0.08886, -0.235252, 0.039342]\n"
]
}
],
"source": [
"data_in_shape = (8, 7, 6)\n",
"L = Cropping2D(cropping=((4,2),(3,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(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": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (with sys packages)",
"language": "python",
"name": "py3syspck"
},
"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.4.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
File diff suppressed because one or more lines are too long
+47
View File
@@ -0,0 +1,47 @@
import Layer from '../../Layer'
import Tensor from '../../Tensor'
import ops from 'ndarray-ops'
/**
* Cropping1D layer class
*/
export default class Cropping1D extends Layer {
/**
* Creates a Cropping1D activation layer
* @param {cropping} attrs.cropping - tuple of of int (length 2)
*/
constructor (attrs = {}) {
super(attrs)
this.layerClass = 'Cropping1D'
const {
cropping = [0,0],
dimOrdering = 'tf'
} = attrs
this.cropping = cropping
this.dimOrdering = dimOrdering
}
/**
* Method for layer computational logic
* @param {Tensor} x
* @returns {Tensor} x
*/
call (x) {
const inputShape = x.tensor.shape
const outputShape = [
inputShape[0] - this.cropping[0] - this.cropping[1],
inputShape[1]
]
let y = new Tensor([], outputShape)
ops.assign(
y.tensor,
x.tensor
.hi(inputShape[0] - this.cropping[1], inputShape[2])
.lo(this.cropping[0], 0)
)
x.tensor = y.tensor
return x
}
}
+59
View File
@@ -0,0 +1,59 @@
import Layer from '../../Layer'
import Tensor from '../../Tensor'
import ops from 'ndarray-ops'
/**
* Cropping2D layer class
*/
export default class Cropping2D extends Layer {
/**
* Creates a Cropping2D activation layer
* @param {cropping} attrs.cropping - tuple of tuple of int (length 2)
*/
constructor (attrs = {}) {
super(attrs)
this.layerClass = 'Cropping2D'
const {
cropping = [[0,0], [0,0]],
dimOrdering = 'tf'
} = attrs
this.cropping = cropping
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.cropping[0][0] - this.cropping[0][1],
inputShape[1] - this.cropping[1][0] - this.cropping[1][1],
inputShape[2]
]
let y = new Tensor([], outputShape)
ops.assign(
y.tensor,
x.tensor
.hi(inputShape[0] - this.cropping[0][1], inputShape[1] - this.cropping[1][1], inputShape[2])
.lo(this.cropping[0][0], this.cropping[1][0], 0)
)
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
}
}
+60
View File
@@ -0,0 +1,60 @@
import Layer from '../../Layer'
import Tensor from '../../Tensor'
import ops from 'ndarray-ops'
/**
* Cropping3D layer class
*/
export default class Cropping3D extends Layer {
/**
* Creates a Cropping3D activation layer
* @param {cropping} attrs.cropping - tuple of tuple of int (length 3)
*/
constructor (attrs = {}) {
super(attrs)
this.layerClass = 'Cropping3D'
const {
cropping = [[0,0], [0,0], [0,0]],
dimOrdering = 'tf'
} = attrs
this.cropping = cropping
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.cropping[0][0] - this.cropping[0][1],
inputShape[1] - this.cropping[1][0] - this.cropping[1][1],
inputShape[2] - this.cropping[2][0] - this.cropping[2][1],
inputShape[3]
]
let y = new Tensor([], outputShape)
ops.assign(
y.tensor,
x.tensor
.hi(inputShape[0] - this.cropping[0][1], inputShape[1] - this.cropping[1][1], inputShape[2] - this.cropping[2][1], inputShape[3])
.lo(this.cropping[0][0], this.cropping[1][0], this.cropping[2][0], 0)
)
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
@@ -10,6 +10,9 @@ import UpSampling3D from './UpSampling3D'
import ZeroPadding1D from './ZeroPadding1D'
import ZeroPadding2D from './ZeroPadding2D'
import ZeroPadding3D from './ZeroPadding3D'
import Cropping1D from './Cropping1D'
import Cropping2D from './Cropping2D'
import Cropping3D from './Cropping3D'
export {
Convolution1D,
@@ -23,5 +26,8 @@ export {
UpSampling3D,
ZeroPadding1D,
ZeroPadding2D,
ZeroPadding3D
ZeroPadding3D,
Cropping1D,
Cropping2D,
Cropping3D
}
+48
View File
@@ -0,0 +1,48 @@
/* eslint-env browser, mocha */
describe('convolutional layer: Cropping1D', 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: Cropping1D', styles.h1)
})
it(`[convolutional.Cropping1D.0] cropping (1,1) on 6x4 input`, function () {
const key = `convolutional.Cropping1D.0`
console.log(`\n%c[${key}] cropping (1,1) on 6x4 input`, styles.h3)
let testLayer = new layers.Cropping1D({ cropping: [1,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.Cropping1D.1] cropping (2,3) on 6x4 input`, function () {
const key = `convolutional.Cropping1D.1`
console.log(`\n%c[${key}] cropping (2,3) on 6x4 input`, styles.h3)
let testLayer = new layers.Cropping1D({ cropping: [2,3] })
let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
const startTime = performance.now()
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: Cropping2D', 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: Cropping2D', styles.h1)
})
it(`[convolutional.Cropping2D.0] cropping (1,1),(1, 1) on 3x5x4 input, dim_ordering=tf`, function () {
const key = `convolutional.Cropping2D.0`
console.log(`\n%c[${key}] cropping (1,1),(1, 1) on 3x5x4 input, dimOrdering=tf`, styles.h3)
let testLayer = new layers.Cropping2D({ cropping: [[1, 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.Cropping2D.0] cropping (1,1),(1, 1) on 3x5x4 input, dim_ordering=th`, function () {
const key = `convolutional.Cropping2D.1`
console.log(`\n%c[${key}] cropping (1,1),(1, 1) on 3x5x4 input, dimOrdering=th`, styles.h3)
let testLayer = new layers.Cropping2D({ cropping: [[1, 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.Cropping2D.2] cropping (4,2),(3,1) on 8x7x6 input, dim_ordering=tf`, function () {
const key = `convolutional.Cropping2D.2`
console.log(`\n%c[${key}] cropping (4,2),(3,1) on 8x7x6 input, dimOrdering=tf`, styles.h3)
let testLayer = new layers.Cropping2D({ cropping: [[4,2],[3,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.Cropping2D.2] cropping (4,2),(3,1) on 8x7x6 input, dim_ordering=th`, function () {
const key = `convolutional.Cropping2D.3`
console.log(`\n%c[${key}] cropping (4,2),(3,1) on 8x7x6 input, dimOrdering=th`, styles.h3)
let testLayer = new layers.Cropping2D({ cropping: [[4,2],[3,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))
})
})
+82
View File
@@ -0,0 +1,82 @@
/* eslint-env browser, mocha */
describe('convolutional layer: Cropping3D', 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: Cropping3D', styles.h1)
})
it(`[convolutional.Cropping3D.0] cropping ((1,1), (1,1), (1,1)) on 3x5x3x3 input, dim_ordering=tf`, function () {
const key = `convolutional.Cropping3D.0`
console.log(`\n%c[${key}] cropping ((1,1), (1,1), (1,1)) on 3x5x3x3 input, dim_ordering=tf`, styles.h3)
let testLayer = new layers.Cropping3D({ cropping: [[1, 1], [1, 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.Cropping3D.0] cropping ((1,1), (1,1), (1,1)) on 3x5x3x3 input, dim_ordering=th`, function () {
const key = `convolutional.Cropping3D.1`
console.log(`\n%c[${key}] cropping ((1,1), (1,1), (1,1)) on 3x5x3x3 input, dim_ordering=th`, styles.h3)
let testLayer = new layers.Cropping3D({ cropping: [[1, 1], [1, 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.Cropping3D.2] cropping (3,2), (2,1), (2,3)) on 7x6x6x6 input, dim_ordering=tf`, function () {
const key = `convolutional.Cropping3D.2`
console.log(`\n%c[${key}] cropping (3,2), (2,1), (2,3)) on 7x6x6x6 input, dim_ordering=tf`, styles.h3)
let testLayer = new layers.Cropping3D({ cropping: [[3,2],[2,1],[2,3]], 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.Cropping3D.2] cropping (3,2), (2,1), (2,3)) on 7x6x6x6 input, dim_ordering=th`, function () {
const key = `convolutional.Cropping3D.3`
console.log(`\n%c[${key}] cropping (3,2), (2,1), (2,3)) on 7x6x6x6 input, dim_ordering=th`, styles.h3)
let testLayer = new layers.Cropping3D({ cropping: [[3,2],[2,1],[2,3]], 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.Cropping1D.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, 0.752844, 0.218213, 0.37408, 0.09404, -0.786108, -0.1961, -0.031679, -0.188902, 0.846634],
shape: [6,4]
},
expected: {
data: [-0.33603, 0.585584, 0.453472, 0.942013, -0.609538, -0.894302, 0.711927, -0.126057, 0.677549, 0.676991, 0.471487, 0.752844, 0.218213, 0.37408, 0.09404, -0.786108],
shape: [4, 4]
}
},
'convolutional.Cropping1D.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, 0.532874, 0.866766, -0.544852, 0.876693, -0.523052, -0.716556, 0.875262, 0.544879],
shape: [6, 4]
},
expected: {
data: [-0.484373, -0.506163, 0.353904, 0.513668],
shape: [1, 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.Cropping2D.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, 0.406968, 0.705926, -0.094137, -0.793497, -0.040684, 0.522292, 0.490496, -0.651771, 0.293113, -0.580922, -0.396436, 0.864522, -0.411659, 0.317379, 0.771844, 0.507235, 0.067782, 0.922641, -0.944205, 0.383713, -0.380187, -0.875176, 0.799314, -0.681818, -0.761323, 0.768315, -0.298568, -0.611688, -0.768656, 0.525693],
shape: [3, 5, 4]
},
expected: {
data: [0.162138, 0.565201, -0.492094, 0.170854, -0.139788, -0.710674, 0.406968, 0.705926, -0.094137, -0.793497, -0.040684, 0.522292],
shape: [1, 3, 4]
}
},
'convolutional.Cropping2D.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, 0.406968, 0.705926, -0.094137, -0.793497, -0.040684, 0.522292, 0.490496, -0.651771, 0.293113, -0.580922, -0.396436, 0.864522, -0.411659, 0.317379, 0.771844, 0.507235, 0.067782, 0.922641, -0.944205, 0.383713, -0.380187, -0.875176, 0.799314, -0.681818, -0.761323, 0.768315, -0.298568, -0.611688, -0.768656, 0.525693],
shape: [3, 5, 4]
},
expected: {
data: [0.428035, 0.160547, 0.272735, 0.010827, 0.381948, -0.676994, 0.565201, -0.492094, -0.710674, 0.406968, -0.793497, -0.040684, 0.507235, 0.067782, 0.383713, -0.380187, -0.681818, -0.761323],
shape: [3, 3, 2]
}
},
'convolutional.Cropping2D.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, 0.898062, -0.203771, 0.645788, 0.596358, -0.571654, -0.636819, -0.367376, -0.892607, -0.123297, 0.748404, -0.783012, 0.061963, -0.908546, -0.988517, 0.97308, 0.483845, 0.967956, 0.95863, 0.633963, -0.109138, -0.615821, -0.479821, 0.42827, 0.761351, 0.108265, -0.835679, -0.200177, 0.556308, -0.346135, -0.591775, 0.888818, 0.088756, 0.887542, 0.231398, -0.062874, 0.379803, 0.248259, -0.004909, -0.694836, 0.246241, 0.576698, 0.877474, 0.353439, 0.528707, 0.585634, -0.985339, 0.438776, -0.314863, 0.784171, 0.12525, 0.889265, -0.644213, 0.052514, 0.733269, 0.099278, -0.141949, 0.498542, 0.735955, 0.760313, -0.660278, -0.604273, 0.199522, 0.346309, -0.488666, 0.706332, 0.995574, 0.234642, 0.042779, 0.583139, 0.159919, 0.104808, 0.232585, 0.625624, 0.748204, -0.878399, 0.514601, -0.392989, -0.835864, 0.247256, -0.889704, -0.776558, 0.069902, -0.982291, 0.139565, 0.559765, 0.364254, -0.167329, -0.027032, -0.396669, 0.887928, 0.24142, -0.950083, -0.354758, 0.815999, -0.533224, 0.001955, -0.997966, -0.716888, 0.861882, -0.883, 0.797625, 0.602008, -0.633245, -0.710132, 0.608369, -0.784398, 0.576564, 0.633279, 0.542795, 0.90345, 0.457414, 0.242734, 0.310622, -0.82517, 0.262998, -0.571046, 0.936527, 0.878469, -0.347791, -0.859749, -0.952931, -0.129702, 0.685477, -0.796418, 0.377681, 0.858414, -0.835134, 0.014816, 0.103085, 0.850919, -0.005764, 0.715943, 0.003942, 0.746505, -0.422674, 0.819656, 0.037147, 0.078259, 0.609219, 0.240121, -0.457013, -0.947625, -0.598543, 0.754378, 0.694688, 0.001741, -0.731877, -0.442437, 0.116966, 0.360755, 0.396709, 0.018889, -0.243222, 0.03233, 0.154516, 0.04915, 0.942633, -0.225662, 0.778155, 0.927135, -0.298936, -0.73013, -0.978144, -0.838932, 0.085808, -0.636771, -0.209125, 0.739682, 0.447976, -0.737185, 0.645007, -0.038338, -0.031764, -0.667117, -0.075763, 0.701876, 0.505738, 0.997181, -0.554428, -0.862689, 0.966555, 0.401094, -0.489316, 0.197598, 0.440944, 0.437652, -0.078096, 0.271921, 0.702964, -0.154695, 0.964746, 0.089738, -0.530063, -0.374368, -0.501949, -0.435823, -0.059041, 0.059762, 0.18368, -0.879219, -0.853283, 0.463376, 0.790678, -0.906068, -0.772338, 0.117419, 0.409168, 0.219139, -0.017059, 0.552391, 0.835856, -0.710045, 0.404615, -0.182959, -0.331881, -0.395508, -0.730692, 0.252354, 0.915251, -0.79357, 0.70079, -0.011832, -0.18324, 0.070365, 0.769189, 0.383026, -0.868293, 0.800455, 0.727587, -0.62417, -0.300598, -0.63724, -0.08886, 0.176103, 0.086305, -0.782202, -0.719459, -0.153585, -0.037527, 0.923902, 0.043134, -0.500307, -0.862448, -0.591515, 0.803712, 0.066251, -0.016947, 0.412293, -0.004009, 0.370996, -0.556311, -0.286518, -0.454324, 0.069928, -0.002182, -0.425322, 0.99516, 0.537532, 0.054711, 0.22533, -0.238724, 0.495853, 0.901436, 0.405811, -0.430268, -0.542533, -0.663813, -0.007121, 0.462074, -0.349408, 0.257701, 0.493632, -0.674434, -0.235252, 0.039342, 0.166896, 0.724501, 0.41962, -0.566634, 0.811497, 0.614648, -0.109631, -0.830493, -0.022923, -0.890479, 0.487839, 0.967617, 0.629215],
shape: [8, 7, 6]
},
expected: {
data: [0.609218, 0.240121, -0.457013, -0.947625, -0.598543, 0.754378, 0.694688, 0.001741, -0.731877, -0.442437, 0.116966, 0.360755, 0.396709, 0.018889, -0.243222, 0.03233, 0.154516, 0.04915, 0.966555, 0.401094, -0.489316, 0.197598, 0.440944, 0.437652, -0.078096, 0.271921, 0.702964, -0.154695, 0.964746, 0.089738, -0.530063, -0.374368, -0.501949, -0.435823, -0.059041, 0.059762],
shape: [2, 3, 6]
}
},
'convolutional.Cropping2D.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, 0.898062, -0.203771, 0.645788, 0.596358, -0.571654, -0.636819, -0.367376, -0.892607, -0.123297, 0.748404, -0.783012, 0.061963, -0.908546, -0.988517, 0.97308, 0.483845, 0.967956, 0.95863, 0.633963, -0.109138, -0.615821, -0.479821, 0.42827, 0.761351, 0.108265, -0.835679, -0.200177, 0.556308, -0.346135, -0.591775, 0.888818, 0.088756, 0.887542, 0.231398, -0.062874, 0.379803, 0.248259, -0.004909, -0.694836, 0.246241, 0.576698, 0.877474, 0.353439, 0.528707, 0.585634, -0.985339, 0.438776, -0.314863, 0.784171, 0.12525, 0.889265, -0.644213, 0.052514, 0.733269, 0.099278, -0.141949, 0.498542, 0.735955, 0.760313, -0.660278, -0.604273, 0.199522, 0.346309, -0.488666, 0.706332, 0.995574, 0.234642, 0.042779, 0.583139, 0.159919, 0.104808, 0.232585, 0.625624, 0.748204, -0.878399, 0.514601, -0.392989, -0.835864, 0.247256, -0.889704, -0.776558, 0.069902, -0.982291, 0.139565, 0.559765, 0.364254, -0.167329, -0.027032, -0.396669, 0.887928, 0.24142, -0.950083, -0.354758, 0.815999, -0.533224, 0.001955, -0.997966, -0.716888, 0.861882, -0.883, 0.797625, 0.602008, -0.633245, -0.710132, 0.608369, -0.784398, 0.576564, 0.633279, 0.542795, 0.90345, 0.457414, 0.242734, 0.310622, -0.82517, 0.262998, -0.571046, 0.936527, 0.878469, -0.347791, -0.859749, -0.952931, -0.129702, 0.685477, -0.796418, 0.377681, 0.858414, -0.835134, 0.014816, 0.103085, 0.850919, -0.005764, 0.715943, 0.003942, 0.746505, -0.422674, 0.819656, 0.037147, 0.078259, 0.609219, 0.240121, -0.457013, -0.947625, -0.598543, 0.754378, 0.694688, 0.001741, -0.731877, -0.442437, 0.116966, 0.360755, 0.396709, 0.018889, -0.243222, 0.03233, 0.154516, 0.04915, 0.942633, -0.225662, 0.778155, 0.927135, -0.298936, -0.73013, -0.978144, -0.838932, 0.085808, -0.636771, -0.209125, 0.739682, 0.447976, -0.737185, 0.645007, -0.038338, -0.031764, -0.667117, -0.075763, 0.701876, 0.505738, 0.997181, -0.554428, -0.862689, 0.966555, 0.401094, -0.489316, 0.197598, 0.440944, 0.437652, -0.078096, 0.271921, 0.702964, -0.154695, 0.964746, 0.089738, -0.530063, -0.374368, -0.501949, -0.435823, -0.059041, 0.059762, 0.18368, -0.879219, -0.853283, 0.463376, 0.790678, -0.906068, -0.772338, 0.117419, 0.409168, 0.219139, -0.017059, 0.552391, 0.835856, -0.710045, 0.404615, -0.182959, -0.331881, -0.395508, -0.730692, 0.252354, 0.915251, -0.79357, 0.70079, -0.011832, -0.18324, 0.070365, 0.769189, 0.383026, -0.868293, 0.800455, 0.727587, -0.62417, -0.300598, -0.63724, -0.08886, 0.176103, 0.086305, -0.782202, -0.719459, -0.153585, -0.037527, 0.923902, 0.043134, -0.500307, -0.862448, -0.591515, 0.803712, 0.066251, -0.016947, 0.412293, -0.004009, 0.370996, -0.556311, -0.286518, -0.454324, 0.069928, -0.002182, -0.425322, 0.99516, 0.537532, 0.054711, 0.22533, -0.238724, 0.495853, 0.901436, 0.405811, -0.430268, -0.542533, -0.663813, -0.007121, 0.462074, -0.349408, 0.257701, 0.493632, -0.674434, -0.235252, 0.039342, 0.166896, 0.724501, 0.41962, -0.566634, 0.811497, 0.614648, -0.109631, -0.830493, -0.022923, -0.890479, 0.487839, 0.967617, 0.629215],
shape: [8, 7, 6]
},
expected: {
data: [0.290718, -0.038623, -0.479821, 0.42827, -0.488666, 0.706332, -0.784398, 0.576564, -0.442437, 0.116966, -0.154695, 0.964746, -0.63724, -0.08886, -0.235252, 0.039342],
shape: [8, 1, 2]
}
}
}
window.TEST_DATA = Object.assign({}, window.TEST_DATA, DATA)
})()
File diff suppressed because one or more lines are too long
+6
View File
@@ -71,6 +71,12 @@
<script src="convolutional/ZeroPadding2D.js"></script>
<script src="convolutional/data_ZeroPadding3D.js"></script>
<script src="convolutional/ZeroPadding3D.js"></script>
<script src="convolutional/data_Cropping1D.js"></script>
<script src="convolutional/Cropping1D.js"></script>
<script src="convolutional/data_Cropping2D.js"></script>
<script src="convolutional/Cropping2D.js"></script>
<script src="convolutional/data_Cropping3D.js"></script>
<script src="convolutional/Cropping3D.js"></script>
<!-- pooling -->
<script src="pooling/data_MaxPooling1D.js"></script>