In [1]:
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


Using TensorFlow backend.

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

pipeline 17


In [3]:
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='concat')
model = Model(input=[input_layer_0, input_layer_1], output=output_layer)

data_in = []
for i in range(2):
    np.random.seed(18000 + 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(18000 + 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)}
})


{'inputs': [{'shape': [8, 8, 2], 'data': [-0.43578179, -0.24587564, -0.31801076, 0.34753836, -0.56738897, -0.45134161, 0.01824736, 0.08846209, 0.34164075, -0.06075771, -0.52425908, 0.84696319, -0.90994422, 0.07699325, 0.0418348, 0.17139282, 0.02191952, -0.47532115, 0.44261465, 0.15052111, 0.81292648, 0.17966397, -0.14979486, -0.12341542, 0.59198995, 0.94453008, 0.45679537, 0.92659727, -0.40560174, 0.2672119, 0.46568924, 0.6661548, -0.0242446, -0.26664235, 0.07392619, 0.11392891, -0.51168729, -0.42751139, 0.30796888, 0.971408, 0.08567601, -0.72599117, 0.99679563, -0.00594722, 0.99674088, 0.15055416, 0.48117098, -0.00546953, 0.04776603, 0.41445607, 0.25716868, -0.64896142, 0.56204123, 0.02679717, 0.9354033, 0.78243992, -0.21693923, -0.46347269, -0.08403621, 0.51505284, -0.0860317, -0.96820361, -0.89216527, -0.90645043, -0.02906557, 0.82151319, 0.74125872, 0.86706933, -0.8619593, -0.72954686, 0.37286524, -0.37978894, 0.70640912, 0.160455, -0.99537876, 0.24985828, -0.86022725, 0.12038504, -0.30743737, 0.20880225, -0.86053997, -0.58652034, -0.09836434, 0.86097492, -0.3465032, -0.88851293, 0.51530642, -0.9467402, 0.55527208, 0.28889341, 0.76723521, 0.1330834, -0.26782408, -0.91670334, 0.29505703, -0.46584891, 0.73243213, 0.9872761, -0.56452691, 0.69869792, -0.03921127, 0.80949254, 0.5178775, -0.42204999, -0.94506364, 0.14794812, -0.42944242, 0.07420884, -0.24556174, 0.30545848, -0.95936839, 0.9850887, -0.03863377, 0.91798345, 0.5025794, 0.05733053, 0.40535191, 0.15817008, -0.25959337, -0.94386359, -0.04140284, -0.77963117, 0.35644775, -0.99568686, 0.07671198, -0.82858986, -0.0563788, -0.5870961]}, {'shape': [8, 8, 2], 'data': [0.31732941, -0.09445001, 0.51368287, -0.94211288, -0.38221727, -0.03966995, 0.26568813, 0.22794522, -0.80243292, -0.12008129, 0.51507666, 0.38174532, 0.84373155, 0.11440871, -0.11473211, -0.79993501, 0.68237308, 0.13911035, 0.54736495, 0.60496742, -0.79614733, -0.92850109, -0.8976427, 0.99907404, -0.70470083, 0.1868947, 0.32129709, 0.6079665, -0.43233557, -0.6535985, -0.82260411, -0.26596421, -0.2890515, 0.52747264, 0.86937158, -0.44593508, -0.30630431, -0.29232529, 0.54717301, -0.78620253, 0.56497549, 0.04218075, 0.25758603, 0.46511485, -0.72157803, 0.17616379, -0.92952566, -0.60129231, -0.67522516, -0.23733133, 0.40261043, 0.84318555, -0.02746633, 0.12799159, 0.66150716, 0.8177334, 0.50287834, 0.5159332, 0.75205807, -0.0162621, 0.79605262, -0.13846732, -0.12987038, 0.4480124, -0.08482921, -0.65083924, -0.59245256, -0.14183413, -0.10124032, -0.97462309, 0.23824755, -0.36425782, 0.51801877, 0.20313135, 0.95819232, -0.29836777, -0.62623841, -0.96011977, -0.27150333, 0.49656037, 0.99106907, -0.63213634, 0.37019201, 0.85219538, 0.67535226, 0.1632053, -0.89960508, 0.6174083, 0.78962112, -0.29384879, -0.19419126, -0.6915843, 0.00360259, 0.38221437, -0.51847547, -0.87617671, 0.90419499, -0.64217193, 0.94943324, -0.2196058, -0.93028959, 0.82932591, -0.68490764, 0.23585349, 0.33549843, -0.89575379, -0.46750698, 0.62855686, -0.22553619, -0.05771774, 0.67680444, 0.64843454, -0.35062741, -0.13813849, 0.92899816, -0.66947569, -0.01434186, 0.45102802, 0.15058188, 0.62446374, -0.93479821, 0.28398312, 0.53153747, 0.83551322, 0.27485061, -0.4725264, -0.41505739, -0.70459538]}], 'weights': [{'shape': [3, 3, 2, 4], 'data': [-0.43578179, -0.24587564, -0.31801076, 0.34753836, -0.56738897, -0.45134161, 0.01824736, 0.08846209, 0.34164075, -0.06075771, -0.52425908, 0.84696319, -0.90994422, 0.07699325, 0.0418348, 0.17139282, 0.02191952, -0.47532115, 0.44261465, 0.15052111, 0.81292648, 0.17966397, -0.14979486, -0.12341542, 0.59198995, 0.94453008, 0.45679537, 0.92659727, -0.40560174, 0.2672119, 0.46568924, 0.6661548, -0.0242446, -0.26664235, 0.07392619, 0.11392891, -0.51168729, -0.42751139, 0.30796888, 0.971408, 0.08567601, -0.72599117, 0.99679563, -0.00594722, 0.99674088, 0.15055416, 0.48117098, -0.00546953, 0.04776603, 0.41445607, 0.25716868, -0.64896142, 0.56204123, 0.02679717, 0.9354033, 0.78243992, -0.21693923, -0.46347269, -0.08403621, 0.51505284, -0.0860317, -0.96820361, -0.89216527, -0.90645043, -0.02906557, 0.82151319, 0.74125872, 0.86706933, -0.8619593, -0.72954686, 0.37286524, -0.37978894]}, {'shape': [4], 'data': [0.31732941, -0.09445001, 0.51368287, -0.94211288]}, {'shape': [3, 3, 2, 4], 'data': [-0.67878727, -0.88048474, 0.31975311, -0.64167497, 0.25906656, -0.23777425, 0.85015497, 0.60302355, -0.47092517, -0.87097275, 0.5919878, 0.08298589, 0.84450546, 0.91241379, -0.23708578, 0.06254957, -0.82464495, -0.4458293, 0.30498047, -0.21653193, -0.68791979, 0.1967965, 0.30273269, 0.88490959, -0.29234621, -0.89366268, -0.48471583, -0.26687009, 0.47322476, -0.39899481, 0.29175976, -0.46534026, -0.98192324, 0.61503957, -0.56152028, 0.73917589, 0.9095103, 0.74553091, 0.65135455, -0.40854003, 0.46461582, -0.78133425, 0.47783681, 0.00807299, -0.91939943, 0.9792523, 0.87236854, -0.74941636, 0.76459477, 0.88023779, -0.46224486, 0.15696763, 0.42865279, -0.52978624, -0.19041743, 0.74025276, -0.07011766, 0.94821892, 0.02875047, 0.3405693, 0.76435326, 0.4885619, 0.9739555, 0.8108435, -0.35441053, 0.74988987, -0.85628251, -0.59856265, 0.48658986, -0.59428463, 0.65063215, 0.11513148]}, {'shape': [4], 'data': [0.08473954, -0.64204749, 0.63724115, 0.98495152]}], 'expected': {'shape': [6, 6, 8], 'data': [0.41576397, 0.0, 0.50781512, 0.0, 0.0, 0.0, 0.0, 1.78502035, 0.0, 0.31778562, 2.21404791, 0.0, 0.0, 0.56585199, 0.0, 0.0, 2.38001609, 0.0, 0.65962255, 0.0, 1.05130017, 2.44152689, 0.39049578, 0.0, 2.11536217, 0.94891357, 3.44389081, 2.05268908, 0.94904006, 1.32967615, 2.70616317, 0.0, 0.0, 1.28951097, 1.11305857, 1.55896235, 1.96458662, 0.84356135, 1.54358315, 3.02610707, 0.10193795, 0.36399847, 3.03350925, 0.0, 0.68279088, 0.0, 0.88318419, 0.81923926, 0.51517361, 0.87203068, 1.17868876, 0.93985504, 0.4775922, 0.0, 1.04130375, 1.50838971, 0.09470218, 0.08477168, 0.97399974, 0.0, 0.99292624, 0.0, 0.0, 2.89495683, 0.0, 0.0, 0.0, 0.0, 1.71154153, 3.06997824, 0.0, 2.89543676, 0.92573255, 0.61075187, 3.25208473, 0.0, 0.34397325, 2.5808866, 0.16551083, 3.7055161, 0.14431462, 0.0, 0.0, 0.0, 1.49842417, 2.54647779, 0.0, 1.03327584, 1.48430717, 0.46283698, 2.09697795, 1.02694464, 2.34203076, 0.0, 0.33271587, 0.95816189, 1.18171251, 0.0, 0.0, 0.0, 0.0, 0.26549989, 1.57197607, 0.62453568, 3.56827617, 1.22883332, 3.76715803, 0.0, 0.0, 0.0, 0.43977165, 0.0, 0.0, 0.43243188, 0.82141042, 1.85758638, 0.0, 0.10486263, 1.46144462, 0.0, 0.7746948, 0.0, 0.49066806, 0.0, 0.0, 0.0, 0.16177738, 0.0, 0.24734139, 0.0, 0.0, 0.0, 0.24122968, 0.0, 0.0, 1.88929963, 0.0, 0.0, 0.0, 0.0, 0.34435734, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0606479, 2.90952897, 1.83917761, 0.0, 2.27481747, 2.96428967, 3.06195974, 2.69710922, 2.24291825, 0.15251806, 0.0, 2.36640239, 4.30436707, 0.0, 0.0, 0.21008873, 0.0, 0.0, 0.27086216, 0.42785203, 2.10548592, 0.0, 0.37072742, 0.0, 0.0, 0.0, 0.0, 1.51211941, 1.97063601, 0.49312013, 1.79330218, 0.03748572, 0.21650547, 0.0, 0.0, 0.0, 1.37311983, 0.24872267, 1.36026597, 0.93163878, 0.0, 0.0, 0.0, 1.40991461, 0.39087284, 0.0, 0.0, 0.0, 0.0, 1.78820384, 0.42765957, 0.41516185, 0.05080074, 0.0, 0.0, 1.06794071, 0.0, 0.21201709, 0.0, 1.48962271, 1.08271921, 2.96551037, 0.0, 1.15348816, 0.0, 0.19367608, 0.0, 0.5837307, 0.0, 1.30145192, 0.0, 0.0, 0.0, 0.0, 0.0, 0.36762607, 1.17703831, 0.0, 0.0, 0.00040215, 0.0, 0.0, 0.0, 1.42695284, 0.0, 0.03259087, 0.0, 0.66699404, 0.0, 0.0, 0.0, 0.0, 1.38679314, 0.2230249, 1.35472751, 3.27696705, 2.01686764, 0.0, 0.26873952, 0.0, 0.0, 0.0, 0.0, 1.16543949, 0.0, 1.96192777, 0.08500355, 2.58480477, 0.70160639, 3.09435892, 2.74670458, 0.69162428, 0.1804741, 3.81414104, 0.0, 2.59334898, 1.5981735, 1.52496147, 2.40232229, 0.0, 0.81154221, 0.12740979, 0.0, 1.24656463, 1.79970694, 0.0, 0.44709331, 0.0, 0.15187567, 0.0, 0.0, 1.55983663, 1.0485785, 0.76264483, 1.04222751, 0.0, 0.0, 1.89849985, 0.35160702, 0.0, 0.0]}}

In [ ]: