我基本上想要在图表的中间提供输入选项,并从那里计算输出。我想到一个主意是使用tf.placeholder_with_default
,它默认为零张量。然后我可以使用加法混合可选输入,但是在大形状上进行加法似乎会产生很多不必要的计算。有更好的实现方式吗?
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.})
tf.placeholder_with_default
的代码部分吗?你想要修改哪一部分呢? - Olivier Moindrot