LogicError: explicit_context_dependent failed: invalid device context - no currently active context?

The python example of resnet_as_a_service under tensorrt/examples/resnet_as_a_service/resnet_as_a_service.py does not work.

[2018-08-15 06:15:13,012] ERROR in app: Exception on /classify [POST]
Traceback (most recent call last):
File “/usr/local/lib/python2.7/dist-packages/flask/app.py”, line 2292, in wsgi_app
response = self.full_dispatch_request()
File “/usr/local/lib/python2.7/dist-packages/flask/app.py”, line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File “/usr/local/lib/python2.7/dist-packages/flask/app.py”, line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File “/usr/local/lib/python2.7/dist-packages/flask/app.py”, line 1813, in full_dispatch_request
rv = self.dispatch_request()
File “/usr/local/lib/python2.7/dist-packages/flask/app.py”, line 1799, in dispatch_request
return self.view_functionsrule.endpoint
File “/usr/local/lib/python2.7/dist-packages/tensorrt/examples/resnet_as_a_service/resnet_as_a_service.py”, line 117, in json_classify
results = engine.infer(image_to_np_CHW(img))[0]
File “/usr/local/lib/python2.7/dist-packages/tensorrt/lite/engine.py”, line 658, in infer
stream = cuda.Stream()
LogicError: explicit_context_dependent failed: invalid device context - no currently active context?
127.0.0.1 - - [15/Aug/2018 06:15:13] “POST /classify HTTP/1.1” 500 -

Any body help ?

I think the problem is that the pycuda.autoinit was never imported in the engine.py module. Try changing the init method so that it also imports this module as well as the pycuda.driver

2 Likes

you are right~

so “import pycuda.autoinit” may solve this issue.

3 Likes

I am facing same error while running tensorRT model on jetson nano using flask.
whereas the model is running ok on jupyter notebook.
Any help or suggestion ?

Solution:
https://stackoverflow.com/questions/61056832/facing-issue-while-running-flask-app-with-tensorrt-model-on-jetson-nano#comment108055562_61061543

confirmed, this solved it