1
votes

I have an issue using keras backend. I set up tensorflow as the backend. I check the ./keras/keras.json, the activate.d and activate.sh to have tensorflow as backend. I also tried to force the envs variable to tensorflow.
The first time a run keras on the jupyter, it works fine. I can also import tensorflow without any bugs.

However when I use jupyter notebook now, the backend is theano.

I try to import keras on ipython and the backend is tensorflow.

I install keras, tensorflow and theano with conda.

python version : 3.6

keras : 2.0.6

tensorflow : 1.3.0

theano : 0.9

OS : win10

I try different ways to change the backend to tensorflow for jupyter notebook but it does not seem to work.

1
I faced a terrible bug with jupyter. I installed it before installing anaconda, and no matter what I did, jupyter was always pointing to the original python and never to the conda environments. In my case (A virtual machine), I gave up and created a new machine, installing jupyter only via conda and at the right environment.Daniel Möller
@DanielMöller, I actually installed jupyter with conda. I am now using ipython and will try to create a specific environment, as you mentioned.youpi
One possible way to kwnow which python you're using from jypiter is running import sys and print(sys.executable). This will tell you if jupyter is running the correct environment.Daniel Möller
Thank you for your help @DanielMöller! It points to Anaconda3/python.exe, which is the correct one. I change the init.py in Anaconda3/lib/site-packages/keras/backend , in the import backend functions line 80, I replace from .theano_backend import * to from .tensorflow_backend import *. It seems to do the trick.youpi
Nice hack :) -- Jupyter should be running somewhere in a folder called envs\yourenvironment for it to work properly without your hack.Daniel Möller

1 Answers

0
votes

Usually, with conda, we create specific environments that are (theoretically) independent from the others.

I suggest you create a tensorflow environment using conda. Using the command prompt:

conda create -n myTensorflowEnv python=3.5

And then you activate this environment:

activate myTensorflowEnv

The name of your environment should then appear in between parentheses at the beginning of the command prompt. (In case this doesn't work, you may need to setup some vars: How to activate an Anaconda environment)

Inside this environment, you install everything you need: Tensorflow, keras and other dependencies. This process will depend on what you want, though, cpu, gpu, compilations, etc.

You should probably install jupyter in this environment as well. (And perhaps -- only if you have the terrible bug I mentioned in my comment -- uninstall the other jupyters first).

If everything goes well, you will be able to use tensorflow in this environment if you run jupyter from this environment.