ahmetozlu / tensorflow_object_counting_api

🚀 The TensorFlow Object Counting API is an open source framework built on top of TensorFlow and Keras that makes it easy to develop object counting systems!
https://www.youtube.com/watch?v=yT_1eKJTdfk
MIT License
1.32k stars 545 forks source link

RuntimeError: Attempted to use a closed Session. #59

Closed LordKnish closed 3 years ago

LordKnish commented 4 years ago

I am experiencing this problem when running the single image object counting.py without modification

Traceback (most recent call last): File "single_image_object_counting.py", line 21, in result = object_counting_api.single_image_object_counting(input_video, detection_graph, category_index, is_color_recognition_enabled) # targeted objects counting File "B:\Tensorflow\models\research\object_detection\api\object_counting_api.py", line 511, in single_image_object_counting feed_dict={image_tensor: image_np_expanded}) File "C:\Users\berni\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\client\session.py", line 956, in run run_metadata_ptr) File "C:\Users\berni\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\client\session.py", line 1103, in _run raise RuntimeError('Attempted to use a closed Session.') RuntimeError: Attempted to use a closed Session.

Tensorflow: 1.15

auliarananana commented 4 years ago

did you solve it because i have same problem @ahmetozlu @cclauss

LordKnish commented 4 years ago

Yes, I used a different piece of code. Counting API is just broken is what i figured out. Badly made, over engineered and not explained well enough. I made my own which i may or may not post. Not sure yet. If you want an in depth explanation personally lmk

SaadAhmed1122 commented 4 years ago

I am also facing this problem plz give solution....

DuCaoTien commented 4 years ago

I solved it. The issue only is the syntax of python. The with tf.Session() as sess scope which automatically closes the sess object once it goes out of scope. You need to move all code under 'with tf.Session(graph=detection_graph) as sess:' to the same margin at the above with means all the code is inside 'tf.Session'. Good luck! Capture

drojasug commented 4 years ago

DuCaoTien it's right. It's an identation problem. I tried starting a pull request but was not able to. @auliarananana and @SaadAhmed1122 feel free to ping me if you need help.

sanchez-christian commented 2 years ago

@drojasug

DuCaoTien it's right. It's an identation problem. I tried starting a pull request but was not able to. @auliarananana and @SaadAhmed1122 feel free to ping me if you need help.

I'm getting a similar error. It says:

raise RuntimeError('Attempted to use a closed Session.')

RuntimeError: Attempted to use a closed Session.

I don't really know what that means. It's giving me error messages also from specific line in specific files in specific folders in anaconda. I however, cannot open those files because it says "IDLE quit unexpectedly" I am using a Mac.