Files
2016-11-15 10:43:49 +08:00

16 KiB

In [2]:
import numpy as np
from keras.models import Model
from keras.layers import Input
from keras.layers.convolutional import Cropping2D
from keras import backend as K
Using TensorFlow backend.
In [3]:
def format_decimal(arr, places=6):
    return [round(x * 10**places) / 10**places for x in arr]

Cropping2D

[convolutional.Cropping2D.0] cropping (1,1),(1, 1) on 3x5x4 input, dim_ordering=tf

In [8]:
data_in_shape = (3, 5, 4)
L = Cropping2D(cropping=((1,1),(1, 1)), dim_ordering='tf')

layer_0 = Input(shape=data_in_shape)
layer_1 = L(layer_0)
model = Model(input=layer_0, output=layer_1)

# set weights to random (use seed for reproducibility)
np.random.seed(250)
data_in = 2 * np.random.random(data_in_shape) - 1
print('')
print('in shape:', data_in_shape)
print('in:', format_decimal(data_in.ravel().tolist()))
result = model.predict(np.array([data_in]))
print('out shape:', result[0].shape)
print('out:', format_decimal(result[0].ravel().tolist()))
in shape: (3, 5, 4)
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]
out shape: (1, 3, 4)
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]

[convolutional.Cropping2D.1] cropping (1,1),(1, 1) on 3x5x4 input, dim_ordering=th

In [9]:
data_in_shape = (3, 5, 4)
L = Cropping2D(cropping=((1,1),(1, 1)), dim_ordering='th')

layer_0 = Input(shape=data_in_shape)
layer_1 = L(layer_0)
model = Model(input=layer_0, output=layer_1)

# set weights to random (use seed for reproducibility)
np.random.seed(250)
data_in = 2 * np.random.random(data_in_shape) - 1
print('')
print('in shape:', data_in_shape)
print('in:', format_decimal(data_in.ravel().tolist()))
result = model.predict(np.array([data_in]))
print('out shape:', result[0].shape)
print('out:', format_decimal(result[0].ravel().tolist()))
in shape: (3, 5, 4)
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]
out shape: (3, 3, 2)
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]

[convolutional.Cropping2D.2] cropping (4,2),(3,1) on 8x7x6 input, dim_ordering=tf

In [10]:
data_in_shape = (8, 7, 6)
L = Cropping2D(cropping=((4,2),(3,1)), dim_ordering='tf')

layer_0 = Input(shape=data_in_shape)
layer_1 = L(layer_0)
model = Model(input=layer_0, output=layer_1)

# set weights to random (use seed for reproducibility)
np.random.seed(252)
data_in = 2 * np.random.random(data_in_shape) - 1
print('')
print('in shape:', data_in_shape)
print('in:', format_decimal(data_in.ravel().tolist()))
result = model.predict(np.array([data_in]))
print('out shape:', result[0].shape)
print('out:', format_decimal(result[0].ravel().tolist()))
in shape: (8, 7, 6)
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]
out shape: (2, 3, 6)
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]

[convolutional.Cropping2D.3] cropping (4,2),(3,1) on 8x7x6 input, dim_ordering=th

In [11]:
data_in_shape = (8, 7, 6)
L = Cropping2D(cropping=((4,2),(3,1)), dim_ordering='th')

layer_0 = Input(shape=data_in_shape)
layer_1 = L(layer_0)
model = Model(input=layer_0, output=layer_1)

# set weights to random (use seed for reproducibility)
np.random.seed(252)
data_in = 2 * np.random.random(data_in_shape) - 1
print('')
print('in shape:', data_in_shape)
print('in:', format_decimal(data_in.ravel().tolist()))
result = model.predict(np.array([data_in]))
print('out shape:', result[0].shape)
print('out:', format_decimal(result[0].ravel().tolist()))
in shape: (8, 7, 6)
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]
out shape: (8, 1, 2)
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]
In [ ]:
In [ ]: