partial_run()需要空的target_list

时间:2018-06-15 13:52:54

标签: python tensorflow deep-learning

我想在tensorflow中逐步运行传感器,所以我使用partial_run_setup和partial_run。并且此代码运行时没有错误:

import tensorflow as tf

x = tf.placeholder("float")
feed = {x: 3.0}
a = tf.Variable(1.0)
b = tf.Variable(2.0)
o1=tf.add(a,x)
o2=tf.train.AdadeltaOptimizer(0.1).minimize(o1)

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(sess.run(o2,feed))

但是这段代码显示错误:

import tensorflow as tf

x = tf.placeholder("float")
feed = {x: 3.0}
a = tf.Variable(1.0)
b = tf.Variable(2.0)
o1=tf.add(a,x)
o2=tf.train.AdadeltaOptimizer(0.1).minimize(o1)

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    h = sess.partial_run_setup([o1, o2], [x])
    print(sess.partial_run(h, o1,feed))
    print(sess.partial_run(h, o2,feed))

错误列表:

Traceback (most recent call last):
  File "test.py", line 15, in <module>
    print(sess.partial_run(h, o2,feed))
  File "/home/zhcong/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 945, in partial_run
    return self._run(handle, fetches, feed_dict, None, None)
  File "/home/zhcong/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1120, in _run
    feed_dict_tensor, options, run_metadata)
  File "/home/zhcong/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1319, in _do_run
    return self._do_call(_prun_fn, self._session, handle, feeds, fetches)
  File "/home/zhcong/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1323, in _do_call
    return fn(*args)
  File "/home/zhcong/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1306, in _prun_fn
    raise RuntimeError('partial_run() requires empty target_list.')
RuntimeError: partial_run() requires empty target_list.

1 个答案:

答案 0 :(得分:0)

Tensorflow partial_run不接受优化程序作为提取。您可以使用

with tf.control_dependencies([o2]):
  dummy = tf.constant(0)

并在partial_run中传递假人

检查以下内容:https://github.com/tensorflow/tensorflow/issues/1899