Caffe: 'GDK_IS_DISPLAY (display)' failed

Created on 5 Aug 2014  ·  16Comments  ·  Source: BVLC/caffe

I was not able to run classify.py via SSH.
I don't want to use X11 during classification, is there any way to avoid that?

zxi@pearl:~/repo/CNN/scripts$ ./classify.py 12.png out

(classify.py:28845): Gdk-CRITICAL : gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed
Traceback (most recent call last):
File "./classify.py", line 14, in
import caffe
File "/home/zxi/repo/CNN/scripts/caffe/
init.py", line 1, in
from .pycaffe import Net, SGDSolver
File "/home/zxi/repo/CNN/scripts/caffe/pycaffe.py", line 11, in
import caffe.io
File "/home/zxi/repo/CNN/scripts/caffe/io.py", line 2, in
import skimage.io
File "/usr/local/lib/python2.7/dist-packages/skimage/io/
init**.py", line 15, in
reset_plugins()
File "/usr/local/lib/python2.7/dist-packages/skimage/io/manage_plugins.py", line 91, in reset_plugins
_load_preferred_plugins()
File "/usr/local/lib/python2.7/dist-packages/skimage/io/manage_plugins.py", line 71, in _load_preferred_plugins
_set_plugin(p_type, preferred_plugins['all'])
File "/usr/local/lib/python2.7/dist-packages/skimage/io/manage_plugins.py", line 83, in _set_plugin
use_plugin(plugin, kind=plugin_type)
File "/usr/local/lib/python2.7/dist-packages/skimage/io/manage_plugins.py", line 253, in use_plugin
_load(name)
File "/usr/local/lib/python2.7/dist-packages/skimage/io/manage_plugins.py", line 297, in _load
fromlist=[modname])
File "/usr/local/lib/python2.7/dist-packages/skimage/io/_plugins/matplotlib_plugin.py", line 1, in
import matplotlib.pyplot as plt
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 98, in
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/__init__.py", line 28, in pylab_setup
globals(),locals(),[backend_name],0)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 7, in
import backend_gtk3
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_gtk3.py", line 49, in
cursors.MOVE : Gdk.Cursor.new(Gdk.CursorType.FLEUR),
TypeError: constructor returned NULL

Most helpful comment

For me it seems to be matplotlib that causes this. If you want to run totally headless at the top of your script you can also try:

import matplotlib 
matplotlib.use('Agg') 

Which will tell matplotlib not to try to load up GTK.

All 16 comments

It is a downstream problem of matplotlib not being able to find display. What is the output if you run "echo $DISPLAY"?

Usually, running ssh with an X session (using ssh -X) will solve that problem.

On Mac with ssh -X, I can run the script for a while (about 10-20 min), after that the above error occurs again and I have to start a new session...
"echo $DISPLAY" outputs "localhost:11.0".

I was having this same issue. As @Yangqing suggested, running ssh -X will fix the problem. I'm using an OSX machine. The easiest way to do this is

  1. Launch XQuartz on your Mac.
  2. In iTerm (or any terminal program, not just the XQuartz terminal) export DISPLAY=:0. (Verify this worked by typing xcalc)
  3. ssh -X ... into the machine running caffe.

Keeping an X session open is a little bit tricky indeed. If you have a reasonably fast network, try starting a VNC or NX server and then connect with GUI - that usually handles things better. Or, use an ipython notebook on the server, allow remote connection to the notebook, and work from there.

If you are on Mac, add this "ForwardX11Timeout 596h" to the file /etc/ssh_config. Hope this helps.

For me it seems to be matplotlib that causes this. If you want to run totally headless at the top of your script you can also try:

import matplotlib 
matplotlib.use('Agg') 

Which will tell matplotlib not to try to load up GTK.

Thanks @jashmenn - your solution works perfectly.

Thanks @jashmenn !
Now it works +1

Now I could login through ssh and my issue is solved!
These are the steps I have followed
username@local:~# sudo -s
root@local:~# ssh -X -v -i /home/username/Downloads/keypair.pem [email protected]
ubuntu@amazon:~# sudo -s
root@amazon:~# nohup ./digits-devserver &

Now, access the site and create the dataset!

In similar spirit to @jashmenn, it is possible to specify this at runtime or set an environment variable:
MPLBACKEND=Agg python your_script.py

sudo pip uninstall matplotlib
sudo apt-get install python-matplotlib

use python-matplotlib can solve the problom.

I was having that problem on my Raspberry Pi and using what @LaurenLuoYun said solved my problem.
Thank you!

I had the same problem, and to me the solution was:
env MPLBACKEND=Agg python testing.py ...

@unifiDa It is a nice solution. Thanks!

tell matplotlib not to try to load up GTK.

Solved my problems. Thanks @jashmenn

Solution to 'GDK_IS_DISPLAY (display)' failed

It seems that the error is a minor error during the ssh connection from a computer to another computer. While I run the test application of class_activation_maps.py (keras examples), it shows the same error.

$ python3 class_activation_maps.py /home/nvidia/Downloads/galaxy.jpg
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused

(image_ocr.py:1257): Gdk-CRITICAL **: 19:44:35.690: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed

Using TensorFlow backend.
.........

However, while I run the following both the commands and the application. It can successfully show the splendid galaxy makeup.

$ echo $DISPLAY
:0
$ python3 class_activation_maps.py /home/nvidia/Downloads/galaxy.jpg

Using TensorFlow backend.
2020-05-01 19:45:14.877288: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.0

Notes:

Another solution is to describe the above-metioned commands in bashrc.

Cheers,

Mike

Was this page helpful?
0 / 5 - 0 ratings