Whit this code:
import tensorflow as tf
w = tf.Variable(tf.random_normal( [ 3 , 3 , 1 , 1 ], stddev = 0.01 ))
if __name__ == '__main__':
initVar = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(initVar)
print w.eval()
Because of the data format w = tf.Variable(tf.random_normal( [kernel_height, kernel_width, input_channel, output_chhannel], stddev = 0.01 )), I would expect to see a matrix like this:
[[[[ -0.004 0.003 0.006]
[ -0.005 -0.008 0.001]
[ 0.006 0.007 0.002]]]]
but it prints this:
[[[[ 0.001]]
[[-0.031]]
[[-0.005]]]
[[[ 0.006]]
[[ 0.011]]
[[ 0.006]]]
[[[ 0.008]]
[[-0.001]]
[[ 0.014]]]]
What I want is to multiply my weight tensor values one-by-one with a constant tensor of 0 and 1 to have masked weights like:
w = [[[[ -0.004 0.003 0.006]
[ -0.005 -0.008 0.001]
[ 0.006 0.007 0.002]]]]
mask = [[[[ 1 1 1]
[ 1 1 0]
[ 0 0 0]]]]
w * mask = [[[[ -0.004 0.003 0.006]
[ -0.005 -0.008 0. ]
[ 0. 0. 0. ]]]]
The code I used it this:
mask = np.ones((3, 3, 1, 1), dtype=np.float32)
mask[1, 2, :, :] = 0.
mask[2, :, :, :] = 0.
weight = tf.get_variable("weight", [3, 3, 1, 1], tf.float32, tf.contrib.layers.xavier_initializer())
weight *= tf.constant(mask, dtype=tf.float32)
But seems it doesn't work properly. I appreciate your help.