目前,我只有一個通道的輸入張量。我試圖弄清楚如何添加額外的頻道。如何在張量流中添加更多輸入張量的通道?
例如,可以說當前輸入的8×8通道之一 -
01, 02,...08,
09, 10,...16,
.
.
57, 58,...64
而且我要補充8×8的兩個通道(以零填充) -
0, 0,...0,
0, 0,...0,
.
.
0, 0,...0
我當前的代碼(接受大小64的列表並重塑爲8x8的1個通道) -
x = tf.placeholder(tf.float32, shape=[None, 64])
x_image = tf.reshape(x, [-1, 8, 8, 1])
input = [1, 2, ...64] #list of 64 items
train_step_policy.run(feed_dict={x: [input], y: [some output list]}, session= sess)
要添加2個chann ELS,我已經改變了代碼,這一點 -
x = tf.placeholder(tf.float32, shape=[None, 64*3])
x_image = tf.reshape(x, [-1, 8, 8, 3])
input = [1, 2, ...64] #list of 64 items
#Inserted 2 more items after each item in the input list
temp = [0*64]
inputchannel3 = [[]]
for b1 in input:
del temp[:]
for b2 in b1:
temp += [b2] + [0] + [0]
inputchannel3.append(temp)
train_step_policy.run(feed_dict={x: inputchannel3, y: [some output list]}, session= sess)
inputchannel3
樣子 - [1, 0, 0, 2, 0, 0, ...64, 0, 0]
我的問題是 - 這是增加新的渠道的正確方法?
我問這個問題的原因是,我不清楚如何tf.reshape
會做這種重塑。是否知道每隔3個項目(而不是3個連續項目)創建3個頻道?
您可以直接使用tf.zeros或tf.zeros_like在TensorFlow中添加零張量。形狀可以通過tensor.get_shape()找到。 tf.concat或tf.stack形成新的張量。這是在圖形內部進行操作的一種方法,它使事情變得清潔。否則,我認爲您應該瞭解如何重塑其形狀,並相應地將數據格式化爲NumPy。 – pfredriksen
@pfredriksen謝謝。零張量的東西只是爲了保持簡單的問題。謝謝,我會研究tf.concat和堆棧。從我讀到的關於重塑的內容來看,它看起來確實並且編譯良好,但由於這是我第一次使用多個通道重塑,我想知道是否有人比我更有知識可以證實它確實是正確的方式申請使用3個頻道。 – Achilles