tensorflow: 1.1.0
tflearn: 0.3.2
I've noticed that model.load() closes the current session.
This code:
with tf.Session() as sess:
# Create a model
model = tflearn.DNN(network, tensorboard_verbose=0, session=sess)
sess.run(tf.global_variables_initializer())
# Offending Code
model.load("graph.chkp")
# Cannot run this line
print(sess.run(tf.add(5, 6)))
Raises the following error:
RuntimeError: Attempted to use a closed Session.
Traceback (most recent call last):
File "test.py", line 132, in <module>
print(sess.run(tf.add(5, 6)))
File "C:\ProgramData\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\client\session.py", line 1214, in __exit__
exec_type, exec_value, exec_tb)
File "C:\ProgramData\Anaconda3\envs\tf\lib\contextlib.py", line 77, in __exit__
self.gen.throw(type, value, traceback)
File "C:\ProgramData\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\framework\ops.py", line 3625, in get_controller
yield default
File "detection.py", line 132, in <module>
print(sess.run(tf.add(5, 6)))
File "C:\ProgramData\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\client\session.py", line 778, in run
run_metadata_ptr)
File "C:\ProgramData\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\client\session.py", line 914, in _run
raise RuntimeError('Attempted to use a closed Session.')
RuntimeError: Attempted to use a closed Session.
if I comment model.load("graph.chkp") then it runs fine.
Is this a bug or am I doing anything wrong?
The reason I need the session is to later freeze the network.
Figure it out!
Instead of doing:
print(sess.run(tf.add(5, 6)))
I need to:
print(model.session.run(tf.add(5, 6)))
Basically use the session that comes from the model.
Most helpful comment
Figure it out!
Instead of doing:
print(sess.run(tf.add(5, 6)))I need to:
print(model.session.run(tf.add(5, 6)))Basically use the session that comes from the model.