Cannot import name 'tf2' - python

I created a v.environment where I have Python version 3.6.5 and there I installed tensorflow-gpu.
The version of TensorFlow is 1.4.0 and of Keras is 2.6.0.
When I write on the script import keras it appears the following Error:
ImportError: cannot import name 'tf2'
Have you any idea?

From comments
Here the problem caused by the TF is too old, and the keras is
too new. Your choice is to downgrade keras to 2.2.1, or use newer
version of tf (paraphrased by Vinson Ciawandy & homomathematicus)

Related

DLL load failed while importing _pywrap_quantize_training

Hi developers and programmers, I'm try to import keras module and it show error, please help, Thank you.
code
from keras.callbacks import EarlyStopping, ReduceLROnPlateau, ModelCheckpoint, TensorBoard
error
DLL load failed while importing _pywrap_quantize_training
I have try to reinstall keras and it show error below, im not is this causing the problem
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
tensorflow 2.10.0 requires keras<2.11,>=2.10.0, but you have keras 2.11.0 which is incompatible.tensorflow 2.10.0 requires tensorflow-estimator<2.11,>=2.10.0, but you have tensorflow-estimator 2.11.0 which is incompatible
im using vscode, xampp
I found the solution by myself, its the version compatible, i uninstall keras and tensorflow, then reinstall tensorflow by the version of 2.10 and it work

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.

Keras does not load because cannot find TensorFlow

Running Anaconda and installed:
Keras = 2.4.3
TensorFlow = 2.4.0
However, when importing Keras - I get "Keras requires TensorFlow 2.2 or higher".
Tried uninstalling/installing - did not help.
Any idea?
You can use
pip install --upgrade tensorflow
to install an upgraded and compatible TensorFlow version in your system.

Tensorflow works but Keras is failed

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

AttributeError: module 'tensorflow' has no attribute 'name_scope' with Keras

I am trying to run a script, but I struggle already at the imports.
This import
from keras.preprocessing.image import save_img
raises the following error:
AttributeError: module 'tensorflow' has no attribute 'name_scope'.
I am using the following packages.
Keras 2.2.2,
Keras-Applications 1.0.4,
Keras-Preprocessing 1.0.2,
tensorflow 1.9.0,
tensorflow-gpu 1.9.0
I was unable to reproduce with the same versions of the keras and tensorflow, reinstalling keras and tensorflow, may solve the issue, please use commands below:
pip install --upgrade pip setuptools wheel
pip install -I tensorflow
pip install -I keras
NOTE: The -I parameter stands for ignore installed package.
For everyone who use Tensorflow 2.0 and stumble upon this question with the same error, like I did: I solved it by changing the imports from keras.xxx to tensorflow.keras.xxx
I also encountered this same problem when I stopped my IDE while executing. Restarting my IDE works for me. Just save your program and restart IDE. Hope it will work for you as well.
As Andriy Ivaneyko mentioned above, reinstalling tensorflow helps. I'm not sure why, but installing tensorflow-serving-api breaks something somewhere along the way. We solved this by running:
pip install --force-reinstall tensorflow
Note that this applies to both tensorflow and tensorflow-gpu installations. Specifically, the above command will fix this problem in situations where you're specifically using tensorlfow-gpu. tensorflow-serving-api installs regular tensorflow if it's not already installed.
I encountered this same bug and reinstalling tensorflow made no difference, and this caused me some headscratching.
Eventually I noticed that my IDE autocomplete had added the following line to my code:
from tensorflow_core.python.keras.callbacks import EarlyStopping
It seems that directly referencing tensorflow_core.python will break tensorflow.
Replacing this with the normal tensorflow import solved the problem!
from tensorflow.keras.callbacks import EarlyStopping
My IDE offered me two different import paths
keras
or
tensorflow_core.python.keras
In my example I could either import like this:
from keras.layers import Dense, Dropout, LSTM, Input, Activation
from keras import optimizers, Model
or like that:
from tensorflow_core.python.keras import Input, Model, optimizers
from tensorflow_core.python.keras.layers import LSTM, Dropout, Dense
Mixing up tensorflow_core.python.keras and plain keras led to the problem in my case. After I imported everything directly from keras and keras.layers, it worked for me.
My tensorflow version is 2.1, and I found my tensorflow-estimator version is 2.2
My fix is to downgrade the estimator to the same version

Categories

Resources