Tensorflow works but Keras is failed - python

I have successfully install tensorflow-gpu and used it happily before,
but due to some reasons I didn't touch TF or Keras for a long time,
and then I got this error.
The error message is like this:
import keras
from keras.layers import Dense
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'keras.layers'
Note:
I used Anaconda to install this stuff.
But I'm sure it was not installed successfully
even if I checked the whether the package exists in anaconda prompt
However, when I tried to import tensorflow itself it is OK:
tf.__version__
'1.13.1'
The tensorflow is a gpu version.
These are the versions of the dependencies:
CUDA : 10.0
cudnn : 7.4
I have uninstall the tensorflow-gpu many times...
Can someone help? Thanks!

Latest version of Tensorflow ~ 2.6.0 has in built Keras api.
!pip install tensorflow
import tensorflow as tf
from tensorflow.keras.layers import Dense

Related

Tensorflow and Keras Installation Problems JupyterLab / Anaconda (Debian)

I've been trying to install keras and tensorflow for Jupyter-lab (python).
I first tried with pip, but the notebook stopped functioning everytime I imported keras.
After some research on different feeds, I decided to uninstall it with pip and try to reinstall it with anaconda3.
Then, there was a path issue installing tensorflow with the conda command. So I researched more and wrote this in the terminal :
export PATH="/home/myname/anaconda3/bin:$PATH"
I created another environment and could install tensorflow with (same for keras) :
conda activate myenv
conda install tensorflow
I came back on the local JupyterLab and imported keras. But it couldn't find the module named keras. I tried again with pip :
!pip install keras
import keras
And got the same :
Requirement already satisfied: keras in /home/myname/.conda/envs/myenv/lib/python3.9/site-packages (2.9.0)
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Input In [6], in <cell line: 10>()
---> 10 import keras
ModuleNotFoundError: No module named 'keras'
Is it a path problem ? How can I solve it ? I don't understand how it can find it, but not import it correctly.
Thank you for your help !
After creating the virtual environment(myenv) in conda, open a new jupyter notebook in the same environment and you need to install TensorFlow in that environmnet using the below code:
!pip install tensorflow
import tensorflow as tf
tf.__version__
Now you can access the Keras from TensorFlow as below:
from tensorflow import keras
keras.__version__

cannot import name 'normalization' from 'tensorflow.python.keras.layers'

I am trying to use tensorflow_rankings, but cannot import it due to the above error. I am using tensorflow 2.8.0 and tensorflow_rankings 0.5.0, which seem to be the latest stable builds. They are what get automatically installed from
pip install tensorflow
pip install tensorflow_ranking
I am on Python 3.8.10, Windows 11.
The TF 2.8.0 docs show there is a Normalization layer in tf.keras.layers. The error seems to come from:
from tensorflow.python.keras.layers import normalization as keras_norm
in
from tensorflow_estimator.python.estimator.canned.dnn import dnn_logit_fn_builder
Any advice?
Seems my installation of TF was corrupted. A full uninstall and reinstall fixed it.

ModuleNotFoundError : No module named 'tensorflow' on Windows 10 x64, Anaconda with spyder 4.0.1 and python 3.7

Solutions tried:
pip install tensorflow
pip show tensorflow --ignore_installed
pip install tensorflow==2.0.0-rc0
conda install -c conda-forge tensorflow
conda install tensorflow
pip3 show tensorflow
pip show tensorflow
Note: you may need to restart the kernel to use updated packages.
WARNING: Package(s) not found: tensorflow
Tried restarting kernel.
Tried restarting laptop
Code trying to run:
from keras.models import load_model
Error:
runcell(0, 'C:/Users/chinm/untitled1.py')
Traceback (most recent call last):
File "C:\Users\chinm\anaconda3\lib\site-packages\keras_init_.py", line 3, in
from tensorflow.keras.layers.experimental.preprocessing import RandomRotation
ModuleNotFoundError: No module named 'tensorflow'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\chinm\untitled1.py", line 14, in
from keras.models import load_model
File "C:\Users\chinm\anaconda3\lib\site-packages\keras_init_.py", line 6, in
'Keras requires TensorFlow 2.2 or higher. '
ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via pip install tensorflow
I can't see your code, but it appears your key error is Keras requires TensorFlow 2.2, while you installed pip install tensorflow==2.0.0-rc0. 2.0 < 2.2. Have you tried installing tensorflow 2.2 or up, or upgrading your existing version?
https://www.tensorflow.org/install/pip recommends:
pip install --upgrade tensorflow
with
python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
to verify the installation.

No module names 'Keras'

I am absolutely new to the development of deep learning and currently, I am just preparing my system to start with some basic tutorials.
I followed the Tutorial on this Blog to prepare the environment for the development of deep leaning projects.
I was successful to do the steps mentioned in the tutorial expect the last one. I Installed tensorflow-gpu using the command pip install tensorflow-gpu in the Python 3.7 Anaconda.
PROBLEM: As per the tutorial, I should try to execute the following commands to check if everything went OK with the installation:
>>> import tensorflow
>>> import keras
The first command was exectued without any issue but the second command (i.e. import keras) is throwing error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module names 'keras'
You installed tensorflow, thats why you can import keras from tensorflow
from tensorflow import keras
Or you install keras separately with:
pip install keras
and then import it with:
import keras
You can import keras by pip (command for use).
pip install keras
After completion of above command you can check whether Keras install or not in your system by
pip list | grep -i keras
Output on console
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
Keras (2.2.4)
Keras-Applications (1.0.7)
Keras-Preprocessing (1.0.9)

Cannot import multi_gpu_model from keras.utils

I have tensorflow-gpu 1.2.1 and keras on ubuntu 16.04.
I am not able to perform:
from kears.utils import multi_gpu_model
Has anyone had success with multi_gpu_model as described in their documentation's FAQ section?
I have a 4 GPU machine with 4 GeForce GTX 1080 Ti cards and want to use all of them.
Here's the error I get:
import keras.utils.multi_gpu_model
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-7-0174878249b1> in <module>()
----> 1 import keras.utils.multi_gpu_model
2
ModuleNotFoundError: No module named 'keras.utils.multi_gpu_model'
I can import keras and keras.utils successfully.
pip uninstall keras
pip install keras==2.2.4
this helped me ...
working on keras hrnetv2
for Tensorflow 2.7.0 this works:
from tensorflow.python.keras.utils.multi_gpu_utils import multi_gpu_model
This function was added on October 11, and there have been no Keras releases that include it. Currently the last Keras release is 2.0.8 released on Aug 25, 2017.
Your only options are to wait until a release is made, or to use a Keras
version directly from git master.
To close this issue: I installed the latest version of Keras from github and got the multi_gpu_model module working as expected.
pip install git+git://github.com/fchollet/keras.git --upgrade
You could reinstall tensorflow-estimator and keras like this:
pip uninstall tensorflow-estimator
pip install tensorflow-estimator
pip uninstall keras
pip install keras
I was able to resolve the issue by this.

Categories

Resources