[英]Select which tensor to use in middle of TensorFlow graph
基本上,我有一張張量的python列表,可以用作圖其余部分的輸入。 我想從其中之一中進行選擇,而無需添加需要計算列表中所有張量的額外依賴項(我認為如果使用tf.cond會發生這種情況)。 如何選擇其中之一? 我無法在python級別上執行此操作,因為我根據從占位符計算出的值選擇了張量。 例如:
x = tf.placeholder(tf.int32, shape=(num_steps, None))
y = tf.placeholder(tf.int32, shape=(None,))
lengths = tf.placeholder(tf.int32, shape=(None,))
# Pretend there is a bunch of lines of code here
output_index = max_sequence_length = tf.reduce_max(lengths)
final_output = potential_outputs[output_index] # won't work, output_index is Tensor
# Pretend the rest of the model uses final_output
我正在展開一個RNN,我只想展開到序列的最大長度。 如果少於展開步驟的數量,則會浪費大量計算資源。 Dynamic_rnn和static_rnn無法滿足我的需求,因此我試圖提出自己的自定義方法來展開圖形。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.