import h5py
import numpy as np
np.set_printoptions(threshold=np.nan)

from shutil import copyfile

copyfile("dummy_lutnet.h5", "pretrained_bin.h5") # create pretrained.h5 using datastructure from dummy.h5

bl = h5py.File("baseline_pruned.h5", 'r')
#dummy = h5py.File("dummy.h5", 'r')
pretrained = h5py.File("pretrained_bin.h5", 'r+')

# dense layer 1

bl_w1 = bl["model_weights"]["binary_dense_1"]["binary_dense_1"]["Variable_1:0"]
bl_pruning_mask = bl["model_weights"]["binary_dense_1"]["binary_dense_1"]["pruning_mask:0"]
bl_gamma = bl["model_weights"]["binary_dense_1"]["binary_dense_1"]["Variable:0"]
zero_fill = np.zeros(np.shape(np.array(bl_w1)))
pret_w1 = pretrained["model_weights"]["binary_dense_1"]["binary_dense_1"]["Variable_1:0"]
pret_pruning_mask = pretrained["model_weights"]["binary_dense_1"]["binary_dense_1"]["pruning_mask:0"]
p_gamma = pretrained["model_weights"]["binary_dense_1"]["binary_dense_1"]["Variable:0"]

pret_w1[...] = np.array(bl_w1)
p_gamma[...] = np.array(bl_gamma)
pret_pruning_mask[...] = np.array(bl_pruning_mask)

print(np.sum(np.array(bl_pruning_mask)), np.prod(np.shape(np.array(bl_pruning_mask))))

# dense layer 2

bl_w1 = bl["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_1:0"]
bl_rand_map_0 = bl["model_weights"]["binary_dense_2"]["binary_dense_2"]["rand_map_0:0"]
bl_pruning_mask = bl["model_weights"]["binary_dense_2"]["binary_dense_2"]["pruning_mask:0"]
bl_gamma = bl["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable:0"]
bl_means = bl["model_weights"]["residual_sign_1"]["residual_sign_1"]["means:0"]
pret_rand_map_0 = pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["rand_map_0:0"]
pret_rand_map_1 = pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["rand_map_1:0"]
pret_rand_map_2 = pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["rand_map_2:0"]
pret_pruning_mask = pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["pruning_mask:0"]
p_gamma = pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable:0"]
pret_means = pretrained["model_weights"]["residual_sign_1"]["residual_sign_1"]["means:0"]

pret_c1 =  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_1:0"]
pret_c2 =  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_2:0"]
pret_c3 =  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_3:0"]
pret_c4 =  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_4:0"]
pret_c5 =  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_5:0"]
pret_c6 =  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_6:0"]
pret_c7 =  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_7:0"]
pret_c8 =  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_8:0"]
pret_c9 =  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_9:0"]
pret_c10=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_10:0"]
pret_c11=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_11:0"]
pret_c12=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_12:0"]
pret_c13=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_13:0"]
pret_c14=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_14:0"]
pret_c15=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_15:0"]
pret_c16=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_16:0"]
pret_c17=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_17:0"]
pret_c18=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_18:0"]
pret_c19=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_19:0"]
pret_c20=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_20:0"]
pret_c21=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_21:0"]
pret_c22=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_22:0"]
pret_c23=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_23:0"]
pret_c24=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_24:0"]
pret_c25=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_25:0"]
pret_c26=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_26:0"]
pret_c27=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_27:0"]
pret_c28=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_28:0"]
pret_c29=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_29:0"]
pret_c30=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_30:0"]
pret_c31=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_31:0"]
pret_c32=  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_32:0"]
pret_w1 =  pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["Variable_33:0"]

pret_rand_map_exp_0 = pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["rand_map_exp_0:0"]
pret_rand_map_exp_1 = pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["rand_map_exp_1:0"]
pret_rand_map_exp_2 = pretrained["model_weights"]["binary_dense_2"]["binary_dense_2"]["rand_map_exp_2:0"]

weight_shape = np.shape(bl_w1)
tile_shape = np.shape(pret_c1)
zero_fill = np.zeros(tile_shape)
one_fill = np.ones(tile_shape)
neg_one_fill = -np.ones(tile_shape)

# randomisation and pruning recovery
bl_w1_unroll = np.array(bl_w1)
bl_w1 = np.array(bl_w1)

rand_map_0 = np.arange(tile_shape[0])
np.random.shuffle(rand_map_0)
rand_map_1 = np.arange(tile_shape[0])
np.random.shuffle(rand_map_1)
rand_map_2 = np.arange(tile_shape[0])
np.random.shuffle(rand_map_2)

pruning_mask = np.array(bl_pruning_mask).astype(bool)
init_mask = np.logical_not(pruning_mask[rand_map_0])
pruning_mask_recover = np.logical_and(pruning_mask, init_mask)[np.argsort(rand_map_0)]
pruning_mask = np.logical_or(pruning_mask, pruning_mask_recover)
init_mask = np.reshape(init_mask, tile_shape)

# expand randomisation map across tiles

rand_map_0_expand = np.tile(rand_map_0,[weight_shape[0]/tile_shape[0]])
rand_map_1_expand = np.tile(rand_map_1,[weight_shape[0]/tile_shape[0]])
rand_map_2_expand = np.tile(rand_map_2,[weight_shape[0]/tile_shape[0]])
for i in range(weight_shape[0]):
        rand_map_0_expand[i] = rand_map_0_expand[i] + (tile_shape[0]*(weight_shape[0]/tile_shape[0]-1)) * (rand_map_0_expand[i]/tile_shape[0]) + tile_shape[0]*(i%weight_shape[0]/tile_shape[0])
        rand_map_1_expand[i] = rand_map_1_expand[i] + (tile_shape[0]*(weight_shape[0]/tile_shape[0]-1)) * (rand_map_1_expand[i]/tile_shape[0]) + tile_shape[0]*(i%weight_shape[0]/tile_shape[0])
        rand_map_2_expand[i] = rand_map_2_expand[i] + (tile_shape[0]*(weight_shape[0]/tile_shape[0]-1)) * (rand_map_2_expand[i]/tile_shape[0]) + tile_shape[0]*(i%weight_shape[0]/tile_shape[0])

bl_w1_rand_0 = bl_w1_unroll[rand_map_0_expand]
bl_w1_rand_0 = np.reshape(bl_w1_rand_0, weight_shape)

w1 = bl_w1

# connect1 only
c1  = one_fill
c2  = neg_one_fill
c3  = one_fill
c4  = neg_one_fill
c5  = one_fill
c6  = neg_one_fill
c7  = one_fill
c8  = neg_one_fill
c9  = one_fill
c10 = neg_one_fill
c11 = one_fill
c12 = neg_one_fill
c13 = one_fill
c14 = neg_one_fill
c15 = one_fill
c16 = neg_one_fill
c17 = neg_one_fill
c18 = one_fill
c19 = neg_one_fill
c20 = one_fill
c21 = neg_one_fill
c22 = one_fill
c23 = neg_one_fill
c24 = one_fill
c25 = neg_one_fill
c26 = one_fill
c27 = neg_one_fill
c28 = one_fill
c29 = neg_one_fill
c30 = one_fill
c31 = neg_one_fill
c32 = one_fill

pret_w1 [...] = w1
pret_c1 [...] = c1
pret_c2 [...] = c2
pret_c3 [...] = c3
pret_c4 [...] = c4
pret_c5 [...] = c5
pret_c6 [...] = c6
pret_c7 [...] = c7
pret_c8 [...] = c8
pret_c9 [...] = c9
pret_c10[...] = c10
pret_c11[...] = c11
pret_c12[...] = c12
pret_c13[...] = c13
pret_c14[...] = c14
pret_c15[...] = c15
pret_c16[...] = c16
pret_c17[...] = c17
pret_c18[...] = c18
pret_c19[...] = c19
pret_c20[...] = c20
pret_c21[...] = c21
pret_c22[...] = c22
pret_c23[...] = c23
pret_c24[...] = c24
pret_c25[...] = c25
pret_c26[...] = c26
pret_c27[...] = c27
pret_c28[...] = c28
pret_c29[...] = c29
pret_c30[...] = c30
pret_c31[...] = c31
pret_c32[...] = c32

pret_rand_map_0[...] = np.reshape(rand_map_0, (-1,1)).astype(float)
pret_rand_map_1[...] = np.reshape(rand_map_1, (-1,1)).astype(float)
pret_rand_map_2[...] = np.reshape(rand_map_2, (-1,1)).astype(float)
p_gamma[...] = np.array(bl_gamma)
pret_means[...] = np.array(bl_means)
pret_pruning_mask[...] = np.array(bl_pruning_mask)

rand_map_0_expand = np.reshape(rand_map_0_expand, [-1,1]).astype(float)
pret_rand_map_exp_0[...] = rand_map_0_expand
rand_map_1_expand = np.reshape(rand_map_1_expand, [-1,1]).astype(float)
pret_rand_map_exp_1[...] = rand_map_1_expand
rand_map_2_expand = np.reshape(rand_map_2_expand, [-1,1]).astype(float)
pret_rand_map_exp_2[...] = rand_map_2_expand

print(np.sum(np.array(bl_pruning_mask)), np.prod(np.shape(np.array(bl_pruning_mask))))

# dense layer 3

bl_w1 = bl["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_1:0"]
bl_rand_map_0 = bl["model_weights"]["binary_dense_3"]["binary_dense_3"]["rand_map_0:0"]
bl_pruning_mask = bl["model_weights"]["binary_dense_3"]["binary_dense_3"]["pruning_mask:0"]
bl_gamma = bl["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable:0"]
bl_means = bl["model_weights"]["residual_sign_2"]["residual_sign_2"]["means:0"]
pret_rand_map_0 = pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["rand_map_0:0"]
pret_rand_map_1 = pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["rand_map_1:0"]
pret_rand_map_2 = pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["rand_map_2:0"]
pret_pruning_mask = pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["pruning_mask:0"]
p_gamma = pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable:0"]
pret_means = pretrained["model_weights"]["residual_sign_2"]["residual_sign_2"]["means:0"]

pret_c1 =  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_1:0"]
pret_c2 =  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_2:0"]
pret_c3 =  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_3:0"]
pret_c4 =  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_4:0"]
pret_c5 =  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_5:0"]
pret_c6 =  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_6:0"]
pret_c7 =  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_7:0"]
pret_c8 =  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_8:0"]
pret_c9 =  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_9:0"]
pret_c10=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_10:0"]
pret_c11=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_11:0"]
pret_c12=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_12:0"]
pret_c13=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_13:0"]
pret_c14=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_14:0"]
pret_c15=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_15:0"]
pret_c16=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_16:0"]
pret_c17=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_17:0"]
pret_c18=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_18:0"]
pret_c19=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_19:0"]
pret_c20=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_20:0"]
pret_c21=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_21:0"]
pret_c22=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_22:0"]
pret_c23=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_23:0"]
pret_c24=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_24:0"]
pret_c25=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_25:0"]
pret_c26=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_26:0"]
pret_c27=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_27:0"]
pret_c28=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_28:0"]
pret_c29=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_29:0"]
pret_c30=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_30:0"]
pret_c31=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_31:0"]
pret_c32=  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_32:0"]
pret_w1 =  pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["Variable_33:0"]

pret_rand_map_exp_0 = pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["rand_map_exp_0:0"]
pret_rand_map_exp_1 = pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["rand_map_exp_1:0"]
pret_rand_map_exp_2 = pretrained["model_weights"]["binary_dense_3"]["binary_dense_3"]["rand_map_exp_2:0"]

weight_shape = np.shape(bl_w1)
tile_shape = np.shape(pret_c1)
zero_fill = np.zeros(tile_shape)
one_fill = np.ones(tile_shape)
neg_one_fill = -np.ones(tile_shape)

# randomisation and pruning recovery
bl_w1_unroll = np.array(bl_w1)
bl_w1 = np.array(bl_w1)

rand_map_0 = np.arange(tile_shape[0])
np.random.shuffle(rand_map_0)
rand_map_1 = np.arange(tile_shape[0])
np.random.shuffle(rand_map_1)
rand_map_2 = np.arange(tile_shape[0])
np.random.shuffle(rand_map_2)

pruning_mask = np.array(bl_pruning_mask).astype(bool)
init_mask = np.logical_not(pruning_mask[rand_map_0])
pruning_mask_recover = np.logical_and(pruning_mask, init_mask)[np.argsort(rand_map_0)]
pruning_mask = np.logical_or(pruning_mask, pruning_mask_recover)
init_mask = np.reshape(init_mask, tile_shape)

# expand randomisation map across tiles

rand_map_0_expand = np.tile(rand_map_0,[weight_shape[0]/tile_shape[0]])
rand_map_1_expand = np.tile(rand_map_1,[weight_shape[0]/tile_shape[0]])
rand_map_2_expand = np.tile(rand_map_2,[weight_shape[0]/tile_shape[0]])
for i in range(weight_shape[0]):
        rand_map_0_expand[i] = rand_map_0_expand[i] + (tile_shape[0]*(weight_shape[0]/tile_shape[0]-1)) * (rand_map_0_expand[i]/tile_shape[0]) + tile_shape[0]*(i%weight_shape[0]/tile_shape[0])
        rand_map_1_expand[i] = rand_map_1_expand[i] + (tile_shape[0]*(weight_shape[0]/tile_shape[0]-1)) * (rand_map_1_expand[i]/tile_shape[0]) + tile_shape[0]*(i%weight_shape[0]/tile_shape[0])
        rand_map_2_expand[i] = rand_map_2_expand[i] + (tile_shape[0]*(weight_shape[0]/tile_shape[0]-1)) * (rand_map_2_expand[i]/tile_shape[0]) + tile_shape[0]*(i%weight_shape[0]/tile_shape[0])

bl_w1_rand_0 = bl_w1_unroll[rand_map_0_expand]
bl_w1_rand_0 = np.reshape(bl_w1_rand_0, weight_shape)

w1 = bl_w1

# connect1 only
c1  = one_fill
c2  = neg_one_fill
c3  = one_fill
c4  = neg_one_fill
c5  = one_fill
c6  = neg_one_fill
c7  = one_fill
c8  = neg_one_fill
c9  = one_fill
c10 = neg_one_fill
c11 = one_fill
c12 = neg_one_fill
c13 = one_fill
c14 = neg_one_fill
c15 = one_fill
c16 = neg_one_fill
c17 = neg_one_fill
c18 = one_fill
c19 = neg_one_fill
c20 = one_fill
c21 = neg_one_fill
c22 = one_fill
c23 = neg_one_fill
c24 = one_fill
c25 = neg_one_fill
c26 = one_fill
c27 = neg_one_fill
c28 = one_fill
c29 = neg_one_fill
c30 = one_fill
c31 = neg_one_fill
c32 = one_fill

pret_w1 [...] = w1
pret_c1 [...] = c1
pret_c2 [...] = c2
pret_c3 [...] = c3
pret_c4 [...] = c4
pret_c5 [...] = c5
pret_c6 [...] = c6
pret_c7 [...] = c7
pret_c8 [...] = c8
pret_c9 [...] = c9
pret_c10[...] = c10
pret_c11[...] = c11
pret_c12[...] = c12
pret_c13[...] = c13
pret_c14[...] = c14
pret_c15[...] = c15
pret_c16[...] = c16
pret_c17[...] = c17
pret_c18[...] = c18
pret_c19[...] = c19
pret_c20[...] = c20
pret_c21[...] = c21
pret_c22[...] = c22
pret_c23[...] = c23
pret_c24[...] = c24
pret_c25[...] = c25
pret_c26[...] = c26
pret_c27[...] = c27
pret_c28[...] = c28
pret_c29[...] = c29
pret_c30[...] = c30
pret_c31[...] = c31
pret_c32[...] = c32

pret_rand_map_0[...] = np.reshape(rand_map_0, (-1,1)).astype(float)
pret_rand_map_1[...] = np.reshape(rand_map_1, (-1,1)).astype(float)
pret_rand_map_2[...] = np.reshape(rand_map_2, (-1,1)).astype(float)
p_gamma[...] = np.array(bl_gamma)
pret_means[...] = np.array(bl_means)
pret_pruning_mask[...] = np.array(bl_pruning_mask)

rand_map_0_expand = np.reshape(rand_map_0_expand, [-1,1]).astype(float)
pret_rand_map_exp_0[...] = rand_map_0_expand
rand_map_1_expand = np.reshape(rand_map_1_expand, [-1,1]).astype(float)
pret_rand_map_exp_1[...] = rand_map_1_expand
rand_map_2_expand = np.reshape(rand_map_2_expand, [-1,1]).astype(float)
pret_rand_map_exp_2[...] = rand_map_2_expand

print(np.sum(np.array(bl_pruning_mask)), np.prod(np.shape(np.array(bl_pruning_mask))))

# dense layer 4

bl_w1 = bl["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_1:0"]
bl_rand_map_0 = bl["model_weights"]["binary_dense_4"]["binary_dense_4"]["rand_map_0:0"]
bl_pruning_mask = bl["model_weights"]["binary_dense_4"]["binary_dense_4"]["pruning_mask:0"]
bl_gamma = bl["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable:0"]
bl_means = bl["model_weights"]["residual_sign_3"]["residual_sign_3"]["means:0"]
pret_rand_map_0 = pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["rand_map_0:0"]
pret_rand_map_1 = pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["rand_map_1:0"]
pret_rand_map_2 = pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["rand_map_2:0"]
pret_pruning_mask = pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["pruning_mask:0"]
p_gamma = pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable:0"]
pret_means = pretrained["model_weights"]["residual_sign_3"]["residual_sign_3"]["means:0"]

pret_c1 =  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_1:0"]
pret_c2 =  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_2:0"]
pret_c3 =  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_3:0"]
pret_c4 =  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_4:0"]
pret_c5 =  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_5:0"]
pret_c6 =  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_6:0"]
pret_c7 =  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_7:0"]
pret_c8 =  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_8:0"]
pret_c9 =  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_9:0"]
pret_c10=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_10:0"]
pret_c11=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_11:0"]
pret_c12=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_12:0"]
pret_c13=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_13:0"]
pret_c14=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_14:0"]
pret_c15=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_15:0"]
pret_c16=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_16:0"]
pret_c17=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_17:0"]
pret_c18=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_18:0"]
pret_c19=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_19:0"]
pret_c20=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_20:0"]
pret_c21=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_21:0"]
pret_c22=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_22:0"]
pret_c23=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_23:0"]
pret_c24=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_24:0"]
pret_c25=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_25:0"]
pret_c26=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_26:0"]
pret_c27=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_27:0"]
pret_c28=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_28:0"]
pret_c29=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_29:0"]
pret_c30=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_30:0"]
pret_c31=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_31:0"]
pret_c32=  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_32:0"]
pret_w1 =  pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["Variable_33:0"]

pret_rand_map_exp_0 = pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["rand_map_exp_0:0"]
pret_rand_map_exp_1 = pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["rand_map_exp_1:0"]
pret_rand_map_exp_2 = pretrained["model_weights"]["binary_dense_4"]["binary_dense_4"]["rand_map_exp_2:0"]

weight_shape = np.shape(bl_w1)
tile_shape = np.shape(pret_c1)
zero_fill = np.zeros(tile_shape)
one_fill = np.ones(tile_shape)
neg_one_fill = -np.ones(tile_shape)

# randomisation and pruning recovery
bl_w1_unroll = np.array(bl_w1)
bl_w1 = np.array(bl_w1)

rand_map_0 = np.arange(tile_shape[0])
np.random.shuffle(rand_map_0)
rand_map_1 = np.arange(tile_shape[0])
np.random.shuffle(rand_map_1)
rand_map_2 = np.arange(tile_shape[0])
np.random.shuffle(rand_map_2)

pruning_mask = np.array(bl_pruning_mask).astype(bool)
init_mask = np.logical_not(pruning_mask[rand_map_0])
pruning_mask_recover = np.logical_and(pruning_mask, init_mask)[np.argsort(rand_map_0)]
pruning_mask = np.logical_or(pruning_mask, pruning_mask_recover)
init_mask = np.reshape(init_mask, tile_shape)

# expand randomisation map across tiles

rand_map_0_expand = np.tile(rand_map_0,[weight_shape[0]/tile_shape[0]])
rand_map_1_expand = np.tile(rand_map_1,[weight_shape[0]/tile_shape[0]])
rand_map_2_expand = np.tile(rand_map_2,[weight_shape[0]/tile_shape[0]])
for i in range(weight_shape[0]):
        rand_map_0_expand[i] = rand_map_0_expand[i] + (tile_shape[0]*(weight_shape[0]/tile_shape[0]-1)) * (rand_map_0_expand[i]/tile_shape[0]) + tile_shape[0]*(i%weight_shape[0]/tile_shape[0])
        rand_map_1_expand[i] = rand_map_1_expand[i] + (tile_shape[0]*(weight_shape[0]/tile_shape[0]-1)) * (rand_map_1_expand[i]/tile_shape[0]) + tile_shape[0]*(i%weight_shape[0]/tile_shape[0])
        rand_map_2_expand[i] = rand_map_2_expand[i] + (tile_shape[0]*(weight_shape[0]/tile_shape[0]-1)) * (rand_map_2_expand[i]/tile_shape[0]) + tile_shape[0]*(i%weight_shape[0]/tile_shape[0])

bl_w1_rand_0 = bl_w1_unroll[rand_map_0_expand]
bl_w1_rand_0 = np.reshape(bl_w1_rand_0, weight_shape)

w1 = bl_w1

# connect1 only
c1  = one_fill
c2  = neg_one_fill
c3  = one_fill
c4  = neg_one_fill
c5  = one_fill
c6  = neg_one_fill
c7  = one_fill
c8  = neg_one_fill
c9  = one_fill
c10 = neg_one_fill
c11 = one_fill
c12 = neg_one_fill
c13 = one_fill
c14 = neg_one_fill
c15 = one_fill
c16 = neg_one_fill
c17 = neg_one_fill
c18 = one_fill
c19 = neg_one_fill
c20 = one_fill
c21 = neg_one_fill
c22 = one_fill
c23 = neg_one_fill
c24 = one_fill
c25 = neg_one_fill
c26 = one_fill
c27 = neg_one_fill
c28 = one_fill
c29 = neg_one_fill
c30 = one_fill
c31 = neg_one_fill
c32 = one_fill

pret_w1 [...] = w1
pret_c1 [...] = c1
pret_c2 [...] = c2
pret_c3 [...] = c3
pret_c4 [...] = c4
pret_c5 [...] = c5
pret_c6 [...] = c6
pret_c7 [...] = c7
pret_c8 [...] = c8
pret_c9 [...] = c9
pret_c10[...] = c10
pret_c11[...] = c11
pret_c12[...] = c12
pret_c13[...] = c13
pret_c14[...] = c14
pret_c15[...] = c15
pret_c16[...] = c16
pret_c17[...] = c17
pret_c18[...] = c18
pret_c19[...] = c19
pret_c20[...] = c20
pret_c21[...] = c21
pret_c22[...] = c22
pret_c23[...] = c23
pret_c24[...] = c24
pret_c25[...] = c25
pret_c26[...] = c26
pret_c27[...] = c27
pret_c28[...] = c28
pret_c29[...] = c29
pret_c30[...] = c30
pret_c31[...] = c31
pret_c32[...] = c32

pret_rand_map_0[...] = np.reshape(rand_map_0, (-1,1)).astype(float)
pret_rand_map_1[...] = np.reshape(rand_map_1, (-1,1)).astype(float)
pret_rand_map_2[...] = np.reshape(rand_map_2, (-1,1)).astype(float)
p_gamma[...] = np.array(bl_gamma)
pret_means[...] = np.array(bl_means)
pret_pruning_mask[...] = np.array(bl_pruning_mask)

rand_map_0_expand = np.reshape(rand_map_0_expand, [-1,1]).astype(float)
pret_rand_map_exp_0[...] = rand_map_0_expand
rand_map_1_expand = np.reshape(rand_map_1_expand, [-1,1]).astype(float)
pret_rand_map_exp_1[...] = rand_map_1_expand
rand_map_2_expand = np.reshape(rand_map_2_expand, [-1,1]).astype(float)
pret_rand_map_exp_2[...] = rand_map_2_expand

print(np.sum(np.array(bl_pruning_mask)), np.prod(np.shape(np.array(bl_pruning_mask))))

# dense layer 5

bl_w1 = bl["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_1:0"]
bl_rand_map_0 = bl["model_weights"]["binary_dense_5"]["binary_dense_5"]["rand_map_0:0"]
bl_pruning_mask = bl["model_weights"]["binary_dense_5"]["binary_dense_5"]["pruning_mask:0"]
bl_gamma = bl["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable:0"]
bl_means = bl["model_weights"]["residual_sign_4"]["residual_sign_4"]["means:0"]
pret_rand_map_0 = pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["rand_map_0:0"]
pret_rand_map_1 = pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["rand_map_1:0"]
pret_rand_map_2 = pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["rand_map_2:0"]
pret_pruning_mask = pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["pruning_mask:0"]
p_gamma = pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable:0"]
pret_means = pretrained["model_weights"]["residual_sign_4"]["residual_sign_4"]["means:0"]

pret_c1 =  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_1:0"]
pret_c2 =  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_2:0"]
pret_c3 =  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_3:0"]
pret_c4 =  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_4:0"]
pret_c5 =  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_5:0"]
pret_c6 =  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_6:0"]
pret_c7 =  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_7:0"]
pret_c8 =  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_8:0"]
pret_c9 =  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_9:0"]
pret_c10=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_10:0"]
pret_c11=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_11:0"]
pret_c12=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_12:0"]
pret_c13=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_13:0"]
pret_c14=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_14:0"]
pret_c15=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_15:0"]
pret_c16=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_16:0"]
pret_c17=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_17:0"]
pret_c18=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_18:0"]
pret_c19=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_19:0"]
pret_c20=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_20:0"]
pret_c21=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_21:0"]
pret_c22=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_22:0"]
pret_c23=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_23:0"]
pret_c24=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_24:0"]
pret_c25=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_25:0"]
pret_c26=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_26:0"]
pret_c27=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_27:0"]
pret_c28=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_28:0"]
pret_c29=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_29:0"]
pret_c30=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_30:0"]
pret_c31=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_31:0"]
pret_c32=  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_32:0"]
pret_w1 =  pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["Variable_33:0"]

pret_rand_map_exp_0 = pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["rand_map_exp_0:0"]
pret_rand_map_exp_1 = pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["rand_map_exp_1:0"]
pret_rand_map_exp_2 = pretrained["model_weights"]["binary_dense_5"]["binary_dense_5"]["rand_map_exp_2:0"]

weight_shape = np.shape(bl_w1)
tile_shape = np.shape(pret_c1)
zero_fill = np.zeros(tile_shape)
one_fill = np.ones(tile_shape)
neg_one_fill = -np.ones(tile_shape)

# randomisation and pruning recovery
bl_w1_unroll = np.array(bl_w1)
bl_w1 = np.array(bl_w1)

rand_map_0 = np.arange(tile_shape[0])
np.random.shuffle(rand_map_0)
rand_map_1 = np.arange(tile_shape[0])
np.random.shuffle(rand_map_1)
rand_map_2 = np.arange(tile_shape[0])
np.random.shuffle(rand_map_2)

pruning_mask = np.array(bl_pruning_mask).astype(bool)
init_mask = np.logical_not(pruning_mask[rand_map_0])
pruning_mask_recover = np.logical_and(pruning_mask, init_mask)[np.argsort(rand_map_0)]
pruning_mask = np.logical_or(pruning_mask, pruning_mask_recover)
init_mask = np.reshape(init_mask, tile_shape)

# expand randomisation map across tiles

rand_map_0_expand = np.tile(rand_map_0,[weight_shape[0]/tile_shape[0]])
rand_map_1_expand = np.tile(rand_map_1,[weight_shape[0]/tile_shape[0]])
rand_map_2_expand = np.tile(rand_map_2,[weight_shape[0]/tile_shape[0]])
for i in range(weight_shape[0]):
        rand_map_0_expand[i] = rand_map_0_expand[i] + (tile_shape[0]*(weight_shape[0]/tile_shape[0]-1)) * (rand_map_0_expand[i]/tile_shape[0]) + tile_shape[0]*(i%weight_shape[0]/tile_shape[0])
        rand_map_1_expand[i] = rand_map_1_expand[i] + (tile_shape[0]*(weight_shape[0]/tile_shape[0]-1)) * (rand_map_1_expand[i]/tile_shape[0]) + tile_shape[0]*(i%weight_shape[0]/tile_shape[0])
        rand_map_2_expand[i] = rand_map_2_expand[i] + (tile_shape[0]*(weight_shape[0]/tile_shape[0]-1)) * (rand_map_2_expand[i]/tile_shape[0]) + tile_shape[0]*(i%weight_shape[0]/tile_shape[0])

bl_w1_rand_0 = bl_w1_unroll[rand_map_0_expand]
bl_w1_rand_0 = np.reshape(bl_w1_rand_0, weight_shape)

w1 = bl_w1

# connect1 only
c1  = one_fill
c2  = neg_one_fill
c3  = one_fill
c4  = neg_one_fill
c5  = one_fill
c6  = neg_one_fill
c7  = one_fill
c8  = neg_one_fill
c9  = one_fill
c10 = neg_one_fill
c11 = one_fill
c12 = neg_one_fill
c13 = one_fill
c14 = neg_one_fill
c15 = one_fill
c16 = neg_one_fill
c17 = neg_one_fill
c18 = one_fill
c19 = neg_one_fill
c20 = one_fill
c21 = neg_one_fill
c22 = one_fill
c23 = neg_one_fill
c24 = one_fill
c25 = neg_one_fill
c26 = one_fill
c27 = neg_one_fill
c28 = one_fill
c29 = neg_one_fill
c30 = one_fill
c31 = neg_one_fill
c32 = one_fill

pret_w1 [...] = w1
pret_c1 [...] = c1
pret_c2 [...] = c2
pret_c3 [...] = c3
pret_c4 [...] = c4
pret_c5 [...] = c5
pret_c6 [...] = c6
pret_c7 [...] = c7
pret_c8 [...] = c8
pret_c9 [...] = c9
pret_c10[...] = c10
pret_c11[...] = c11
pret_c12[...] = c12
pret_c13[...] = c13
pret_c14[...] = c14
pret_c15[...] = c15
pret_c16[...] = c16
pret_c17[...] = c17
pret_c18[...] = c18
pret_c19[...] = c19
pret_c20[...] = c20
pret_c21[...] = c21
pret_c22[...] = c22
pret_c23[...] = c23
pret_c24[...] = c24
pret_c25[...] = c25
pret_c26[...] = c26
pret_c27[...] = c27
pret_c28[...] = c28
pret_c29[...] = c29
pret_c30[...] = c30
pret_c31[...] = c31
pret_c32[...] = c32

pret_rand_map_0[...] = np.reshape(rand_map_0, (-1,1)).astype(float)
pret_rand_map_1[...] = np.reshape(rand_map_1, (-1,1)).astype(float)
pret_rand_map_2[...] = np.reshape(rand_map_2, (-1,1)).astype(float)
p_gamma[...] = np.array(bl_gamma)
pret_means[...] = np.array(bl_means)
pret_pruning_mask[...] = np.array(bl_pruning_mask)

rand_map_0_expand = np.reshape(rand_map_0_expand, [-1,1]).astype(float)
pret_rand_map_exp_0[...] = rand_map_0_expand
rand_map_1_expand = np.reshape(rand_map_1_expand, [-1,1]).astype(float)
pret_rand_map_exp_1[...] = rand_map_1_expand
rand_map_2_expand = np.reshape(rand_map_2_expand, [-1,1]).astype(float)
pret_rand_map_exp_2[...] = rand_map_2_expand

print(np.sum(np.array(bl_pruning_mask)), np.prod(np.shape(np.array(bl_pruning_mask))))


# bn 1

bl_beta = bl["model_weights"]["batch_normalization_1"]["batch_normalization_1"]["beta:0"]
bl_gamma = bl["model_weights"]["batch_normalization_1"]["batch_normalization_1"]["gamma:0"]
bl_moving_mean = bl["model_weights"]["batch_normalization_1"]["batch_normalization_1"]["moving_mean:0"]
bl_moving_variance = bl["model_weights"]["batch_normalization_1"]["batch_normalization_1"]["moving_variance:0"]
p_beta = pretrained["model_weights"]["batch_normalization_1"]["batch_normalization_1"]["beta:0"]
p_gamma = pretrained["model_weights"]["batch_normalization_1"]["batch_normalization_1"]["gamma:0"]
p_moving_mean = pretrained["model_weights"]["batch_normalization_1"]["batch_normalization_1"]["moving_mean:0"]
p_moving_variance = pretrained["model_weights"]["batch_normalization_1"]["batch_normalization_1"]["moving_variance:0"]

p_beta[...] = np.array(bl_beta)
p_gamma[...] = np.array(bl_gamma)
p_moving_mean[...] = np.array(bl_moving_mean)
p_moving_variance[...] = np.array(bl_moving_variance)

# bn 2

bl_beta = bl["model_weights"]["batch_normalization_2"]["batch_normalization_2"]["beta:0"]
bl_gamma = bl["model_weights"]["batch_normalization_2"]["batch_normalization_2"]["gamma:0"]
bl_moving_mean = bl["model_weights"]["batch_normalization_2"]["batch_normalization_2"]["moving_mean:0"]
bl_moving_variance = bl["model_weights"]["batch_normalization_2"]["batch_normalization_2"]["moving_variance:0"]
p_beta = pretrained["model_weights"]["batch_normalization_2"]["batch_normalization_2"]["beta:0"]
p_gamma = pretrained["model_weights"]["batch_normalization_2"]["batch_normalization_2"]["gamma:0"]
p_moving_mean = pretrained["model_weights"]["batch_normalization_2"]["batch_normalization_2"]["moving_mean:0"]
p_moving_variance = pretrained["model_weights"]["batch_normalization_2"]["batch_normalization_2"]["moving_variance:0"]

p_beta[...] = np.array(bl_beta)
p_gamma[...] = np.array(bl_gamma)
p_moving_mean[...] = np.array(bl_moving_mean)
p_moving_variance[...] = np.array(bl_moving_variance)

# bn 3

bl_beta = bl["model_weights"]["batch_normalization_3"]["batch_normalization_3"]["beta:0"]
bl_gamma = bl["model_weights"]["batch_normalization_3"]["batch_normalization_3"]["gamma:0"]
bl_moving_mean = bl["model_weights"]["batch_normalization_3"]["batch_normalization_3"]["moving_mean:0"]
bl_moving_variance = bl["model_weights"]["batch_normalization_3"]["batch_normalization_3"]["moving_variance:0"]
p_beta = pretrained["model_weights"]["batch_normalization_3"]["batch_normalization_3"]["beta:0"]
p_gamma = pretrained["model_weights"]["batch_normalization_3"]["batch_normalization_3"]["gamma:0"]
p_moving_mean = pretrained["model_weights"]["batch_normalization_3"]["batch_normalization_3"]["moving_mean:0"]
p_moving_variance = pretrained["model_weights"]["batch_normalization_3"]["batch_normalization_3"]["moving_variance:0"]

p_beta[...] = np.array(bl_beta)
p_gamma[...] = np.array(bl_gamma)
p_moving_mean[...] = np.array(bl_moving_mean)
p_moving_variance[...] = np.array(bl_moving_variance)

# bn 4

bl_beta = bl["model_weights"]["batch_normalization_4"]["batch_normalization_4"]["beta:0"]
bl_gamma = bl["model_weights"]["batch_normalization_4"]["batch_normalization_4"]["gamma:0"]
bl_moving_mean = bl["model_weights"]["batch_normalization_4"]["batch_normalization_4"]["moving_mean:0"]
bl_moving_variance = bl["model_weights"]["batch_normalization_4"]["batch_normalization_4"]["moving_variance:0"]
p_beta = pretrained["model_weights"]["batch_normalization_4"]["batch_normalization_4"]["beta:0"]
p_gamma = pretrained["model_weights"]["batch_normalization_4"]["batch_normalization_4"]["gamma:0"]
p_moving_mean = pretrained["model_weights"]["batch_normalization_4"]["batch_normalization_4"]["moving_mean:0"]
p_moving_variance = pretrained["model_weights"]["batch_normalization_4"]["batch_normalization_4"]["moving_variance:0"]

p_beta[...] = np.array(bl_beta)
p_gamma[...] = np.array(bl_gamma)
p_moving_mean[...] = np.array(bl_moving_mean)
p_moving_variance[...] = np.array(bl_moving_variance)

# bn 5

bl_beta = bl["model_weights"]["batch_normalization_5"]["batch_normalization_5"]["beta:0"]
bl_gamma = bl["model_weights"]["batch_normalization_5"]["batch_normalization_5"]["gamma:0"]
bl_moving_mean = bl["model_weights"]["batch_normalization_5"]["batch_normalization_5"]["moving_mean:0"]
bl_moving_variance = bl["model_weights"]["batch_normalization_5"]["batch_normalization_5"]["moving_variance:0"]
p_beta = pretrained["model_weights"]["batch_normalization_5"]["batch_normalization_5"]["beta:0"]
p_gamma = pretrained["model_weights"]["batch_normalization_5"]["batch_normalization_5"]["gamma:0"]
p_moving_mean = pretrained["model_weights"]["batch_normalization_5"]["batch_normalization_5"]["moving_mean:0"]
p_moving_variance = pretrained["model_weights"]["batch_normalization_5"]["batch_normalization_5"]["moving_variance:0"]

p_beta[...] = np.array(bl_beta)
p_gamma[...] = np.array(bl_gamma)
p_moving_mean[...] = np.array(bl_moving_mean)
p_moving_variance[...] = np.array(bl_moving_variance)

pretrained.close()

[((3, 0, 3, 37), 'numpy.set_printoptions', 'np.set_printoptions', (), '', True, 'import numpy as np\n'), ((7, 0, 7, 48), 'shutil.copyfile', 'copyfile', ({(7, 9, 7, 26): '"""dummy_lutnet.h5"""', (7, 28, 7, 47): '"""pretrained_bin.h5"""'}, {}), "('dummy_lutnet.h5', 'pretrained_bin.h5')", False, 'from shutil import copyfile\n'), ((9, 5, 9, 41), 'h5py.File', 'h5py.File', ({(9, 15, 9, 35): '"""baseline_pruned.h5"""', (9, 37, 9, 40): '"""r"""'}, {}), "('baseline_pruned.h5', 'r')", False, 'import h5py\n'), ((11, 13, 11, 49), 'h5py.File', 'h5py.File', ({(11, 23, 11, 42): '"""pretrained_bin.h5"""', (11, 44, 11, 48): '"""r+"""'}, {}), "('pretrained_bin.h5', 'r+')", False, 'import h5py\n'), ((23, 15, 23, 30), 'numpy.array', 'np.array', ({(23, 24, 23, 29): 'bl_w1'}, {}), '(bl_w1)', True, 'import numpy as np\n'), ((24, 15, 24, 33), 'numpy.array', 'np.array', ({(24, 24, 24, 32): 'bl_gamma'}, {}), '(bl_gamma)', True, 'import numpy as np\n'), ((25, 25, 25, 50), 'numpy.array', 'np.array', ({(25, 34, 25, 49): 'bl_pruning_mask'}, {}), '(bl_pruning_mask)', True, 'import numpy as np\n'), ((81, 15, 81, 30), 'numpy.shape', 'np.shape', ({(81, 24, 81, 29): 'bl_w1'}, {}), '(bl_w1)', True, 'import numpy as np\n'), ((82, 13, 82, 30), 'numpy.shape', 'np.shape', ({(82, 22, 82, 29): 'pret_c1'}, {}), '(pret_c1)', True, 'import numpy as np\n'), ((83, 12, 83, 32), 'numpy.zeros', 'np.zeros', ({(83, 21, 83, 31): 'tile_shape'}, {}), '(tile_shape)', True, 'import numpy as np\n'), ((84, 11, 84, 30), 'numpy.ones', 'np.ones', ({(84, 19, 84, 29): 'tile_shape'}, {}), '(tile_shape)', True, 'import numpy as np\n'), ((88, 15, 88, 30), 'numpy.array', 'np.array', ({(88, 24, 88, 29): 'bl_w1'}, {}), '(bl_w1)', True, 'import numpy as np\n'), ((89, 8, 89, 23), 'numpy.array', 'np.array', ({(89, 17, 89, 22): 'bl_w1'}, {}), '(bl_w1)', True, 'import numpy as np\n'), ((91, 13, 91, 37), 'numpy.arange', 'np.arange', ({(91, 23, 91, 36): 'tile_shape[0]'}, {}), '(tile_shape[0])', True, 'import numpy as np\n'), ((92, 0, 92, 29), 'numpy.random.shuffle', 'np.random.shuffle', ({(92, 18, 92, 28): 'rand_map_0'}, {}), '(rand_map_0)', True, 'import numpy as np\n'), ((93, 13, 93, 37), 'numpy.arange', 'np.arange', ({(93, 23, 93, 36): 'tile_shape[0]'}, {}), '(tile_shape[0])', True, 'import numpy as np\n'), ((94, 0, 94, 29), 'numpy.random.shuffle', 'np.random.shuffle', ({(94, 18, 94, 28): 'rand_map_1'}, {}), '(rand_map_1)', True, 'import numpy as np\n'), ((95, 13, 95, 37), 'numpy.arange', 'np.arange', ({(95, 23, 95, 36): 'tile_shape[0]'}, {}), '(tile_shape[0])', True, 'import numpy as np\n'), ((96, 0, 96, 29), 'numpy.random.shuffle', 'np.random.shuffle', ({(96, 18, 96, 28): 'rand_map_2'}, {}), '(rand_map_2)', True, 'import numpy as np\n'), ((99, 12, 99, 52), 'numpy.logical_not', 'np.logical_not', ({(99, 27, 99, 51): 'pruning_mask[rand_map_0]'}, {}), '(pruning_mask[rand_map_0])', True, 'import numpy as np\n'), ((101, 15, 101, 64), 'numpy.logical_or', 'np.logical_or', ({(101, 29, 101, 41): 'pruning_mask', (101, 43, 101, 63): 'pruning_mask_recover'}, {}), '(pruning_mask, pruning_mask_recover)', True, 'import numpy as np\n'), ((102, 12, 102, 45), 'numpy.reshape', 'np.reshape', ({(102, 23, 102, 32): 'init_mask', (102, 34, 102, 44): 'tile_shape'}, {}), '(init_mask, tile_shape)', True, 'import numpy as np\n'), ((106, 20, 106, 71), 'numpy.tile', 'np.tile', ({(106, 28, 106, 38): 'rand_map_0', (106, 39, 106, 70): '[weight_shape[0] / tile_shape[0]]'}, {}), '(rand_map_0, [weight_shape[0] / tile_shape[0]])', True, 'import numpy as np\n'), ((107, 20, 107, 71), 'numpy.tile', 'np.tile', ({(107, 28, 107, 38): 'rand_map_1', (107, 39, 107, 70): '[weight_shape[0] / tile_shape[0]]'}, {}), '(rand_map_1, [weight_shape[0] / tile_shape[0]])', True, 'import numpy as np\n'), ((108, 20, 108, 71), 'numpy.tile', 'np.tile', ({(108, 28, 108, 38): 'rand_map_2', (108, 39, 108, 70): '[weight_shape[0] / tile_shape[0]]'}, {}), '(rand_map_2, [weight_shape[0] / tile_shape[0]])', True, 'import numpy as np\n'), ((115, 15, 115, 53), 'numpy.reshape', 'np.reshape', ({(115, 26, 115, 38): 'bl_w1_rand_0', (115, 40, 115, 52): 'weight_shape'}, {}), '(bl_w1_rand_0, weight_shape)', True, 'import numpy as np\n'), ((190, 15, 190, 33), 'numpy.array', 'np.array', ({(190, 24, 190, 32): 'bl_gamma'}, {}), '(bl_gamma)', True, 'import numpy as np\n'), ((191, 18, 191, 36), 'numpy.array', 'np.array', ({(191, 27, 191, 35): 'bl_means'}, {}), '(bl_means)', True, 'import numpy as np\n'), ((192, 25, 192, 50), 'numpy.array', 'np.array', ({(192, 34, 192, 49): 'bl_pruning_mask'}, {}), '(bl_pruning_mask)', True, 'import numpy as np\n'), ((255, 15, 255, 30), 'numpy.shape', 'np.shape', ({(255, 24, 255, 29): 'bl_w1'}, {}), '(bl_w1)', True, 'import numpy as np\n'), ((256, 13, 256, 30), 'numpy.shape', 'np.shape', ({(256, 22, 256, 29): 'pret_c1'}, {}), '(pret_c1)', True, 'import numpy as np\n'), ((257, 12, 257, 32), 'numpy.zeros', 'np.zeros', ({(257, 21, 257, 31): 'tile_shape'}, {}), '(tile_shape)', True, 'import numpy as np\n'), ((258, 11, 258, 30), 'numpy.ones', 'np.ones', ({(258, 19, 258, 29): 'tile_shape'}, {}), '(tile_shape)', True, 'import numpy as np\n'), ((262, 15, 262, 30), 'numpy.array', 'np.array', ({(262, 24, 262, 29): 'bl_w1'}, {}), '(bl_w1)', True, 'import numpy as np\n'), ((263, 8, 263, 23), 'numpy.array', 'np.array', ({(263, 17, 263, 22): 'bl_w1'}, {}), '(bl_w1)', True, 'import numpy as np\n'), ((265, 13, 265, 37), 'numpy.arange', 'np.arange', ({(265, 23, 265, 36): 'tile_shape[0]'}, {}), '(tile_shape[0])', True, 'import numpy as np\n'), ((266, 0, 266, 29), 'numpy.random.shuffle', 'np.random.shuffle', ({(266, 18, 266, 28): 'rand_map_0'}, {}), '(rand_map_0)', True, 'import numpy as np\n'), ((267, 13, 267, 37), 'numpy.arange', 'np.arange', ({(267, 23, 267, 36): 'tile_shape[0]'}, {}), '(tile_shape[0])', True, 'import numpy as np\n'), ((268, 0, 268, 29), 'numpy.random.shuffle', 'np.random.shuffle', ({(268, 18, 268, 28): 'rand_map_1'}, {}), '(rand_map_1)', True, 'import numpy as np\n'), ((269, 13, 269, 37), 'numpy.arange', 'np.arange', ({(269, 23, 269, 36): 'tile_shape[0]'}, {}), '(tile_shape[0])', True, 'import numpy as np\n'), ((270, 0, 270, 29), 'numpy.random.shuffle', 'np.random.shuffle', ({(270, 18, 270, 28): 'rand_map_2'}, {}), '(rand_map_2)', True, 'import numpy as np\n'), ((273, 12, 273, 52), 'numpy.logical_not', 'np.logical_not', ({(273, 27, 273, 51): 'pruning_mask[rand_map_0]'}, {}), '(pruning_mask[rand_map_0])', True, 'import numpy as np\n'), ((275, 15, 275, 64), 'numpy.logical_or', 'np.logical_or', ({(275, 29, 275, 41): 'pruning_mask', (275, 43, 275, 63): 'pruning_mask_recover'}, {}), '(pruning_mask, pruning_mask_recover)', True, 'import numpy as np\n'), ((276, 12, 276, 45), 'numpy.reshape', 'np.reshape', ({(276, 23, 276, 32): 'init_mask', (276, 34, 276, 44): 'tile_shape'}, {}), '(init_mask, tile_shape)', True, 'import numpy as np\n'), ((280, 20, 280, 71), 'numpy.tile', 'np.tile', ({(280, 28, 280, 38): 'rand_map_0', (280, 39, 280, 70): '[weight_shape[0] / tile_shape[0]]'}, {}), '(rand_map_0, [weight_shape[0] / tile_shape[0]])', True, 'import numpy as np\n'), ((281, 20, 281, 71), 'numpy.tile', 'np.tile', ({(281, 28, 281, 38): 'rand_map_1', (281, 39, 281, 70): '[weight_shape[0] / tile_shape[0]]'}, {}), '(rand_map_1, [weight_shape[0] / tile_shape[0]])', True, 'import numpy as np\n'), ((282, 20, 282, 71), 'numpy.tile', 'np.tile', ({(282, 28, 282, 38): 'rand_map_2', (282, 39, 282, 70): '[weight_shape[0] / tile_shape[0]]'}, {}), '(rand_map_2, [weight_shape[0] / tile_shape[0]])', True, 'import numpy as np\n'), ((289, 15, 289, 53), 'numpy.reshape', 'np.reshape', ({(289, 26, 289, 38): 'bl_w1_rand_0', (289, 40, 289, 52): 'weight_shape'}, {}), '(bl_w1_rand_0, weight_shape)', True, 'import numpy as np\n'), ((364, 15, 364, 33), 'numpy.array', 'np.array', ({(364, 24, 364, 32): 'bl_gamma'}, {}), '(bl_gamma)', True, 'import numpy as np\n'), ((365, 18, 365, 36), 'numpy.array', 'np.array', ({(365, 27, 365, 35): 'bl_means'}, {}), '(bl_means)', True, 'import numpy as np\n'), ((366, 25, 366, 50), 'numpy.array', 'np.array', ({(366, 34, 366, 49): 'bl_pruning_mask'}, {}), '(bl_pruning_mask)', True, 'import numpy as np\n'), ((429, 15, 429, 30), 'numpy.shape', 'np.shape', ({(429, 24, 429, 29): 'bl_w1'}, {}), '(bl_w1)', True, 'import numpy as np\n'), ((430, 13, 430, 30), 'numpy.shape', 'np.shape', ({(430, 22, 430, 29): 'pret_c1'}, {}), '(pret_c1)', True, 'import numpy as np\n'), ((431, 12, 431, 32), 'numpy.zeros', 'np.zeros', ({(431, 21, 431, 31): 'tile_shape'}, {}), '(tile_shape)', True, 'import numpy as np\n'), ((432, 11, 432, 30), 'numpy.ones', 'np.ones', ({(432, 19, 432, 29): 'tile_shape'}, {}), '(tile_shape)', True, 'import numpy as np\n'), ((436, 15, 436, 30), 'numpy.array', 'np.array', ({(436, 24, 436, 29): 'bl_w1'}, {}), '(bl_w1)', True, 'import numpy as np\n'), ((437, 8, 437, 23), 'numpy.array', 'np.array', ({(437, 17, 437, 22): 'bl_w1'}, {}), '(bl_w1)', True, 'import numpy as np\n'), ((439, 13, 439, 37), 'numpy.arange', 'np.arange', ({(439, 23, 439, 36): 'tile_shape[0]'}, {}), '(tile_shape[0])', True, 'import numpy as np\n'), ((440, 0, 440, 29), 'numpy.random.shuffle', 'np.random.shuffle', ({(440, 18, 440, 28): 'rand_map_0'}, {}), '(rand_map_0)', True, 'import numpy as np\n'), ((441, 13, 441, 37), 'numpy.arange', 'np.arange', ({(441, 23, 441, 36): 'tile_shape[0]'}, {}), '(tile_shape[0])', True, 'import numpy as np\n'), ((442, 0, 442, 29), 'numpy.random.shuffle', 'np.random.shuffle', ({(442, 18, 442, 28): 'rand_map_1'}, {}), '(rand_map_1)', True, 'import numpy as np\n'), ((443, 13, 443, 37), 'numpy.arange', 'np.arange', ({(443, 23, 443, 36): 'tile_shape[0]'}, {}), '(tile_shape[0])', True, 'import numpy as np\n'), ((444, 0, 444, 29), 'numpy.random.shuffle', 'np.random.shuffle', ({(444, 18, 444, 28): 'rand_map_2'}, {}), '(rand_map_2)', True, 'import numpy as np\n'), ((447, 12, 447, 52), 'numpy.logical_not', 'np.logical_not', ({(447, 27, 447, 51): 'pruning_mask[rand_map_0]'}, {}), '(pruning_mask[rand_map_0])', True, 'import numpy as np\n'), ((449, 15, 449, 64), 'numpy.logical_or', 'np.logical_or', ({(449, 29, 449, 41): 'pruning_mask', (449, 43, 449, 63): 'pruning_mask_recover'}, {}), '(pruning_mask, pruning_mask_recover)', True, 'import numpy as np\n'), ((450, 12, 450, 45), 'numpy.reshape', 'np.reshape', ({(450, 23, 450, 32): 'init_mask', (450, 34, 450, 44): 'tile_shape'}, {}), '(init_mask, tile_shape)', True, 'import numpy as np\n'), ((454, 20, 454, 71), 'numpy.tile', 'np.tile', ({(454, 28, 454, 38): 'rand_map_0', (454, 39, 454, 70): '[weight_shape[0] / tile_shape[0]]'}, {}), '(rand_map_0, [weight_shape[0] / tile_shape[0]])', True, 'import numpy as np\n'), ((455, 20, 455, 71), 'numpy.tile', 'np.tile', ({(455, 28, 455, 38): 'rand_map_1', (455, 39, 455, 70): '[weight_shape[0] / tile_shape[0]]'}, {}), '(rand_map_1, [weight_shape[0] / tile_shape[0]])', True, 'import numpy as np\n'), ((456, 20, 456, 71), 'numpy.tile', 'np.tile', ({(456, 28, 456, 38): 'rand_map_2', (456, 39, 456, 70): '[weight_shape[0] / tile_shape[0]]'}, {}), '(rand_map_2, [weight_shape[0] / tile_shape[0]])', True, 'import numpy as np\n'), ((463, 15, 463, 53), 'numpy.reshape', 'np.reshape', ({(463, 26, 463, 38): 'bl_w1_rand_0', (463, 40, 463, 52): 'weight_shape'}, {}), '(bl_w1_rand_0, weight_shape)', True, 'import numpy as np\n'), ((538, 15, 538, 33), 'numpy.array', 'np.array', ({(538, 24, 538, 32): 'bl_gamma'}, {}), '(bl_gamma)', True, 'import numpy as np\n'), ((539, 18, 539, 36), 'numpy.array', 'np.array', ({(539, 27, 539, 35): 'bl_means'}, {}), '(bl_means)', True, 'import numpy as np\n'), ((540, 25, 540, 50), 'numpy.array', 'np.array', ({(540, 34, 540, 49): 'bl_pruning_mask'}, {}), '(bl_pruning_mask)', True, 'import numpy as np\n'), ((603, 15, 603, 30), 'numpy.shape', 'np.shape', ({(603, 24, 603, 29): 'bl_w1'}, {}), '(bl_w1)', True, 'import numpy as np\n'), ((604, 13, 604, 30), 'numpy.shape', 'np.shape', ({(604, 22, 604, 29): 'pret_c1'}, {}), '(pret_c1)', True, 'import numpy as np\n'), ((605, 12, 605, 32), 'numpy.zeros', 'np.zeros', ({(605, 21, 605, 31): 'tile_shape'}, {}), '(tile_shape)', True, 'import numpy as np\n'), ((606, 11, 606, 30), 'numpy.ones', 'np.ones', ({(606, 19, 606, 29): 'tile_shape'}, {}), '(tile_shape)', True, 'import numpy as np\n'), ((610, 15, 610, 30), 'numpy.array', 'np.array', ({(610, 24, 610, 29): 'bl_w1'}, {}), '(bl_w1)', True, 'import numpy as np\n'), ((611, 8, 611, 23), 'numpy.array', 'np.array', ({(611, 17, 611, 22): 'bl_w1'}, {}), '(bl_w1)', True, 'import numpy as np\n'), ((613, 13, 613, 37), 'numpy.arange', 'np.arange', ({(613, 23, 613, 36): 'tile_shape[0]'}, {}), '(tile_shape[0])', True, 'import numpy as np\n'), ((614, 0, 614, 29), 'numpy.random.shuffle', 'np.random.shuffle', ({(614, 18, 614, 28): 'rand_map_0'}, {}), '(rand_map_0)', True, 'import numpy as np\n'), ((615, 13, 615, 37), 'numpy.arange', 'np.arange', ({(615, 23, 615, 36): 'tile_shape[0]'}, {}), '(tile_shape[0])', True, 'import numpy as np\n'), ((616, 0, 616, 29), 'numpy.random.shuffle', 'np.random.shuffle', ({(616, 18, 616, 28): 'rand_map_1'}, {}), '(rand_map_1)', True, 'import numpy as np\n'), ((617, 13, 617, 37), 'numpy.arange', 'np.arange', ({(617, 23, 617, 36): 'tile_shape[0]'}, {}), '(tile_shape[0])', True, 'import numpy as np\n'), ((618, 0, 618, 29), 'numpy.random.shuffle', 'np.random.shuffle', ({(618, 18, 618, 28): 'rand_map_2'}, {}), '(rand_map_2)', True, 'import numpy as np\n'), ((621, 12, 621, 52), 'numpy.logical_not', 'np.logical_not', ({(621, 27, 621, 51): 'pruning_mask[rand_map_0]'}, {}), '(pruning_mask[rand_map_0])', True, 'import numpy as np\n'), ((623, 15, 623, 64), 'numpy.logical_or', 'np.logical_or', ({(623, 29, 623, 41): 'pruning_mask', (623, 43, 623, 63): 'pruning_mask_recover'}, {}), '(pruning_mask, pruning_mask_recover)', True, 'import numpy as np\n'), ((624, 12, 624, 45), 'numpy.reshape', 'np.reshape', ({(624, 23, 624, 32): 'init_mask', (624, 34, 624, 44): 'tile_shape'}, {}), '(init_mask, tile_shape)', True, 'import numpy as np\n'), ((628, 20, 628, 71), 'numpy.tile', 'np.tile', ({(628, 28, 628, 38): 'rand_map_0', (628, 39, 628, 70): '[weight_shape[0] / tile_shape[0]]'}, {}), '(rand_map_0, [weight_shape[0] / tile_shape[0]])', True, 'import numpy as np\n'), ((629, 20, 629, 71), 'numpy.tile', 'np.tile', ({(629, 28, 629, 38): 'rand_map_1', (629, 39, 629, 70): '[weight_shape[0] / tile_shape[0]]'}, {}), '(rand_map_1, [weight_shape[0] / tile_shape[0]])', True, 'import numpy as np\n'), ((630, 20, 630, 71), 'numpy.tile', 'np.tile', ({(630, 28, 630, 38): 'rand_map_2', (630, 39, 630, 70): '[weight_shape[0] / tile_shape[0]]'}, {}), '(rand_map_2, [weight_shape[0] / tile_shape[0]])', True, 'import numpy as np\n'), ((637, 15, 637, 53), 'numpy.reshape', 'np.reshape', ({(637, 26, 637, 38): 'bl_w1_rand_0', (637, 40, 637, 52): 'weight_shape'}, {}), '(bl_w1_rand_0, weight_shape)', True, 'import numpy as np\n'), ((712, 15, 712, 33), 'numpy.array', 'np.array', ({(712, 24, 712, 32): 'bl_gamma'}, {}), '(bl_gamma)', True, 'import numpy as np\n'), ((713, 18, 713, 36), 'numpy.array', 'np.array', ({(713, 27, 713, 35): 'bl_means'}, {}), '(bl_means)', True, 'import numpy as np\n'), ((714, 25, 714, 50), 'numpy.array', 'np.array', ({(714, 34, 714, 49): 'bl_pruning_mask'}, {}), '(bl_pruning_mask)', True, 'import numpy as np\n'), ((737, 14, 737, 31), 'numpy.array', 'np.array', ({(737, 23, 737, 30): 'bl_beta'}, {}), '(bl_beta)', True, 'import numpy as np\n'), ((738, 15, 738, 33), 'numpy.array', 'np.array', ({(738, 24, 738, 32): 'bl_gamma'}, {}), '(bl_gamma)', True, 'import numpy as np\n'), ((739, 21, 739, 45), 'numpy.array', 'np.array', ({(739, 30, 739, 44): 'bl_moving_mean'}, {}), '(bl_moving_mean)', True, 'import numpy as np\n'), ((740, 25, 740, 53), 'numpy.array', 'np.array', ({(740, 34, 740, 52): 'bl_moving_variance'}, {}), '(bl_moving_variance)', True, 'import numpy as np\n'), ((753, 14, 753, 31), 'numpy.array', 'np.array', ({(753, 23, 753, 30): 'bl_beta'}, {}), '(bl_beta)', True, 'import numpy as np\n'), ((754, 15, 754, 33), 'numpy.array', 'np.array', ({(754, 24, 754, 32): 'bl_gamma'}, {}), '(bl_gamma)', True, 'import numpy as np\n'), ((755, 21, 755, 45), 'numpy.array', 'np.array', ({(755, 30, 755, 44): 'bl_moving_mean'}, {}), '(bl_moving_mean)', True, 'import numpy as np\n'), ((756, 25, 756, 53), 'numpy.array', 'np.array', ({(756, 34, 756, 52): 'bl_moving_variance'}, {}), '(bl_moving_variance)', True, 'import numpy as np\n'), ((769, 14, 769, 31), 'numpy.array', 'np.array', ({(769, 23, 769, 30): 'bl_beta'}, {}), '(bl_beta)', True, 'import numpy as np\n'), ((770, 15, 770, 33), 'numpy.array', 'np.array', ({(770, 24, 770, 32): 'bl_gamma'}, {}), '(bl_gamma)', True, 'import numpy as np\n'), ((771, 21, 771, 45), 'numpy.array', 'np.array', ({(771, 30, 771, 44): 'bl_moving_mean'}, {}), '(bl_moving_mean)', True, 'import numpy as np\n'), ((772, 25, 772, 53), 'numpy.array', 'np.array', ({(772, 34, 772, 52): 'bl_moving_variance'}, {}), '(bl_moving_variance)', True, 'import numpy as np\n'), ((785, 14, 785, 31), 'numpy.array', 'np.array', ({(785, 23, 785, 30): 'bl_beta'}, {}), '(bl_beta)', True, 'import numpy as np\n'), ((786, 15, 786, 33), 'numpy.array', 'np.array', ({(786, 24, 786, 32): 'bl_gamma'}, {}), '(bl_gamma)', True, 'import numpy as np\n'), ((787, 21, 787, 45), 'numpy.array', 'np.array', ({(787, 30, 787, 44): 'bl_moving_mean'}, {}), '(bl_moving_mean)', True, 'import numpy as np\n'), ((788, 25, 788, 53), 'numpy.array', 'np.array', ({(788, 34, 788, 52): 'bl_moving_variance'}, {}), '(bl_moving_variance)', True, 'import numpy as np\n'), ((801, 14, 801, 31), 'numpy.array', 'np.array', ({(801, 23, 801, 30): 'bl_beta'}, {}), '(bl_beta)', True, 'import numpy as np\n'), ((802, 15, 802, 33), 'numpy.array', 'np.array', ({(802, 24, 802, 32): 'bl_gamma'}, {}), '(bl_gamma)', True, 'import numpy as np\n'), ((803, 21, 803, 45), 'numpy.array', 'np.array', ({(803, 30, 803, 44): 'bl_moving_mean'}, {}), '(bl_moving_mean)', True, 'import numpy as np\n'), ((804, 25, 804, 53), 'numpy.array', 'np.array', ({(804, 34, 804, 52): 'bl_moving_variance'}, {}), '(bl_moving_variance)', True, 'import numpy as np\n'), ((85, 16, 85, 35), 'numpy.ones', 'np.ones', ({(85, 24, 85, 34): 'tile_shape'}, {}), '(tile_shape)', True, 'import numpy as np\n'), ((100, 23, 100, 62), 'numpy.logical_and', 'np.logical_and', ({(100, 38, 100, 50): 'pruning_mask', (100, 52, 100, 61): 'init_mask'}, {}), '(pruning_mask, init_mask)', True, 'import numpy as np\n'), ((259, 16, 259, 35), 'numpy.ones', 'np.ones', ({(259, 24, 259, 34): 'tile_shape'}, {}), '(tile_shape)', True, 'import numpy as np\n'), ((274, 23, 274, 62), 'numpy.logical_and', 'np.logical_and', ({(274, 38, 274, 50): 'pruning_mask', (274, 52, 274, 61): 'init_mask'}, {}), '(pruning_mask, init_mask)', True, 'import numpy as np\n'), ((433, 16, 433, 35), 'numpy.ones', 'np.ones', ({(433, 24, 433, 34): 'tile_shape'}, {}), '(tile_shape)', True, 'import numpy as np\n'), ((448, 23, 448, 62), 'numpy.logical_and', 'np.logical_and', ({(448, 38, 448, 50): 'pruning_mask', (448, 52, 448, 61): 'init_mask'}, {}), '(pruning_mask, init_mask)', True, 'import numpy as np\n'), ((607, 16, 607, 35), 'numpy.ones', 'np.ones', ({(607, 24, 607, 34): 'tile_shape'}, {}), '(tile_shape)', True, 'import numpy as np\n'), ((622, 23, 622, 62), 'numpy.logical_and', 'np.logical_and', ({(622, 38, 622, 50): 'pruning_mask', (622, 52, 622, 61): 'init_mask'}, {}), '(pruning_mask, init_mask)', True, 'import numpy as np\n'), ((18, 30, 18, 45), 'numpy.array', 'np.array', ({(18, 39, 18, 44): 'bl_w1'}, {}), '(bl_w1)', True, 'import numpy as np\n'), ((27, 13, 27, 38), 'numpy.array', 'np.array', ({(27, 22, 27, 37): 'bl_pruning_mask'}, {}), '(bl_pruning_mask)', True, 'import numpy as np\n'), ((98, 15, 98, 40), 'numpy.array', 'np.array', ({(98, 24, 98, 39): 'bl_pruning_mask'}, {}), '(bl_pruning_mask)', True, 'import numpy as np\n'), ((100, 63, 100, 85), 'numpy.argsort', 'np.argsort', ({(100, 74, 100, 84): 'rand_map_0'}, {}), '(rand_map_0)', True, 'import numpy as np\n'), ((187, 23, 187, 53), 'numpy.reshape', 'np.reshape', ({(187, 34, 187, 44): 'rand_map_0', (187, 46, 187, 52): '(-1, 1)'}, {}), '(rand_map_0, (-1, 1))', True, 'import numpy as np\n'), ((188, 23, 188, 53), 'numpy.reshape', 'np.reshape', ({(188, 34, 188, 44): 'rand_map_1', (188, 46, 188, 52): '(-1, 1)'}, {}), '(rand_map_1, (-1, 1))', True, 'import numpy as np\n'), ((189, 23, 189, 53), 'numpy.reshape', 'np.reshape', ({(189, 34, 189, 44): 'rand_map_2', (189, 46, 189, 52): '(-1, 1)'}, {}), '(rand_map_2, (-1, 1))', True, 'import numpy as np\n'), ((194, 20, 194, 57), 'numpy.reshape', 'np.reshape', ({(194, 31, 194, 48): 'rand_map_0_expand', (194, 50, 194, 56): '[-1, 1]'}, {}), '(rand_map_0_expand, [-1, 1])', True, 'import numpy as np\n'), ((196, 20, 196, 57), 'numpy.reshape', 'np.reshape', ({(196, 31, 196, 48): 'rand_map_1_expand', (196, 50, 196, 56): '[-1, 1]'}, {}), '(rand_map_1_expand, [-1, 1])', True, 'import numpy as np\n'), ((198, 20, 198, 57), 'numpy.reshape', 'np.reshape', ({(198, 31, 198, 48): 'rand_map_2_expand', (198, 50, 198, 56): '[-1, 1]'}, {}), '(rand_map_2_expand, [-1, 1])', True, 'import numpy as np\n'), ((201, 13, 201, 38), 'numpy.array', 'np.array', ({(201, 22, 201, 37): 'bl_pruning_mask'}, {}), '(bl_pruning_mask)', True, 'import numpy as np\n'), ((272, 15, 272, 40), 'numpy.array', 'np.array', ({(272, 24, 272, 39): 'bl_pruning_mask'}, {}), '(bl_pruning_mask)', True, 'import numpy as np\n'), ((274, 63, 274, 85), 'numpy.argsort', 'np.argsort', ({(274, 74, 274, 84): 'rand_map_0'}, {}), '(rand_map_0)', True, 'import numpy as np\n'), ((361, 23, 361, 53), 'numpy.reshape', 'np.reshape', ({(361, 34, 361, 44): 'rand_map_0', (361, 46, 361, 52): '(-1, 1)'}, {}), '(rand_map_0, (-1, 1))', True, 'import numpy as np\n'), ((362, 23, 362, 53), 'numpy.reshape', 'np.reshape', ({(362, 34, 362, 44): 'rand_map_1', (362, 46, 362, 52): '(-1, 1)'}, {}), '(rand_map_1, (-1, 1))', True, 'import numpy as np\n'), ((363, 23, 363, 53), 'numpy.reshape', 'np.reshape', ({(363, 34, 363, 44): 'rand_map_2', (363, 46, 363, 52): '(-1, 1)'}, {}), '(rand_map_2, (-1, 1))', True, 'import numpy as np\n'), ((368, 20, 368, 57), 'numpy.reshape', 'np.reshape', ({(368, 31, 368, 48): 'rand_map_0_expand', (368, 50, 368, 56): '[-1, 1]'}, {}), '(rand_map_0_expand, [-1, 1])', True, 'import numpy as np\n'), ((370, 20, 370, 57), 'numpy.reshape', 'np.reshape', ({(370, 31, 370, 48): 'rand_map_1_expand', (370, 50, 370, 56): '[-1, 1]'}, {}), '(rand_map_1_expand, [-1, 1])', True, 'import numpy as np\n'), ((372, 20, 372, 57), 'numpy.reshape', 'np.reshape', ({(372, 31, 372, 48): 'rand_map_2_expand', (372, 50, 372, 56): '[-1, 1]'}, {}), '(rand_map_2_expand, [-1, 1])', True, 'import numpy as np\n'), ((375, 13, 375, 38), 'numpy.array', 'np.array', ({(375, 22, 375, 37): 'bl_pruning_mask'}, {}), '(bl_pruning_mask)', True, 'import numpy as np\n'), ((446, 15, 446, 40), 'numpy.array', 'np.array', ({(446, 24, 446, 39): 'bl_pruning_mask'}, {}), '(bl_pruning_mask)', True, 'import numpy as np\n'), ((448, 63, 448, 85), 'numpy.argsort', 'np.argsort', ({(448, 74, 448, 84): 'rand_map_0'}, {}), '(rand_map_0)', True, 'import numpy as np\n'), ((535, 23, 535, 53), 'numpy.reshape', 'np.reshape', ({(535, 34, 535, 44): 'rand_map_0', (535, 46, 535, 52): '(-1, 1)'}, {}), '(rand_map_0, (-1, 1))', True, 'import numpy as np\n'), ((536, 23, 536, 53), 'numpy.reshape', 'np.reshape', ({(536, 34, 536, 44): 'rand_map_1', (536, 46, 536, 52): '(-1, 1)'}, {}), '(rand_map_1, (-1, 1))', True, 'import numpy as np\n'), ((537, 23, 537, 53), 'numpy.reshape', 'np.reshape', ({(537, 34, 537, 44): 'rand_map_2', (537, 46, 537, 52): '(-1, 1)'}, {}), '(rand_map_2, (-1, 1))', True, 'import numpy as np\n'), ((542, 20, 542, 57), 'numpy.reshape', 'np.reshape', ({(542, 31, 542, 48): 'rand_map_0_expand', (542, 50, 542, 56): '[-1, 1]'}, {}), '(rand_map_0_expand, [-1, 1])', True, 'import numpy as np\n'), ((544, 20, 544, 57), 'numpy.reshape', 'np.reshape', ({(544, 31, 544, 48): 'rand_map_1_expand', (544, 50, 544, 56): '[-1, 1]'}, {}), '(rand_map_1_expand, [-1, 1])', True, 'import numpy as np\n'), ((546, 20, 546, 57), 'numpy.reshape', 'np.reshape', ({(546, 31, 546, 48): 'rand_map_2_expand', (546, 50, 546, 56): '[-1, 1]'}, {}), '(rand_map_2_expand, [-1, 1])', True, 'import numpy as np\n'), ((549, 13, 549, 38), 'numpy.array', 'np.array', ({(549, 22, 549, 37): 'bl_pruning_mask'}, {}), '(bl_pruning_mask)', True, 'import numpy as np\n'), ((620, 15, 620, 40), 'numpy.array', 'np.array', ({(620, 24, 620, 39): 'bl_pruning_mask'}, {}), '(bl_pruning_mask)', True, 'import numpy as np\n'), ((622, 63, 622, 85), 'numpy.argsort', 'np.argsort', ({(622, 74, 622, 84): 'rand_map_0'}, {}), '(rand_map_0)', True, 'import numpy as np\n'), ((709, 23, 709, 53), 'numpy.reshape', 'np.reshape', ({(709, 34, 709, 44): 'rand_map_0', (709, 46, 709, 52): '(-1, 1)'}, {}), '(rand_map_0, (-1, 1))', True, 'import numpy as np\n'), ((710, 23, 710, 53), 'numpy.reshape', 'np.reshape', ({(710, 34, 710, 44): 'rand_map_1', (710, 46, 710, 52): '(-1, 1)'}, {}), '(rand_map_1, (-1, 1))', True, 'import numpy as np\n'), ((711, 23, 711, 53), 'numpy.reshape', 'np.reshape', ({(711, 34, 711, 44): 'rand_map_2', (711, 46, 711, 52): '(-1, 1)'}, {}), '(rand_map_2, (-1, 1))', True, 'import numpy as np\n'), ((716, 20, 716, 57), 'numpy.reshape', 'np.reshape', ({(716, 31, 716, 48): 'rand_map_0_expand', (716, 50, 716, 56): '[-1, 1]'}, {}), '(rand_map_0_expand, [-1, 1])', True, 'import numpy as np\n'), ((718, 20, 718, 57), 'numpy.reshape', 'np.reshape', ({(718, 31, 718, 48): 'rand_map_1_expand', (718, 50, 718, 56): '[-1, 1]'}, {}), '(rand_map_1_expand, [-1, 1])', True, 'import numpy as np\n'), ((720, 20, 720, 57), 'numpy.reshape', 'np.reshape', ({(720, 31, 720, 48): 'rand_map_2_expand', (720, 50, 720, 56): '[-1, 1]'}, {}), '(rand_map_2_expand, [-1, 1])', True, 'import numpy as np\n'), ((723, 13, 723, 38), 'numpy.array', 'np.array', ({(723, 22, 723, 37): 'bl_pruning_mask'}, {}), '(bl_pruning_mask)', True, 'import numpy as np\n'), ((27, 58, 27, 83), 'numpy.array', 'np.array', ({(27, 67, 27, 82): 'bl_pruning_mask'}, {}), '(bl_pruning_mask)', True, 'import numpy as np\n'), ((201, 58, 201, 83), 'numpy.array', 'np.array', ({(201, 67, 201, 82): 'bl_pruning_mask'}, {}), '(bl_pruning_mask)', True, 'import numpy as np\n'), ((375, 58, 375, 83), 'numpy.array', 'np.array', ({(375, 67, 375, 82): 'bl_pruning_mask'}, {}), '(bl_pruning_mask)', True, 'import numpy as np\n'), ((549, 58, 549, 83), 'numpy.array', 'np.array', ({(549, 67, 549, 82): 'bl_pruning_mask'}, {}), '(bl_pruning_mask)', True, 'import numpy as np\n'), ((723, 58, 723, 83), 'numpy.array', 'np.array', ({(723, 67, 723, 82): 'bl_pruning_mask'}, {}), '(bl_pruning_mask)', True, 'import numpy as np\n')]