Models: something went wrong when i was using the object_detection_tutorial.ipynb ,i cant get the result.

Created on 28 Mar 2018  路  20Comments  路  Source: tensorflow/models

hi ,i was following the tutorial https://pythonprogramming.net/introduction-use-tensorflow-object-detection-api-tutorial/ and i used jupyter to run the object_detection_tutorial.ipynb,but i cant get the same result as the tutorial did,iwent into the jupyter and run the command run all,but i get this when running part 3

utils/visualization_utils.py:25: UserWarning:
This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called before pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

The backend was originally set to 'module://ipykernel.pylab.backend_inline' by the following code:
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/lib/python2.7/dist-packages/ipykernel_launcher.py", line 16, in
app.launch_new_instance()
File "/usr/local/lib/python2.7/dist-packages/traitlets/config/application.py", line 658, in launch_instance
app.start()
File "/usr/local/lib/python2.7/dist-packages/ipykernel/kernelapp.py", line 486, in start
self.io_loop.start()
File "/usr/local/lib/python2.7/dist-packages/tornado/ioloop.py", line 1009, in start
self._run_callback(self._callbacks.popleft())
File "/usr/local/lib/python2.7/dist-packages/tornado/ioloop.py", line 760, in _run_callback
ret = callback()
File "/usr/local/lib/python2.7/dist-packages/tornado/stack_context.py", line 276, in null_wrapper
return fn(args, kwargs)
File "/usr/local/lib/python2.7/dist-packages/zmq/eventloop/zmqstream.py", line 536, in
self.io_loop.add_callback(lambda : self._handle_events(self.socket, 0))
File "/usr/local/lib/python2.7/dist-packages/zmq/eventloop/zmqstream.py", line 450, in _handle_events
self._handle_recv()
File "/usr/local/lib/python2.7/dist-packages/zmq/eventloop/zmqstream.py", line 480, in _handle_recv
self._run_callback(callback, msg)
File "/usr/local/lib/python2.7/dist-packages/zmq/eventloop/zmqstream.py", line 432, in _run_callback
callback(
args, *kwargs)
File "/usr/local/lib/python2.7/dist-packages/tornado/stack_context.py", line 276, in null_wrapper
return fn(
args, *kwargs)
File "/usr/local/lib/python2.7/dist-packages/ipykernel/kernelbase.py", line 283, in dispatcher
return self.dispatch_shell(stream, msg)
File "/usr/local/lib/python2.7/dist-packages/ipykernel/kernelbase.py", line 233, in dispatch_shell
handler(stream, idents, msg)
File "/usr/local/lib/python2.7/dist-packages/ipykernel/kernelbase.py", line 399, in execute_request
user_expressions, allow_stdin)
File "/usr/local/lib/python2.7/dist-packages/ipykernel/ipkernel.py", line 208, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "/usr/local/lib/python2.7/dist-packages/ipykernel/zmqshell.py", line 537, in run_cell
return super(ZMQInteractiveShell, self).run_cell(
args, *kwargs)
File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2718, in run_cell
interactivity=interactivity, compiler=compiler, result=result)
File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2828, in run_ast_nodes
if self.run_code(code, result):
File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2882, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 2, in
get_ipython().magic(u'matplotlib inline')
File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2160, in magic
return self.run_line_magic(magic_name, magic_arg_s)
File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2081, in run_line_magic
result = fn(
args,
kwargs)
File "", line 2, in matplotlib
File "/usr/local/lib/python2.7/dist-packages/IPython/core/magic.py", line 188, in
call = lambda f, a, *k: f(a, *k)
File "/usr/local/lib/python2.7/dist-packages/IPython/core/magics/pylab.py", line 100, in matplotlib
gui, backend = self.shell.enable_matplotlib(args.gui)
File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2950, in enable_matplotlib
pt.activate_matplotlib(backend)
File "/usr/local/lib/python2.7/dist-packages/IPython/core/pylabtools.py", line 309, in activate_matplotlib
matplotlib.pyplot.switch_backend(backend)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 231, in switch_backend
matplotlib.use(newbackend, warn=False, force=True)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/__init__.py", line 1410, in use
reload(sys.modules['matplotlib.backends'])
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/__init__.py", line 16, in
line for line in traceback.format_stack()

import matplotlib; matplotlib.use('Agg') # pylint: disable=multiple-statements

can anyone explain why and help me fix it ,thank you so much~~

Most helpful comment

I have a workaround for this issue. Just put the following code directly in the Python file that you're trying to run:

import matplotlib; matplotlib.use('Agg')

For instance I was trying to use model_main.py, so I changed the import section just below the __future__ imports:

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import matplotlib; matplotlib.use('Agg')

from absl import flags

import tensorflow as tf

from object_detection import model_hparams
from object_detection import model_lib
.....

This also fixed the following Tkinter threading exception: RuntimeError: main thread is not in main loop

All 20 comments

Hi I got the same error. have you find the solution?

Me too, any ideas for this?

I have also got the same problem. Anybody found a solution?

This is how I solved it.
I put this lines the first in my notebook program
import matplotlib matplotlib.use('Agg') # pylint: disable=multiple-statements
and I commented in /models/research/object_detection/utils/visualization_utils.py:25
line import matplotlib; matplotlib.use('Agg') # pylint: disable=multiple-statements

@Drgx96 锛孒i emmmmm,I just did as what you said ,but then I got another warnning ,
/usr/local/lib/python3.5/dist-packages/ipykernel_launcher.py:9: UserWarning:
This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called before pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

The backend was originally set to 'module://ipykernel.pylab.backend_inline' by the following code:
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.5/dist-packages/ipykernel_launcher.py", line 16, in
app.launch_new_instance()
File "/usr/local/lib/python3.5/dist-packages/traitlets/config/application.py", line 658, in launch_instance
app.start()
File "/usr/local/lib/python3.5/dist-packages/ipykernel/kernelapp.py", line 486, in start
self.io_loop.start()
File "/usr/local/lib/python3.5/dist-packages/tornado/platform/asyncio.py", line 112, in start
self.asyncio_loop.run_forever()
File "/usr/lib/python3.5/asyncio/base_events.py", line 345, in run_forever
self._run_once()
File "/usr/lib/python3.5/asyncio/base_events.py", line 1312, in _run_once
handle._run()
File "/usr/lib/python3.5/asyncio/events.py", line 125, in _run
self._callback(self._args)
File "/usr/local/lib/python3.5/dist-packages/tornado/ioloop.py", line 760, in _run_callback
ret = callback()
File "/usr/local/lib/python3.5/dist-packages/tornado/stack_context.py", line 276, in null_wrapper
return fn(
args, kwargs)
File "/usr/local/lib/python3.5/dist-packages/zmq/eventloop/zmqstream.py", line 536, in
self.io_loop.add_callback(lambda : self._handle_events(self.socket, 0))
File "/usr/local/lib/python3.5/dist-packages/zmq/eventloop/zmqstream.py", line 450, in _handle_events
self._handle_recv()
File "/usr/local/lib/python3.5/dist-packages/zmq/eventloop/zmqstream.py", line 480, in _handle_recv
self._run_callback(callback, msg)
File "/usr/local/lib/python3.5/dist-packages/zmq/eventloop/zmqstream.py", line 432, in _run_callback
callback(args, *kwargs)
File "/usr/local/lib/python3.5/dist-packages/tornado/stack_context.py", line 276, in null_wrapper
return fn(args, *kwargs)
File "/usr/local/lib/python3.5/dist-packages/ipykernel/kernelbase.py", line 283, in dispatcher
return self.dispatch_shell(stream, msg)
File "/usr/local/lib/python3.5/dist-packages/ipykernel/kernelbase.py", line 233, in dispatch_shell
handler(stream, idents, msg)
File "/usr/local/lib/python3.5/dist-packages/ipykernel/kernelbase.py", line 399, in execute_request
user_expressions, allow_stdin)
File "/usr/local/lib/python3.5/dist-packages/ipykernel/ipkernel.py", line 208, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "/usr/local/lib/python3.5/dist-packages/ipykernel/zmqshell.py", line 537, in run_cell
return super(ZMQInteractiveShell, self).run_cell(args, *kwargs)
File "/usr/local/lib/python3.5/dist-packages/IPython/core/interactiveshell.py", line 2728, in run_cell
interactivity=interactivity, compiler=compiler, result=result)
File "/usr/local/lib/python3.5/dist-packages/IPython/core/interactiveshell.py", line 2856, in run_ast_nodes
if self.run_code(code, result):
File "/usr/local/lib/python3.5/dist-packages/IPython/core/interactiveshell.py", line 2910, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 2, in
get_ipython().run_line_magic('matplotlib', 'inline')
File "/usr/local/lib/python3.5/dist-packages/IPython/core/interactiveshell.py", line 2095, in run_line_magic
result = fn(args,
kwargs)
File "", line 2, in matplotlib
File "/usr/local/lib/python3.5/dist-packages/IPython/core/magic.py", line 187, in
call = lambda f, *a, *
k: f(a, *k)
File "/usr/local/lib/python3.5/dist-packages/IPython/core/magics/pylab.py", line 99, in matplotlib
gui, backend = self.shell.enable_matplotlib(args.gui)
File "/usr/local/lib/python3.5/dist-packages/IPython/core/interactiveshell.py", line 2978, in enable_matplotlib
pt.activate_matplotlib(backend)
File "/usr/local/lib/python3.5/dist-packages/IPython/core/pylabtools.py", line 308, in activate_matplotlib
matplotlib.pyplot.switch_backend(backend)
File "/usr/local/lib/python3.5/dist-packages/matplotlib/pyplot.py", line 231, in switch_backend
matplotlib.use(newbackend, warn=False, force=True)
File "/usr/local/lib/python3.5/dist-packages/matplotlib/__init__.py", line 1410, in use
reload(sys.modules['matplotlib.backends'])
File "/usr/lib/python3.5/importlib/__init__.py", line 166, in reload
_bootstrap._exec(spec, module)
File "/usr/local/lib/python3.5/dist-packages/matplotlib/backends/__init__.py", line 16, in
line for line in traceback.format_stack()

