In [3]:
import numpy as np
import json
from keras.models import Model
from keras.layers import Input
from keras.layers import Conv2D, MaxPooling2D, AveragePooling2D, BatchNormalization, merge
from keras import backend as K

In [2]:
def format_decimal(arr, places=8):
    return [round(x * 10**places) / 10**places for x in arr]

pipeline 13


In [8]:
data_in_shape = (8, 8, 2)

input_layer_0 = Input(shape=data_in_shape)
branch_0 = Conv2D(4, 3, 3, activation='relu', border_mode='valid', subsample=(1, 1), dim_ordering='tf', bias=True)(input_layer_0)

input_layer_1 = Input(shape=data_in_shape)
branch_1 = Conv2D(4, 3, 3, activation='relu', border_mode='valid', subsample=(1, 1), dim_ordering='tf', bias=True)(input_layer_1)

output_layer = merge([branch_0, branch_1], mode='sum')
model = Model(input=[input_layer_0, input_layer_1], output=output_layer)

data_in = []
for i in range(2):
    np.random.seed(14000 + i)
    data_in.append(np.expand_dims(2 * np.random.random(data_in_shape) - 1, axis=0))

# set weights to random (use seed for reproducibility)
weights = []
for i, w in enumerate(model.get_weights()):
    np.random.seed(14000 + i)
    weights.append(2 * np.random.random(w.shape) - 1)
model.set_weights(weights)

result = model.predict(data_in)

print({
    'inputs': [{'data': format_decimal(data_in[i].ravel().tolist()), 'shape': list(data_in_shape)} for i in range(2)],
    'weights': [{'data': format_decimal(weights[i].ravel().tolist()), 'shape': list(weights[i].shape)} for i in range(len(weights))],
    'expected': {'data': format_decimal(result[0].ravel().tolist()), 'shape': list(result[0].shape)}
})


{'expected': {'data': [0.49210405, 0.78813863, 0.80875194, 0.02256742, 0.0, 1.14902639, 0.0, 1.11243999, 2.13309002, 0.0, 0.44006902, 0.0, 3.53826928, 0.19820355, 0.18296772, 2.48644972, 0.50676137, 1.81432986, 0.73195964, 0.0, 0.50878185, 2.69197035, 0.0, 0.05229884, 0.0, 3.51237178, 0.0, 2.60257316, 0.18060298, 0.45954669, 0.14290473, 0.0, 1.09695649, 0.96614468, 0.03861353, 0.0, 0.97643173, 0.0, 0.0, 1.55073714, 1.27272809, 2.80467463, 1.07905078, 3.81365204, 0.46500301, 0.0, 0.67199701, 1.00177813, 1.55169642, 1.07905459, 1.29224563, 3.05485988, 0.0, 0.0, 0.84400892, 1.88644063, 0.0, 0.0, 0.40178961, 1.11865294, 0.3880142, 1.3144846, 0.0, 0.0, 0.90191823, 1.9006021, 0.0, 1.66821051, 0.31298846, 2.30192852, 0.66049147, 0.0, 1.05352902, 1.24678028, 0.97645408, 0.82053316, 0.95613432, 2.30244541, 0.73437548, 0.0, 0.25425911, 0.19471523, 2.00992203, 0.0, 1.37360823, 0.0, 0.19346008, 1.78056741, 0.91455579, 1.39071429, 1.02137518, 1.50679064, 0.0, 0.94718862, 0.0, 2.27148438, 3.00846195, 0.37041825, 0.2600593, 1.09495115, 0.38782495, 1.37645555, 0.0, 3.05024576, 1.29602182, 1.58189619, 0.53475505, 0.62371898, 0.0, 3.28248072, 1.03542781, 0.0, 0.74798959, 1.39645505, 0.22474456, 0.80222774, 1.4872402, 1.36315942, 0.7029357, 1.01787603, 2.69548988, 3.1335516, 0.0, 0.0, 2.10291624, 0.35781768, 1.60651338, 1.61903679, 2.07757258, 2.50550795, 0.0, 1.00181079, 0.71755189, 0.10277405, 1.72633541, 2.75524282, 1.4232744, 0.34911481, 1.19651127, 0.73669118, 1.04301894, 0.18378244, 0.0, 0.0], 'shape': [6, 6, 4]}, 'weights': [{'data': [0.94636168, -0.60749294, 0.47038978, -0.44810639, -0.23804824, -0.14783996, 0.84259064, -0.12799473, -0.7072945, 0.33832906, -0.39998704, -0.6784409, 0.48128242, 0.88595733, 0.17366553, 0.19317228, -0.87186124, 0.20819267, 0.43340585, 0.34782729, 0.45657324, 0.73403655, -0.28406518, -0.1889677, -0.53545233, -0.89735104, -0.06114965, 0.9709907, -0.02882778, -0.07108202, 0.25275845, 0.18851726, -0.84255677, 0.06989192, -0.26656543, 0.66038004, -0.55384838, 0.12235443, 0.63707637, -0.62159893, -0.76826837, -0.3895198, 0.62734823, 0.11164784, -0.08596045, 0.80988134, 0.32206446, 0.75941775, -0.13577699, 0.5201059, 0.47018927, -0.54722409, 0.54412035, 0.53550267, 0.34895323, -0.16334045, -0.28852756, 0.46748087, -0.44165986, -0.70644566, 0.34930924, 0.32556376, 0.25965428, -0.56220458, -0.02069371, -0.38608416, -0.89569536, -0.35577182, -0.04941919, 0.31347747, 0.2529894, -0.04142487], 'shape': [3, 3, 2, 4]}, {'data': [-0.09437357, 0.47033922, -0.41270746, 0.49966848], 'shape': [4]}, {'data': [-0.22837715, -0.22230936, 0.26823772, 0.05535942, -0.22956455, -0.10234008, -0.50307303, -0.95543367, -0.36785246, -0.4791907, -0.51407323, 0.12021895, 0.52257042, -0.65492285, -0.20476916, 0.81773536, 0.55766873, -0.04743445, -0.75140616, -0.45316717, 0.28676025, 0.12635257, 0.32091179, -0.5669796, 0.06660197, -0.49609356, 0.43052308, -0.95598179, -0.26356655, 0.11926243, -0.01782551, -0.55640167, -0.26311291, 0.24523985, 0.10741962, -0.38807744, 0.02491843, -0.57043266, 0.69741488, 0.24522496, 0.15695022, -0.54070679, 0.93109466, 0.71028652, 0.05828449, 0.10743773, 0.48728289, -0.15727079, -0.64786328, 0.07715914, 0.13573435, 0.95366093, -0.754078, -0.99969626, -0.35330832, 0.45456095, -0.65198138, 0.37340387, 0.0335547, -0.64918599, -0.32317928, -0.02134762, 0.92365292, -0.72473276, -0.07507326, 0.86710689, 0.9254535, 0.93568168, 0.88678517, -0.40467394, -0.63707188, 0.88008026], 'shape': [3, 3, 2, 4]}, {'data': [0.12028789, -0.20679595, -0.6353794, -0.38780904], 'shape': [4]}], 'inputs': [{'data': [0.94636168, -0.60749294, 0.47038978, -0.44810639, -0.23804824, -0.14783996, 0.84259064, -0.12799473, -0.7072945, 0.33832906, -0.39998704, -0.6784409, 0.48128242, 0.88595733, 0.17366553, 0.19317228, -0.87186124, 0.20819267, 0.43340585, 0.34782729, 0.45657324, 0.73403655, -0.28406518, -0.1889677, -0.53545233, -0.89735104, -0.06114965, 0.9709907, -0.02882778, -0.07108202, 0.25275845, 0.18851726, -0.84255677, 0.06989192, -0.26656543, 0.66038004, -0.55384838, 0.12235443, 0.63707637, -0.62159893, -0.76826837, -0.3895198, 0.62734823, 0.11164784, -0.08596045, 0.80988134, 0.32206446, 0.75941775, -0.13577699, 0.5201059, 0.47018927, -0.54722409, 0.54412035, 0.53550267, 0.34895323, -0.16334045, -0.28852756, 0.46748087, -0.44165986, -0.70644566, 0.34930924, 0.32556376, 0.25965428, -0.56220458, -0.02069371, -0.38608416, -0.89569536, -0.35577182, -0.04941919, 0.31347747, 0.2529894, -0.04142487, 0.33058479, -0.5083358, 0.29291231, -0.1090193, 0.3184212, -0.30623713, -0.71170371, 0.48841419, -0.49430721, -0.12712101, 0.66658866, 0.80860656, -0.56360325, -0.28737425, -0.00388397, 0.85984002, -0.85979559, 0.70309115, 0.23724326, 0.05948296, -0.6724265, -0.75589794, 0.60868834, 0.93734424, -0.91503352, 0.24464176, 0.07658801, -0.42395861, -0.70947444, -0.58332417, 0.46941749, 0.83020986, 0.13363719, 0.29060606, 0.39557675, 0.75660875, -0.38284088, 0.02690223, -0.7980595, -0.10038077, 0.82031065, 0.6700165, 0.65694306, 0.07398395, -0.7965507, -0.81284042, -0.39133449, 0.00495174, -0.97658835, 0.67242628, 0.3043187, -0.43132553, 0.54241842, 0.72461939, 0.93129887, -0.85936277], 'shape': [8, 8, 2]}, {'data': [-0.09437357, 0.47033922, -0.41270746, 0.49966848, -0.29680428, -0.26926845, -0.28986893, 0.52261399, 0.20785549, 0.42575224, 0.0505914, 0.73905784, 0.15741574, 0.4561654, 0.53608112, 0.9736292, 0.66103821, -0.35137435, 0.10137471, 0.47979701, 0.52333242, -0.29817146, -0.76149817, 0.11188112, 0.86089847, 0.64889675, 0.53085032, 0.79705619, -0.80495076, 0.99082335, 0.3869455, 0.81624786, -0.74086025, 0.01877771, 0.73596348, -0.1157914, -0.23167594, -0.8042806, -0.11405481, -0.45324934, -0.51174808, -0.46445606, 0.57493807, 0.27395792, 0.7156521, 0.09349372, 0.04282135, 0.8120398, 0.71543101, 0.26712294, -0.33793451, 0.50182053, 0.88078807, 0.51401416, 0.68987873, 0.13588121, -0.08679856, -0.70937881, -0.6960674, -0.33469843, 0.87051261, 0.22195507, -0.65571964, -0.63404223, -0.60637367, -0.98827112, -0.42671223, 0.41378695, 0.64234678, 0.53721155, -0.27927596, 0.45946595, 0.04131866, 0.24375447, 0.97339231, -0.30065302, 0.09442078, 0.50760847, -0.17038862, -0.31169519, 0.1120715, -0.05857511, -0.39830265, 0.48898836, 0.39996455, -0.43435026, -0.08770207, 0.59647305, 0.66503445, -0.65647493, -0.80133391, 0.83030328, 0.15311733, -0.05048314, -0.02749838, 0.32078434, -0.3532473, -0.94276689, -0.90761118, -0.33113375, -0.21700578, -0.75385678, 0.22738094, -0.80139374, 0.85113905, 0.01003838, 0.41078611, -0.62042866, 0.76949463, -0.22720036, -0.79352101, -0.14386886, -0.92328433, 0.33227111, -0.78555295, 0.94496906, -0.84595452, -0.05534949, -0.96951076, 0.44890035, -0.91969642, -0.08033923, -0.26799455, 0.46293057, 0.17503004, -0.22760975, 0.65570771, 0.77487423], 'shape': [8, 8, 2]}]}

In [ ]: