How to broadcast third dimension in tensorflow? -
i have sobel filter
sobel_x = tf.constant([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], tf.float32)
i want depth of 64. shape momentarily [3,3,1], should result in [3,3,64].
how that? following line, shape errors.
tf.tile(sobel_x, [1, 1, 64]) valueerror: shape must rank 2 rank 3 'tile' (op: 'tile') input shapes: [3,3], [3].
the reason cannot broadcast third dimension not exist, , have rank 2 tensor.
>>> sess.run(tf.shape(sobel_x)) array([3, 3], dtype=int32)
we can solve problem reshaping tensor first.
>>> sobel_x = tf.reshape(sobel_x, [3, 3, 1]) >>> tf.tile(sobel_x, [1, 1, 64]) <tf.tensor 'tile_6:0' shape=(3, 3, 64) dtype=float32>
Comments
Post a Comment