In [1]:
import numpy as np
import json
from keras.models import Model
from keras.layers import Input, Permute, 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]

graph 0

test Permute -> Merge concat


In [3]:
data_in_shape = (3, 3, 5)

input_layer_0 = Input(shape=data_in_shape)
branch_0 = Permute((1, 3, 2))(input_layer_0)

input_layer_1 = Input(shape=data_in_shape)
branch_1 = Permute((2, 3, 1))(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(1000 + 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(1000 + 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)}
})


{'weights': [], 'inputs': [{'data': [0.30717917, -0.76998611, 0.90056573, -0.0356172, 0.74494907, -0.57533464, -0.91858075, -0.20561108, -0.53373561, 0.68348145, -0.58583531, 0.48493907, -0.21569174, -0.63548696, 0.48707883, -0.86083584, 0.77067441, 0.9052888, 0.86228687, -0.16913809, -0.94203668, 0.96405497, -0.32072463, 0.41337439, -0.27624586, -0.9297882, 0.71011651, 0.31450702, 0.53136599, 0.10817448, 0.77018587, 0.80839523, -0.9791566, -0.85088653, -0.51074158, -0.7333905, 0.3958502, -0.20359023, 0.76624438, -0.63798498, -0.13500166, -0.96371359, 0.38287572, -0.0606187, -0.74355562], 'shape': [3, 3, 5]}, {'data': [-0.38753564, -0.46987287, -0.60787987, -0.13895705, -0.9537729, -0.60843617, -0.29438942, -0.55351596, 0.22704371, 0.16091422, 0.70713536, -0.91773893, -0.02365113, 0.84165231, -0.78179623, -0.17788676, -0.05974636, -0.7454069, 0.96471, -0.95936807, 0.4109721, 0.93101828, -0.29450922, 0.21178952, -0.56523933, 0.98393909, 0.33835913, 0.38607948, -0.64905815, 0.66089761, -0.50762447, 0.20839139, 0.63702411, -0.1645071, -0.87706191, 0.81450811, 0.46773082, -0.23926805, -0.21161686, 0.75720675, -0.77634106, -0.13142644, 0.13712337, -0.96075827, -0.26970662], 'shape': [3, 3, 5]}], 'expected': {'data': [0.30717918, -0.57533461, -0.58583534, -0.38753563, -0.17788675, -0.50762445, -0.76998609, -0.91858077, 0.48493907, -0.46987286, -0.05974635, 0.20839138, 0.90056574, -0.20561108, -0.21569175, -0.60787988, -0.74540693, 0.6370241, -0.0356172, -0.53373563, -0.63548696, -0.13895705, 0.96471, -0.16450709, 0.74494904, 0.68348145, 0.48707882, -0.9537729, -0.95936805, -0.8770619, -0.86083585, -0.94203669, -0.92978823, -0.60843617, 0.41097209, 0.81450808, 0.77067441, 0.96405494, 0.71011651, -0.29438943, 0.93101829, 0.46773082, 0.90528882, -0.32072464, 0.31450701, -0.55351597, -0.2945092, -0.23926805, 0.86228687, 0.41337439, 0.53136599, 0.22704372, 0.21178952, -0.21161686, -0.16913809, -0.27624586, 0.10817447, 0.16091423, -0.56523931, 0.75720674, 0.77018589, -0.73339051, -0.13500166, 0.70713538, 0.98393911, -0.77634108, 0.80839521, 0.39585021, -0.96371359, -0.91773891, 0.33835912, -0.13142644, -0.97915661, -0.20359023, 0.38287571, -0.02365112, 0.38607949, 0.13712338, -0.85088652, 0.76624441, -0.06061869, 0.84165233, -0.64905816, -0.96075827, -0.51074159, -0.63798499, -0.74355561, -0.78179622, 0.66089761, -0.26970661], 'shape': [3, 5, 6]}}

In [ ]: