Tensorflow-tf.reshape()詳細
TensorFlowはよく使われる深さ学習フレームワークであり、データの準備中にデータを所望の次元に処理することがよくあります.ここではreshape構文を使用する必要があります.
numpyのreshapeと同様に、基本構文は次のとおりです.
One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.
翻訳すると次のようになります.
1つの次元が-1に設定されている場合、この成分が表す次元は自動的に計算されます.
簡単に言えば-1はデフォルト値で、まず他の人に適しています.その時、総要素の個数を他のいくつかの積で割って、私は何が何であるべきですか.
ここでは以下の例で簡単に観察できます.
numpyのreshapeと同様に、基本構文は次のとおりです.
tf.reshape(tensor, shape, name=None)
One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.
翻訳すると次のようになります.
1つの次元が-1に設定されている場合、この成分が表す次元は自動的に計算されます.
簡単に言えば-1はデフォルト値で、まず他の人に適しています.その時、総要素の個数を他のいくつかの積で割って、私は何が何であるべきですか.
ここでは以下の例で簡単に観察できます.
# tensor 't' is [1, 2, 3, 4, 5, 6, 7, 8, 9]
# tensor 't' has shape [9]
reshape(t, [3, 3]) ==> [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
# tensor 't' is [[[1, 1], [2, 2]],
# [[3, 3], [4, 4]]]
# tensor 't' has shape [2, 2, 2]
reshape(t, [2, 4]) ==> [[1, 1, 2, 2],
[3, 3, 4, 4]]
# tensor 't' is [[[1, 1, 1],
# [2, 2, 2]],
# [[3, 3, 3],
# [4, 4, 4]],
# [[5, 5, 5],
# [6, 6, 6]]]
# tensor 't' has shape [3, 2, 3]
# pass '[-1]' to flatten 't'
reshape(t, [-1]) ==> [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6]
# -1 can also be used to infer the shape
# -1 is inferred to be 9:
reshape(t, [2, -1]) ==> [[1, 1, 1, 2, 2, 2, 3, 3, 3],
[4, 4, 4, 5, 5, 5, 6, 6, 6]]
# -1 is inferred to be 2:
reshape(t, [-1, 9]) ==> [[1, 1, 1, 2, 2, 2, 3, 3, 3],
[4, 4, 4, 5, 5, 5, 6, 6, 6]]
# -1 is inferred to be 3:
reshape(t, [ 2, -1, 3]) ==> [[[1, 1, 1],
[2, 2, 2],
[3, 3, 3]],
[[4, 4, 4],
[5, 5, 5],
[6, 6, 6]]]
# tensor 't' is [7]
# shape `[]` reshapes to a scalar
reshape(t, []) ==> 7