2017-07-28 61 views
0

我有一个索贝尔滤波器如何在tensorflow中播放第三维?

sobel_x = tf.constant([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], tf.float32) 

我想要得到的64中深度的形状是暂时[3,3,1],但应引起[3,3,64]。

这怎么办?随着下面的行,我得到形状错误。

tf.tile(sobel_x, [1, 1, 64]) 



ValueError: Shape must be rank 2 but is rank 3 for 'Tile' (op: 'Tile') with input shapes: [3,3], [3]. 

回答

0

你不能广播的原因是第三维不存在,所以你实际上有一个秩2张量。

>>> sess.run(tf.shape(sobel_x)) 
array([3, 3], dtype=int32) 

我们可以通过先改变张量来解决这个问题。

>>> 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> 
0

我认为你的问题是与sobel_x。

sobel_x.get_shape(): TensorShape([Dimension(3), Dimension(3)]) sobel_x: <tf.tensor 'Const:0' shape=(3, 3) dtype=float32

所以sobel_x是一个二维矩阵,你传递一个等级3输入平铺因此错误。

修正:使sobel_x 3维,使得形状是shape=(3, 3, 1) 然后tf.tile(sobel_x, [1, 1, 64]将输出shape=(1, 1, 64)