Forums

Get error when i load Tensorflow Keras model prediction

hello members why i get error when i load tensorflow model from my web site :

http://falahgs.pythonanywhere.com/

020-01-11 10:50:07 2020-01-11 10:49:59.404515: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): Host, Default Version
2020-01-11 10:50:07 /usr/lib/python3.7/site-packages/tensorflow_core/python/framework/indexed_slices.py:424: UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown shape. This may consume a large amount of memory.#012  "Converting sparse IndexedSlices to a dense Tensor of unknown shape. "
2020-01-11 10:50:07 xception_model: <keras.engine.training.Model object at 0x7fe3da71dfd0>
2020-01-11 10:50:07 WSGI app 0 (mountpoint='') ready in 11 seconds on interpreter 0x84e380 pid: 1 (default app)
2020-01-11 10:50:07 *** uWSGI is running in multiple interpreter mode ***
2020-01-11 10:50:07 gracefully (RE)spawned uWSGI master process (pid: 1)
2020-01-11 10:50:07 spawned uWSGI worker 1 (pid: 24, cores: 1)
2020-01-11 10:50:07 spawned 2 offload threads for uWSGI worker 1
2020-01-11 10:50:07 metrics collector thread started
2020-01-11 10:50:07 announcing my loyalty to the Emperor...
2020-01-11 10:51:40 filename: /home/falahgs/mysite/uploads/9F127C3.png
2020-01-11 10:51:40 file_path: /home/falahgs/mysite/uploads/3.png
2020-01-11 10:51:40 Begin Model Prediction...

[edit by admin: formatting]

Tensorflow doesn't work in website code on PythonAnywhere -- as you're using Keras, then you should be able to get it working by switching to the Keras backend.

@giles ... thanks for reply... did u mean to change keras.json file from { "floatx": "float32", "epsilon": 1e-07, "backend": "tensorflow", "image_data_format": "channels_last" } to { "floatx": "float32", "epsilon": 1e-07, "backend": "keras", "image_data_format": "channels_last" }

Oops, sorry, I mistyped in my last post. I should have said "switching to the theano backend". So you've found the right thing to change, but it should be "backend": "theano".

@giles thanks for help.. when i change keras.json to :

{ "image_dim_ordering": "th", "epsilon": 1e-07, "floatx": "float32", "backend": "theano" } also i get error message in error.log file

2020-01-13 17:17:38,915: Error running WSGI application 2020-01-13 17:17:38,918: ModuleNotFoundError: No module named 'theano' 2020-01-13 17:17:38,919: File "/var/www/falahgs_pythonanywhere_com_wsgi.py", line 16, in <module> 2020-01-13 17:17:38,919: from flask_app import app as application # noqa 2020-01-13 17:17:38,919:

how to install theano in pythonanywhere site hosting ...? or in my code setting to theano package ...?

thanks for help

Here you go: http://help.pythonanywhere.com/pages/InstallingNewModules/

I tried changing the backend to 'theano'. This does not solve the issue. There are no errors however, when it comes to prediction, it doesnt do anything.. It justs hangs on there. Any solutions please.. Is there a particular version of tensorflow that works? It works fine on the console though :( strange

Add some debugging code to see where it hangs.

I get the same error ...still the same error with tenserflow and theano...!!! i don't know why pythonanywhere dosen't work very well with tensetflow backend .

What error? There are a number of errors being discussed in this thread.

Till now all I know is if Keras is using Tensorflow as backend then, pythonanywhere crashes because tf tries to change the thread causing the app to crash.

Now, I tried changing to theano as suggested by pythonanywhere here. But, it does not work in local (with warning of missing c++, g++, mingw etc.). After installing these dependencies, it might work, but mingw requires conda & g++ requires apt-get which we cannot install in pythonanywhere.

I also tried using theano in server without mingw but it keeps loading as mentioned by @sathishs above.

There seems to be no solution here. I might probably change to other hosting services.

A question to everyone who's having these problems -- which version of Python are you using? And are you using the built-in version of Keras, or one that you have installed (for example into a virtualenv)?

@buildchange -- regarding C++, etc. -- those are all pre-installed on PythonAnywhere, as is Theano, so you would not need to install them on our servers.

Just to add to the above -- we've heard from some other users that the most recent version of Tensorflow seems to have fixed the behaviour that stopped it from working in website code on PythonAnywhere, but only in Python 3.7 -- 3.8 still doesn't work. So perhaps you could see what happens if you stick with TensorFlow but switch to 3.7 if that's not the version that you're already using?

I tried multiple version combinations, inside virtualenv and these seems to work:

  • python: 3.7.5
  • tensorflow: 2.1.0
  • keras: 2.3.1

I tested both tf.keras and keras. Both are working fine, but are a lot slower then local machine because pythonanywhere does not provide GPU. Better then crashing the whole thread I guess.

Side note, I bailed on Theano

That's really useful, thanks for letting us know! It sounds like we need to update our help page on running Keras code in websites.