我試圖從我目前正在閱讀的論文的實作中了解以下內容:
在tensorflow, 如果我有一個x形狀張量(4,64,5,5)
然后我通過做創建一個新的維度
x = x[:,:,tf.newaxis]以一個新的張量結束
shape(4,64,1,5,5)然后我做
x = tf.tile(x, (1, 1, 5, 1, 1))
以某種形狀結束 (4,64,5,5,5)
閱讀 的檔案tf.tile,我仍然不明白在這種情況下它到底在做什么。我是否將新維度復制了 5 次?如果是,那么 tensorflow 在新維度中究竟放置了什么?我到底在復制什么?
uj5u.com熱心網友回復:
它實際上是通過在第三維上重復輸入 5 次來創建一個新的張量,從而產生 5 x 5 行 x 5 列:
x = tf.random.uniform(((1,1,5,5)))
x = x[:,:,tf.newaxis]
print('Before tile -->', x)
x = tf.tile(x, (1, 1, 5, 1, 1))
print('After tile -->', x)
Before tile --> tf.Tensor(
[[[[[0.86033905 0.91900826 0.39433706 0.9772172 0.32149637]
[0.01335323 0.03711665 0.664286 0.11703181 0.7997707 ]
[0.7063314 0.01817334 0.685941 0.6407242 0.59115565]
[0.819417 0.46511436 0.00940382 0.12464321 0.9256897 ]
[0.45731974 0.8999344 0.3199395 0.41329288 0.05623758]]]]], shape=(1, 1, 1, 5, 5), dtype=float32)
After tile --> tf.Tensor(
[[[[[0.86033905 0.91900826 0.39433706 0.9772172 0.32149637]
[0.01335323 0.03711665 0.664286 0.11703181 0.7997707 ]
[0.7063314 0.01817334 0.685941 0.6407242 0.59115565]
[0.819417 0.46511436 0.00940382 0.12464321 0.9256897 ]
[0.45731974 0.8999344 0.3199395 0.41329288 0.05623758]]
[[0.86033905 0.91900826 0.39433706 0.9772172 0.32149637]
[0.01335323 0.03711665 0.664286 0.11703181 0.7997707 ]
[0.7063314 0.01817334 0.685941 0.6407242 0.59115565]
[0.819417 0.46511436 0.00940382 0.12464321 0.9256897 ]
[0.45731974 0.8999344 0.3199395 0.41329288 0.05623758]]
[[0.86033905 0.91900826 0.39433706 0.9772172 0.32149637]
[0.01335323 0.03711665 0.664286 0.11703181 0.7997707 ]
[0.7063314 0.01817334 0.685941 0.6407242 0.59115565]
[0.819417 0.46511436 0.00940382 0.12464321 0.9256897 ]
[0.45731974 0.8999344 0.3199395 0.41329288 0.05623758]]
[[0.86033905 0.91900826 0.39433706 0.9772172 0.32149637]
[0.01335323 0.03711665 0.664286 0.11703181 0.7997707 ]
[0.7063314 0.01817334 0.685941 0.6407242 0.59115565]
[0.819417 0.46511436 0.00940382 0.12464321 0.9256897 ]
[0.45731974 0.8999344 0.3199395 0.41329288 0.05623758]]
[[0.86033905 0.91900826 0.39433706 0.9772172 0.32149637]
[0.01335323 0.03711665 0.664286 0.11703181 0.7997707 ]
[0.7063314 0.01817334 0.685941 0.6407242 0.59115565]
[0.819417 0.46511436 0.00940382 0.12464321 0.9256897 ]
[0.45731974 0.8999344 0.3199395 0.41329288 0.05623758]]]]], shape=(1, 1, 5, 5, 5), dtype=float32)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/383020.html
