当我运行sess.run时,我在模型中的权重会被更新(而不是训练步骤),这一点让我很难理解。
我尝试给我的模型提供变量,以获得估计的输出,但是当我运行sess.run时,权重会被更新。
### in the training phase ####
X_eval, Y_eval, O_eval, W_eval, cost_eval, train_step_eval = sess.run([X, Y, O_out, W, cost, train_step], feed_dict={X:x_batch , Y:y_batch})
### when the training is finished (closed for loop) ###
print(W_eval)
Y_out, W_eval2 = sess.run([O_out, W], feed_dict = {X:labeled_features[:,: - n_labels], Y:labeled_features[:,- n_labels :]})
print(W_eval2)当我比较W_eval和W_eval2时,它们是不一样的,我不明白为什么。请你指出正确的方向,为什么重量不一样?
'w3': array([[-2.9685912],
[-3.215485 ],
[ 3.8806837],
[-3.331745 ],
[-3.3904853]], dtype=float32
'w3': array([[-2.9700036],
[-3.2168453],
[ 3.8804765],
[-3.3330843],
[-3.3922129]], dtype=float32提前谢谢你。
编辑添加了W_eval赋值。
发布于 2018-06-20 12:29:38
你的代码
### in the training phase ####
X_eval, Y_eval, O_eval, W_eval, cost_eval, train_step_eval = sess.run([X, Y, O_out, W, cost, train_step], feed_dict={X:x_batch , Y:y_batch})
### when the training is finished (closed for loop) ###
print(W_eval)
Y_out, W_eval2 = sess.run([O_out, W], feed_dict = {X:labeled_features[:,: - n_labels], Y:labeled_features[:,- n_labels :]})
print(W_eval2)仍然执行train_step。要理解正在发生的事情,一个更简单的版本是:
import tensorflow as tf
a = tf.get_variable('a', initializer=42.)
train_step = a.assign(a + 1)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
value, _ = sess.run([a, train_step]) # will update a
print(value)
value = sess.run([a]) # will not update a
print(value)
value = sess.run([a]) # will not update a
print(value)给出输出
42.0
[43.0]
[43.0]另一件要检查的事情是,x_batch == labeled_features[:,: - n_labels]是否持有。
https://stackoverflow.com/questions/50945179
复制相似问题