我想从模型参数的特定值开始优化tensorflow中的模型。为此,我创建了以下代码:
s = tf.Session()
s.run(tf.global_variables_initializer())
W = s.run(tf.assign(W, weights)) # <------- LINE 1
c1 = s.run(C, feed_dict = {X : Xs})
if verbose: print '\nInitial costs:', c1, '\n'
for i in range(n_steps):
s.run(T, feed_dict = {X : Xs})
c = s.run(C, feed_dict = {X : Xs})
if verbose: print '\t', i, '\t', c
print s.run(W) # <------- LINE 2
s.close()
现在,如果我按原样运行它,会得到以下错误:
TypeError: Fetch argument array([0.5, 0.5, 0.5, 0.5, 0.5]) has invalid type <type 'numpy.ndarray'>, must be a string or Tensor. (Can not convert a ndarray into a Tensor or Operation.)
但是,当我评论第1行或第2行时,它开始工作。
所以,看起来我可以设置一个初始值w,但是之后我不能得到它的优化值。或者,或者,我可以得到优化的值,但前提是我从一个随机值开始。