autonomio / talos

Hyperparameter Experiments with TensorFlow and Keras
https://autonom.io
MIT License
1.62k stars 268 forks source link

"TypeError: constructor returned NULL" on Raspberry pi #393

Closed freezly closed 5 years ago

freezly commented 5 years ago

1) Confirm the below

2) Include the output of:

talos.__version__ not possible, because of import issue. pip3 list gives me: talos (0.6.3)

3) Explain clearly what you expect to happen

Running talos via ssh or cronjob on a UI-less linux server and raspberry pi's

4) Explain what actually happened

My code runs fine under Kubuntu 18.04. I want to run the same code and model on a raspberry pi and I'm connected via SSH. On Raspi I get an error as soon "import talos as ta" is called:

`Unable to init server: Could not connect: Connection refused Unable to init server: Verbindung ist gescheitert:Connection refused

(predictor.py:18596): Gdk-CRITICAL **: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed Traceback (most recent call last): File "/home/pi/git/repo/predictor.py", line 2, in import talos as ta File "/home/pi/.local/lib/python3.5/site-packages/talos/init.py", line 14, in from . import utils File "/home/pi/.local/lib/python3.5/site-packages/talos/utils/init.py", line 3, in from kerasplotlib import TrainingLog as live File "/home/pi/.local/lib/python3.5/site-packages/kerasplotlib/init.py", line 1, in from kerasplotlib.traininglog import TrainingLog File "/home/pi/.local/lib/python3.5/site-packages/kerasplotlib/traininglog.py", line 5, in import matplotlib.pyplot as plt File "/home/pi/.local/lib/python3.5/site-packages/matplotlib/pyplot.py", line 115, in _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup() File "/home/pi/.local/lib/python3.5/site-packages/matplotlib/backends/init.py", line 62, in pylab_setup [backend_name], 0) File "/home/pi/.local/lib/python3.5/site-packages/matplotlib/backends/backend_gtk3agg.py", line 9, in from . import backend_agg, backend_gtk3 File "/home/pi/.local/lib/python3.5/site-packages/matplotlib/backends/backend_gtk3.py", line 32, in cursors.MOVE : Gdk.Cursor.new(Gdk.CursorType.FLEUR), TypeError: constructor returned NULL`

Seems this is a problem like this: https://stackoverflow.com/questions/31328436/typeerror-constructor-returned-null-while-importing-pyplot-in-ssh

Is talos build to run on servers or only on PC's with an UI?

5) Provide a code-complete reference

  1. run on raspberry pi: python3
  2. send to python console: import talos as ta
  3. Error happens

NOTE: If the data is sensitive and can't be shared, create dummy data that mimics it.

A self-contained Jupyter Notebook, Google Colab, or similar is highly preferred and will speed up helping you with your issue.


mikkokotila commented 5 years ago

Check out the these lines from .travis.yml. I think it will help you resolve this issue. Let me know how it goes.

I'm also interested to know what you are working on with Pi, if you don't mind sharing.

Because travis is also server environment, and Talos pass there, there is definitely no issue with Talos running in GUI-less environment.

freezly commented 5 years ago

Thx for quick reply. I want to learn how I can bring models in production and talos seems to be perfect ... first parameter optimiziation and after that deploy the new model. I hope I can use talos later in real projects ... the work with talos feels pretty good.

So ... you are right: on an ubuntu test server the import command is working ... without your tip with travis.yml.

But for the PI your tip does'nt work for me. I run the export command and the same error occures. xvfb is not available on Pi. I know ... it is not a talos problem ... but: do you have any further ideas?

mikkokotila commented 5 years ago

Can you share the exact error message you are getting on Pi.

freezly commented 5 years ago

The error message which I posted above is exactly what I get. I have no more than that.

I found a workaround:

if 'DISPLAY' not in os.environ: matplotlib.use('Pdf')

does the magic avoiding the gtk stuff.

Found on: https://stackoverflow.com/questions/31328436/typeerror-constructor-returned-null-while-importing-pyplot-in-ssh

mikkokotila commented 5 years ago

os.environ["DISPLAY"] does not return anything in osx, so I assume similar case will happen in some other distros as well. Closing this as resolving it would go quite far from the focus of Talos. Good that you found a workaround.

This does raise an important question that have been lurking there all the while; does it really make sense to carry over all the baggage from matplotlib to Talos. Answer is that probably not.