此代碼工作正常:TensorFlow主管防止變量賦值:圖形定稿,並且不能被修改
import tensorflow as tf
x = tf.Variable(initial_value=0)
with tf.Session() as session:
print session.run(x.assign(1))
但這個代碼失敗:
import tensorflow as tf
x = tf.Variable(initial_value=0)
supervisor = tf.train.Supervisor(logdir="/tmp")
with tf.Session() as session:
print session.run(x.assign(1))
唯一的區別是tf.train.Supervisor
的實例。請注意,我們甚至不使用主管創建管理會話。
的錯誤是:保持
python tf_supervisor_freeze.py
Traceback (most recent call last):
File "tf_supervisor_freeze.py", line 6, in <module>
print session.run(x.assign(1))
File "<virtual_env_path>/lib/python2.7/site-packages/tensorflow/python/ops/variables.py", line 522, in assign
return state_ops.assign(self._variable, value, use_locking=use_locking)
File "<virtual_env_path>/lib/python2.7/site-packages/tensorflow/python/ops/gen_state_ops.py", line 47, in assign
use_locking=use_locking, name=name)
File "<virtual_env_path>/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 491, in apply_op
preferred_dtype=default_dtype)
File "<virtual_env_path>/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 702, in internal_convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "<virtual_env_path>/lib/python2.7/site-packages/tensorflow/python/framework/constant_op.py", line 110, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
File "<virtual_env_path>/lib/python2.7/site-packages/tensorflow/python/framework/constant_op.py", line 103, in constant
attrs={"value": tensor_value, "dtype": dtype_value}, name=name).outputs[0]
File "<virtual_env_path>/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2286, in create_op
self._check_not_finalized()
File "<virtual_env_path>/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2009, in _check_not_finalized
raise RuntimeError("Graph is finalized and cannot be modified.")
RuntimeError: Graph is finalized and cannot be modified.
Process finished with exit code 1
錯誤如果tf.train.Supervisor(logdir="/tmp", summary_op=None, saver=None)
用於禁用一些主管的服務。
這個問題是由Github上的其他人提出的,但沒有提供答案;該請求改爲在StackOverflow上引發問題。唯一相關的StackOverflow question似乎沒有解決這個特定情況。
但他爲什麼這樣呢?我的意思是,定稿使得無法凍結圖表並將其保存到磁盤。 :( – oopcode