Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

something went wrong when i was using the object_detection_tutorial.ipynb ,i cant get the result. #3786

Closed
CallmeAG opened this issue Mar 28, 2018 · 20 comments

Comments

@CallmeAG
Copy link

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~~

@SaimaNasirOfficial
Copy link

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

@TioSJ
Copy link

TioSJ commented Mar 31, 2018

Me too, any ideas for this?

@RatGabi
Copy link

RatGabi commented Apr 2, 2018

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

@RatGabi
Copy link

RatGabi commented Apr 2, 2018

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

@CallmeAG
Copy link
Author

CallmeAG commented Apr 2, 2018

@Drgx96 ,Hi 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!

@talgart
Copy link

talgart commented Apr 2, 2018

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()

@dextroza
Copy link

dextroza commented Apr 4, 2018

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

clsung added a commit to clsung/models that referenced this issue Apr 22, 2018
commit:7a9934d has change the matplotlib imports, it cause
object_det4ection_tutorial.ipynb to unable to run.
This commit fixes the problem.
@roachsinai
Copy link

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

@majeedhussain49
Copy link

majeedhussain49 commented May 9, 2018

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)

@sapt09
Copy link

sapt09 commented May 11, 2018

@majeedhussain49 Can you elaborate that fix. Please mail it to savantadarsh@gmail.com

@tibro26
Copy link

tibro26 commented May 31, 2018

-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.

@irmowan
Copy link
Contributor

irmowan commented Jul 13, 2018

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.

@ghost
Copy link

ghost commented Jul 20, 2018

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

@Manish-rai21bit
Copy link

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

@dalianzhouzf
Copy link

I got the same warning from the commit of 17fa528

$ git log -1
commit 17fa528
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.

@JakeMalis
Copy link

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

@wt-huang
Copy link

wt-huang commented Nov 1, 2018

Closing as this is resolved

@wt-huang wt-huang closed this as completed Nov 1, 2018
@zhyiyu
Copy link

zhyiyu commented Sep 26, 2019

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

@Mohit-Ak
Copy link

This warning is still present.

@Ramanujam-RS
Copy link

Update matplotlib and restart kernel worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests