What works in python 2.7 - dynamically changing Keras backend
# When I executed the suggestion -- the output I got..
BaseExceptionTraceback (most recent call last)
<ipython-input-7-c4352a2d60e6> in <module>()
      3 import keras; import keras.backend
      4 if keras.backend.backend() != 'theano':
----> 5     raise BaseException("This script uses other backend")
      6 else:
      7     keras.backend.set_image_dim_ordering('th')
BaseException: This script uses other backend
-- Not sure, how this would help if we are not able to dynamically change the backend.
-- Instead what helped me was the following:
How to switch Backend with Keras (from TensionFlow to Theano)
Code in iPython
from keras import backend; print(backend._BACKEND)
from keras import backend as K
import os
def set_keras_backend(backend):
    if K.backend() != backend:
        os.environ['KERAS_BACKEND'] = backend
        reload(K)
        assert K.backend() == backend
print ("Change Keras Backend to Theano")        
set_keras_backend("theano")  
from keras import backend; print(backend._BACKEND)
Output in iPython
tensorflow
Change Keras Backend to Theano
theano