2017-07-28 7 views
0

私は形に64の深さを取得したいソーベルフィルタテンソルフローで3次元をブロードキャストする方法は?

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

を持っているが、[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

ブロードキャストできない理由は、3次元が存在しないため、実際にはランク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は、2次元マトリクスであり、あなたは、それゆえのタイルにエラーをランク3入力を渡します。

修正:形状はshape=(3, 3, 1) 次いでtf.tile(sobel_x, [1, 1, 64]意志出力shape=(1, 1, 64)

あることsobel_x 3次元のようなメイク
関連する問題