TensorFlow controller prevents variable assignment: the graph is complete and cannot be changed

This code works fine:

import tensorflow as tf
x = tf.Variable(initial_value=0)

with tf.Session() as session:
    print session.run(x.assign(1))

But this code does not work:

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))

The only difference is creating a tf.train.Supervisor. Note that we do not even use the dispatcher to create a managed session.

Error:

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

The error remains if tf.train.Supervisor(logdir="/tmp", summary_op=None, saver=None)used to disable some supervisor services.

This problem was raised by someone else on Github , but there was no answer; the request was to raise the issue on StackOverflow. The only up-to-date https://stackoverflow.com/a/167482/ ... does not seem to affect this particular case.

+4
source share
2

, , .

RuntimeError ( " ".)

tf.train.Supervisor() . /tensorflow/python/training/supervisor.py 1.0.

:

# The graph is not allowed to change anymore.
graph.finalize()

, Supervisor().

+4

, , . :

import tensorflow as tf
x = tf.Variable(initial_value=0)
a = x.assign(1)
supervisor = tf.train.Supervisor(logdir="/tmp")

with tf.Session() as session:
    print session.run(a)

, , - (.. a = x.assign(1)). , , .

+3

Source: https://habr.com/ru/post/1674480/


All Articles