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.
Related
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.
I am using colab to train a tensorflow model. I see that google colab installs the following version by default:
import tensorflow
tensorflow.__version__
2.6.0
...
[train model]
...
model.save('mymodel.h5')
However, when I download the model to my windows pc and try to load it with tensorflow/keras, I get an error
import keras
import tensorflow
model = keras.models.load_model(r"mymodel.h5")
model_config = json.loads(model_config.decode('utf-8'))
AttributeError: 'str' object has no attribute 'decode'
After searching on the net, it appears this is due to the different tensorflow versions (colab vs. my PC).
tensorflow.__version__
Out[4]: '2.1.0'
The problem is that when I install tensorflow with conda install tensorflow-gpu this is the version I get. Even trying to force conda install tensorflow-gpu==2.6 does not install anything.
What should I do?
Thanks!
hacky solution for now...
download tensorflow 2.1 + CUDA and CuDNN using conda install tensorflow-gpu
upgrade using pip install tensorflow-gpu==2.6 --upgrade --force-reinstall
The GPU does not work (likely because the CUDA versions are not the right ones) but at least I can run a tf 2.6 script using the CPU.
tensorflow version 2.3.1
numpy version 1.20
below the code
# define model
model = Sequential()
model.add(LSTM(50, activation='relu', input_shape=(n_steps, n_features)))
model.add(Dense(1))
model.compile(optimizer='adam', loss='mse')
we got
NotImplementedError: Cannot convert a symbolic Tensor
(lstm_2/strided_slice:0) to a numpy array. This error may indicate
that you're trying to pass a Tensor to a NumPy call, which is not
supported
it seems to me a crazy error!
I solved with numpy downgrade to 1.18.5
pip install -U numpy==1.18.5
If you are using anaconda:
conda install numpy=1.19
Similar issue, with
tensorflow 2.3.0
numpy 1.20.3
on Windows 7.
Solved by modifying tensorflow/python/framework/ops.py, replacing
def __array__(self):
raise NotImplementedError(
at line #845~846 with
def __array__(self):
raise TypeError(
.
Tensorflow 2.5 update:
tensorflow and tensorflow-gpu 2.5 packages still includes numpy-1.19.5 as a dependency.
The error referenced in this post will be reproduced if tensorflow 2.5 installation is mixed with numpy>1.19.5
tensorflow-2.5, numpy-1.19.5 are compatible with python-3.9
I had the same problem, solved it by downgrading python from 3.8 to 3.6
Same issue with tf 2.4.1, numpy 1.21, and python 3.9 .
Downgrading numpy to 1.19.2 with
conda install numpy==1.19.2
solved my problem.
I faced this issue with M1 chip. Here is the how I fixed:
conda create create --name tf
conda activate tf
conda install numpy ~=1.18.5
pip install tensorflow-macos
and voila you are ready to go !
I had the same issue with tensorflow 2.5.0 and numpy 1.21.2. There were suggestions here to make changes in array_ops.py file but this didn't work for me. Another answer in the same page with following steps worked.
pip uninstall tensorflow
pip install tensorflow
pip uninstall numpy
pip install numpy
Basically these steps don't downgrade numpy but either upgrades or keeps it at the same level. Above steps upgraded tensorflow 2.7.0 and numpy 1.21.4 and my code ran without any issues.
Here is the cell that needs to be run before starting the tutorial.
##test {"skip": true}
# tensorflow_federated_nightly also bring in tf_nightly, which
# can causes a duplicate tensorboard install, leading to errors.
!pip uninstall --yes tensorboard tb-nightly
!pip install --quiet --upgrade tensorflow_federated_nightly
!pip install --quiet --upgrade nest_asyncio
!pip install --quiet tb-nightly # or tensorboard, but not both
import nest_asyncio
nest_asyncio.apply()
It is giving out following errors:
ERROR: tensorflow 2.4.1 requires tensorboard~=2.4, which is not installed.
ERROR: tensorflow 2.4.1 has requirement gast==0.3.3, but you'll have gast 0.4.0 which is incompatible.
ERROR: tensorflow 2.4.1 has requirement grpcio~=1.32.0, but you'll have grpcio 1.34.1 which is incompatible.
ERROR: tensorflow 2.4.1 has requirement h5py~=2.10.0, but you'll have h5py 3.1.0 which is incompatible.
ERROR: datascience 0.10.6 has requirement folium==0.2.1, but you'll have folium 0.8.3 which is incompatible.
Need help resolving this. I am not much familiar with libraries and classes on Tensorflow.
Even though the console says there was an error, the pip packages should have been installed correctly.
This happens because the notebooks use tensorflow-federated-nightly, which depends on an installs tf-nightly overwriting the base tensorflow install. However pip still thinks the TFF dependencies will conflict with the now overwritten TensorFlow core package.
Adding tensorflow to the !pip uninstall list may make this error go away, but the functionality of the notebook won't change.
You can import tensorflow federated like the following. It solved my error. I tried to follow Federated Learning for Image Classification and while I was trying to import tensorflow_federated it was always giving me error.
from tensorflow_federated import python as tff
I had initially installed tf-nightly by mistake and later uninstalled it. Now, I have installed two different versions of tensorflow on two different conda environments (tf1.14-gpu and tf2.0-gpu). When I execute the command
conda list -n tf1.14-gpu tensorflow it shows the following output
# Name Version Build Channel
tensorflow 1.14.0 gpu_py36h3fb9ad6_0
tensorflow-base 1.14.0 gpu_py36he45bfe2_0
tensorflow-estimator 1.14.0 py_0
tensorflow-gpu 1.14.0 h0d30ee6_0
When I execute the command conda list -n tf2.0-gpu tensorflow it shows the following output
# Name Version Build Channel
tensorflow 2.1.0 gpu_py36h2e5cdaa_0
tensorflow-base 2.1.0 gpu_py36h6c5654b_0
tensorflow-estimator 2.1.0 pyhd54b08b_0
tensorflow-gpu 2.1.0 h0d30ee6_0
But in both the environments when i import tensorflow and check for its version, it gives the same output as '2.2.0-dev20200218' which I assume is the version for tensorflow nightly build. I am not able to use this version for my existing models. I tried uninstalling anaconda and reinstalling the two environments with tensorflow 1.14 and tensorflow 2.0, but it tensorflow version still shows the same as '2.2.0-dev20200218'. Any idea how to overcome this ?
I ran to the same problem. Could it be possible that you installed tf-nightly using pip and not Conda? But when you run import tensorflow as tf; print(tf.__version__)it picks up the global pip version which is troublesome to get rid of?
p.s. Sorry that I'm posting instead of commenting. Don't have 50 reputation points yet.