7
我基本上想要將選項輸入到圖形中間並計算從那裏輸出。我的一個想法是使用默認爲零張量的tf.placeholder_with_default
。然後我可以使用加法混合可選輸入,但是在大的形狀上添加這似乎是很多不必要的計算。有沒有更好的方法來完成?如何將可選輸入添加到TensorFlow中的圖形中?
input_enabled = tf.placeholder_with_default(tf.constant(1.), [1])
input_shape = [None, in_size]
input = tf.placeholder_with_default(tf.zeros(input_shape), input_shape)
// ...
bottleneck_shape = [None, bottleneck_size]
bottleneck = input_enabled * f(prev_layer) + tf.placeholder_with_default(tf.zeros(bottleneck_shape), bottleneck_shape)
// ...
// Using graph with input at first layer:
sess.run([output], feed_dict={input: x})
// Using graph with input at bottleneck layer:
sess.run([output], feed_dict={bottleneck: b, input_enabled: 0.})
你能給出一個更具體的問題概述嗎?你想要什麼類型的可選輸入,並做什麼? –
A有一個類似autoencoder的圖形,我想用一個用於訓練的圖形重建代碼作爲瓶頸輸入。 –
你可以給你現在使用'tf.placeholder_with_default'的部分代碼來改變嗎? –