keras backend theano/tensorflow - python

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.

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.

Related

Tensorflow-GPU not using GPU with CUDA,CUDNN

I want to use Tensorflow on GPU. So I install all the needed tool and installed as below-
CUDA-11.2
CUDNN-11.1
Anaconda-2020.11
Tensorflow-GPU-2.3.0
I tested that my cuda,cudnn is working using deviseQuery example.
But Tensorflow not used GPU. Then i find that version compatibility issue is possible so i innstalled CudaToolkit,cudnn using conda environment checking with version compatibility on Tensorflow website which is given below.
CUDA-10.2.89
CUDNN-7.6.5
Tensorflow-GPU-2.3.0
But after this try Tensorflow-GPU not used GPU,yet. so what i am doing now? Any steps or suggestion require.
The installation engine has a problem for tensorflow-gpu 2.3 in Anaconda on Windows 10.
Workaround is to explicitly specify the correct tensorflow build:
conda install tensorflow-gpu=2.3 tensorflow=2.3=mkl_py38h1fcfbd6_0

Tensorflow - The kernel appears to have died. It will restart automatically

I am reading "Hands-On Machine Learning with Scikit-Learn, Keras and Tensorflow" and installed Tensorflow 2 as follows:
$ python3 -m pip install --upgrade tensorflow
In the jupyter notebook I tried to import Tensorflow as follows:
import tensorflow as tf
But then I get the following error message:
The kernel appears to have died. It will restart automatically
I know there is a bunch of StackOverflow threads about this topic. I have read them all. Some of them are old, some are new. Most of them suggest to downgrade the Tensorflow version to 1.5. But when I do that I can not use some of the methods of the Keras API (e.g. load_data() could not be found).
Is there anyone who have found a solution for that?
The second version of the textbook is all about TensorFlow version 2 so you have to use TensorFlow version 2 to use code. if there is a problem get the first version of the textbook which uses TensorFlow 1.
But I suggest learning TensorFlow 2 as it is the latest version.
if you are using anaconda Try installing TensorFlow 2 in a new environment.
To create a new environment open anaconda prompt.
conda create -n envname python=3.6
and then activate the environment
activate envname
Now try installing TensorFlow 2 and other necessary modules
and check.
If it does not work the best solution is to use google colab(colab.research.google.com/).where you can do everything online, you can even have free GPU.

no module named keras after installing keras

I'm using anaconda ver 3, and I have installed python as well separately from anaconda. I installed python ver 2.7 and ver 3.6 from python website.
Now, I have installed keras from anaconda command prompt by using conda install keras. However, when I open jupyter notebook and write :
import keras
it says :
no module named keras
I also tried importing tensorflow but it gave me the same error
As far as i know, keras is a version of tensorflow. You should try installing tensorflow instead and then run
import tensorflow as tf
tf.__version__
if you get '2.1.0' or any 2., you should be all set!
EDIT1: Keras is part of tensorflow not a version (as pointed out in the comments).
EDIT2: The link below gives good details on environments activation/creation.
https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
Okay so what I did is first updated anaconda by using :
conda update conda
and then I installed python :
conda install python=3.7
and finally I installed keras again :
conda install keras
And now I can import both packages of keras and tenserflow

How to "downgrade" a Keras/Tensorflow model so older code can work with it

I'm quite new to Keras and Tensorflow, and I'd like to export my model to Javascript to be able to run it in a web browser. This worked great with WebDNN a year ago.
Today I updated my Tensorflow installation and ran the whole model again. Unfortunately, I'm now getting the error
NotImplementedError: WebDNN supports TensorFlow >=v1.2.0,<=v1.4.0 Currently, TensorFlow 1.13.1 is installed.
How can I "downgrade" my model data to the Tensorflow 1.4.0 format so that it runs with WebDNN?
Should I create a new Anaconda environment, install Tensorflow 1.4.0 there, and move the model weights to that environment? Or should I try to adapt the code of WebDNN so that it works with TensorFlow 1.13?
You can try pip uninstall tensorflow and then pip install tensorflow-gpu==1.4.0.
It is good practice to install your dependencies in separate environments, to avoid global pollution.

Error installing Tensorflow in Windows 7

I am trying to install Tensorflow on a Windows 7 laptop in order to use jupyter notebook to play around with the object detection notebook in Github. I am facing this error:
ImportError Traceback (most recent call
last) in ()
4 import sys
5 import tarfile
----> 6 import tensorflow as tf
7 import zipfile
8
ImportError: No module named tensorflow
I am getting the above error when I start the Jupyter Notebook from inside the Conda environment in Windows 7. I have installed Python 3.5.4 & within conda environment, tensorflow as well.
I am also getting ... not recognized as an internal/external... for $ command while giving $ python and sometimes also for pip3 I have included several file paths in Environment Variables. Can you please suggest me what to do. I am using the Conda env as I feel I have a problem in having Windows Service Pack 1.
Make sure your Tensorflow folder is somewhere that the environment will look, such as [Python install directory]/Lib/Site-packages
If you are using Anaconda to manage your installation, be aware that it is community supported and not officially supported by Google. Google has a detailed guide on how to install Tensorflow on Windows as well as how to validate the installation. Follow their steps carefully and be aware you may need to start the process over if you miss a step.
1) Make sure you start with a clean Conda Environment for Tensorflow. You will need to specifiy Python version 3.5. You can do this by running the command,
C:> conda create -n tensorflow python=3.5
2) Once the new Conda environmnet is created, activate it. This step is commonly overlooked.
C:> activate tensorflow
(tensorflow)C:> # The Conda environment may appear before the drive letter
3) With the Tensorflow environment active, issue the pip command to install the appropriate Tensorflow version. To keep things simple, I assume you will be installing the CPU version. If you need the GPU version, refer to the Google guide since there are other things you will need to do in order to set up the NVIDIA drivers.
(tensorflow)C:> pip install --ignore-installed --upgrade tensorflow
Note the flags included on the pip install command.
To make sure that Tensorflow is installed properly, validate the installation. Do this by double checking that the Tensorflow Conda environment is active and starting a python console. Once the console is running type the following sample program, suggested by Google's guide.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
If you are new to Tensorflow, this code may not make sense. What it does is import the Tensorflow library, assign a variable called "hello" to a Tensorflow constant tensor. Tensorflow is a library designed to operate on Tensor data objects. The next line initiates a Tensorflow session which loads all the data objects. The final line prints the output of Session.run() on the hello constant object. If everything is set up correctly you should see
Hello, TensorFlow!
output on the console. If you don't, check to common installation issues included in Google's Tensorflow install guide.

Categories

Resources