Forums

Unable to change keras backend

I am using keras on my server to predict on images. I understand that tensorflow doesn't work with pythonanywhere and so I tried changing my keras backend to theano. I followed the discussion on https://www.pythonanywhere.com/forums/topic/12720/ and related threads.

This is what I tried:

  • Changed backend to 'theano' in keras.json
  • Downgraded keras to 2.3.1 (I used bash console and also verified that keras is downgraded by using pip show keras)
  • pip install theano (not needed but did it anyway)

  • Added the following lines in my app.py: import os; os.environ['KERAS_BACKEND'] = 'theano'

  • I wasn't able to downgrade tensorflow to 2.1.0 (I tried to do so because it was suggested in some thread)
  • Also downgraded python to 3.7

Despite all of this, when I run the following lines in my app.py

from keras import backend as K
import keras

print('Backend used: ', K.backend())
print('Version used: ', keras.__version__)

I get the keras version as 2.9.0 and backend as tensorflow. Please help

How are you running the code when you get the too-high value for the version of keras -- is it in a console? Or are you seeing that version in the website's server log?

nvm, I got it to work somehow. Opened a console in app.py file and repeated the pip steps. Probably that's how it worked. Anyways, I switched to pytorch now and it is less of a pain.

OK, glad to hear you got it to work!