if __name__ == '__main__':
I cant find the reason for this ,but i got the result !
thanks anyway!

so have u found? cause i also tried that and got the same error like ur CallMe smth like' line for line in traceback.format_stack()

I also have this problem. Did you fix it and how?

I clone the lastest tensorflow/model, still have this problem.

I too fixed it by just commenting import matplotlib matplotlib.use('Agg') # pylint: disable=multiple-statements in visualization_utils.py file and by removing (matplotlib line -> from matplotlib import pyplot as plt) from bottom and placing it in the beginning of py file (object detection_tutorial.py)

@majeedhussain49 Can you elaborate that fix. Please mail it to [email protected]

-cd tensorflow/models/research/object_detection/utils/
-vi visualization_utils.py
and make these change
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
Hopefully this helps.

In latest API version, it has been like you say @tibro26 :

import matplotlib; matplotlib.use('Agg')  # pylint: disable=multiple-statements
import matplotlib.pyplot as plt  # pylint: disable=g-import-not-at-top

Still not work.

I have a workaround for this issue. Just put the following code directly in the Python file that you're trying to run:

import matplotlib; matplotlib.use('Agg')

For instance I was trying to use model_main.py, so I changed the import section just below the __future__ imports:

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import matplotlib; matplotlib.use('Agg')

from absl import flags

import tensorflow as tf

from object_detection import model_hparams
from object_detection import model_lib
.....

This also fixed the following Tkinter threading exception: RuntimeError: main thread is not in main loop

I don't think this is a fatal warning. My Program runs fine even with this warning. I,m using tensorflow 1.9 on python2

I got the same warning from the commit of 17fa52864bfc7a7444a8b921d8a8eb1669e14ebd

$ git log -1
commit 17fa52864bfc7a7444a8b921d8a8eb1669e14ebd
Author: Reed reedwm@google.com
Date: Thu Sep 13 17:05:22 2018 -0700

Wait longer for async process to spawn. (#5307)

Sometimes it takes longer than 15 seconds, and even longer than 1 minute, to spawn and create the alive file.

I just removed the line in the first block that read from matplotlib import pyplot as plt and it fixed it.

Closing as this is resolved

I restarted the kernel that imports matplotlib and all is good. It happens only when I execute that very same kernel a second time.

This warning is still present.

Update matplotlib and restart kernel worked for me.

Was this page helpful?
0 / 5 - 0 ratings