Tflearn: model.load closes session.

Created on 25 Sep 2017  路  1Comment  路  Source: tflearn/tflearn

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.

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.

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bnaul picture bnaul  路  3Comments

bittlingmayer picture bittlingmayer  路  4Comments

benbogin picture benbogin  路  5Comments

SebastianKlein picture SebastianKlein  路  3Comments

luoruisichuan picture luoruisichuan  路  5Comments