将可视化操作分组在一起时,下面两个程序之间生成的输出之间存在很大差异。
tf.name_scope
提供双rnn输出,一个在name_scope
内,一个在外,而tf.variable_scope
给出更清晰的表示。我怎么知道我是否必须在变量与名称范围内包装一些东西(除get_variable
的明显情况外)?
import tensorflow as tf
with tf.name_scope("bongo"):
x = tf.placeholder(tf.float32,[1,None, 50], name='myxxxx')
lstm = tf.contrib.rnn.BasicLSTMCell(77)
drop = tf.contrib.rnn.DropoutWrapper(lstm, output_keep_prob=0.5)
cell = tf.contrib.rnn.MultiRNNCell([drop] * 3)
initial_state = cell.zero_state(33, tf.float32)
with tf.name_scope("alias"):
outputs, final_state = tf.nn.dynamic_rnn(
cell,
x, dtype=tf.float32)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
fw = tf.summary.FileWriter('/tmp/testmodel/1', sess.graph)
和
import tensorflow as tf
with tf.name_scope("bongo"):
x = tf.placeholder(tf.float32,[1,None, 50], name='myxxxx')
lstm = tf.contrib.rnn.BasicLSTMCell(77)
drop = tf.contrib.rnn.DropoutWrapper(lstm, output_keep_prob=0.5)
cell = tf.contrib.rnn.MultiRNNCell([drop] * 3)
initial_state = cell.zero_state(33, tf.float32)
with tf.variable_scope("alias"):
outputs, final_state = tf.nn.dynamic_rnn(
cell,
x, dtype=tf.float32)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
fw = tf.summary.FileWriter('/tmp/testmodel/1', sess.graph)