ImportError: cannot import name 'keras_tensor' from 'tensorflow.python.keras.engine when i am doing import tensorflow_addons as tfa - tensorflow

when i am installing tensorflow- addons using below code
pip install tensorflow-addons
then it shows
requirement already satisfied as tensorflow flow version 2.10.0
when i am running this command which is shown below
import tensorflow_addons as tfa
it show the error shown below hw to resolve this error
C:\Users\AKANKSHA BALI\Anaconda3\lib\site-packages\tensorflow_addons\utils\ensure_tf_install.py:67: UserWarning: Tensorflow Addons supports using Python ops for all Tensorflow versions above or equal to 2.3.0 and strictly below 2.5.0 (nightly versions are not supported).
The versions of TensorFlow you are currently using is 1.15.0 and is not supported.
Some things might work, some things might not.
If you were to encounter a bug, do not file an issue.
If you want to make sure you're using a tested and supported configuration, either change the TensorFlow version or the TensorFlow Addons's version.
You can find the compatibility matrix in TensorFlow Addon's readme:
https://github.com/tensorflow/addons
UserWarning,
Traceback (most recent call last):
File "<ipython-input-2-8e92e93ce06e>", line 1, in <module>
import tensorflow_addons as tfa
File "C:\Users\AKANKSHA BALI\Anaconda3\lib\site-packages\tensorflow_addons\__init__.py", line 21, in <module>
from tensorflow_addons import activations
File "C:\Users\AKANKSHA BALI\Anaconda3\lib\site-packages\tensorflow_addons\activations\__init__.py", line 17, in <module>
from tensorflow_addons.activations.gelu import gelu
File "C:\Users\AKANKSHA BALI\Anaconda3\lib\site-packages\tensorflow_addons\activations\gelu.py", line 20, in <module>
from tensorflow_addons.utils import types
File "C:\Users\AKANKSHA BALI\Anaconda3\lib\site-packages\tensorflow_addons\utils\types.py", line 23, in <module>
from tensorflow.python.keras.engine import keras_tensor
ImportError: cannot import name 'keras_tensor' from 'tensorflow.python.keras.engine' (C:\Users\AKANKSHA BALI\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\__init__.py)

Related

Tensorflow.io module is missing - how do I get gfile?

I'm trying to use the tensorflow.io.gfile module to load an inference graph. When I try to import the gfile module, so I can get to the GFile class, I get the following results:
>>> import tensorflow
>>> from tensorflow.io import gfile
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow.io'
No module named 'tensorflow.io'
>>> tensorflow.__version__
'2.0.0'
I'm on MacOS Catalina with Python 3.7.4.
How can I successfully import sub-modules of tensorflow.io if it's missing?
https://www.tensorflow.org/api_docs/python/tf/io/gfile/GFile
pip install tensorflow.io
Should solve the problem.
The answer relies on the assumption that you are using TF2.0, in which this functionality has been moved to a separate package.

No module named 'tensorflow.contrib' while importing tflearn

While I was importing tflearn I'm getting this error:-
import tflearn
Traceback (most recent call last):
File "", line 1, in
File "/Users/rohansethi/anaconda3/lib/python3.7/site-packages/tflearn/init.py", line 4, in
from . import config
File "/Users/rohansethi/anaconda3/lib/python3.7/site-packages/tflearn/config.py", line 5, in
from .variables import variable
File "/Users/rohansethi/anaconda3/lib/python3.7/site-packages/tflearn/variables.py", line 7, in
from tensorflow.contrib.framework.python.ops import add_arg_scope as contrib_add_arg_scope
ModuleNotFoundError: No module named 'tensorflow.contrib'
You need to use an older version of TensorFlow.
tensorflow.contrib
Was removed from tensorflow with versions >=1.14.
This is what you can do:
pip uninstall tensorflow
pip install tensorflow==1.14
To check if everything is working fine:
Start python in the console by typing python Then:
import tensorflow
tensorflow.__version__
It should show you 1.14.
Now you can run your program.

ImportError: cannot import name 'abs' from tensorflow.python.keras._impl.keras.backend

Current Version Stacks:
python 3.5
tensorflow 1.14.0
tensorflow-estimator 1.14.0
tensorflow-gpu 1.14.0
tensorflow-tensorboard 0.1.8
protobuf 3.9.1
Keras 2.2.4
Keras-Applications 1.0.7
Keras-Preprocessing 1.0.9
Drivers & Machine:
Ubuntu 16.04 , NVIDIA-SMI 396.54 , CUDA - 9.0 , CuDnn 7 , libcudnn - 7.4.1
Summary-
Not able to import abs from tensorflow.python.keras._impl.keras.backend on
tensorflow-gpu == 1.14.0
And Not able to get CheckpointableBase attribute on tensorflow-gpu == 1.8.0
Which tensorflow-gpu and keras version supports both CheckpointableBase attribute and 'abs' from tensorflow.python.keras._impl.keras.backend ?
Details -
I'm currently training matterport mask rcnn with Keras==2.2.4. According to some threads in order to get abs I have tried updating tensorflow-gpu to 1.8.0 , updating protobuf. Although I was then able to import abs, but end up reciveing " AttributeError: module 'tensorflow.python.training.checkpointable' has no attribute 'CheckpointableBase' " on tensorflow-gpu to 1.8.0. Then in order to get CheckpointableBase some threads pointed to again update tensorflow-gpu == 1.14.0.
Traceback :
Traceback (most recent call last):
File "/home/kalpit/Desktop/palash/m-rcnn-traning/data/libraries/bacteria_rcnn_train.py", line 53, in <module>
import keras
File "/usr/local/lib/python3.5/dist-packages/keras/__init__.py", line 3, in <module>
from . import utils
File "/usr/local/lib/python3.5/dist-packages/keras/utils/__init__.py", line 6, in <module>
from . import conv_utils
File "/usr/local/lib/python3.5/dist-packages/keras/utils/conv_utils.py", line 9, in <module>
from .. import backend as K
File "/usr/local/lib/python3.5/dist-packages/keras/backend/__init__.py", line 84, in <module>
from .tensorflow_backend import *
File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 5, in <module>
import tensorflow as tf
File "/usr/local/lib/python3.5/dist-packages/tensorflow/__init__.py", line 28, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/__init__.py", line 83, in <module>
from tensorflow.python import keras
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras/__init__.py", line 26, in <module>
from tensorflow.python.keras import activations
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras/activations/__init__.py", line 22, in <module>
from tensorflow.python.keras._impl.keras.activations import elu
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras/_impl/keras/__init__.py", line 21, in <module>
from tensorflow.python.keras._impl.keras import activations
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras/_impl/keras/activations.py", line 23, in <module>
from tensorflow.python.keras._impl.keras import backend as K
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras/_impl/keras/backend.py", line 38, in <module>
from tensorflow.python.layers import base as tf_base_layers
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/layers/base.py", line 25, in <module>
from tensorflow.python.keras import backend
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras/backend/__init__.py", line 22, in <module>
from tensorflow.python.keras._impl.keras.backend import abs
ImportError: cannot import name 'abs'
Hi,
I was able to resolve this issue by removing all the tensorFlow and keras python3 packages from dist-packages dir itself , uninstalling using pip3 and then again installing tensorflow==1.8.0
tensorflow-gpu==1.8.0 , Keras==2.2.4
( The Potential reason which caused this specific erro was python referring multiple tensoflow-gpu,keras version packages files in dis-packages dir. Although installing a specific tensoflow-gpu,keras version via pip3 should ideally remove previous existing versions. But In my case that didn't occurred.)
Solution:
Locate tensorflow , keras packages in dist-packages dir using $ locate --basename '\tensorflow' command (provided you are using Ubuntu). In my case it is
$ locate --basename '\tensorflow'
outputs -
/usr/local/lib/python3.5/dist-packages/tensorflow
/usr/local/lib/python3.5/dist-packages/tensorflow/include/tensorflow
/usr/share/nginx/html/projects/python/machine-learning/objectDetection/models-master/research/syntaxnet/tensorflow
&
$ locate --basename '\keras'
outputs-
/usr/local/lib/python3.5/dist-packages/keras
/usr/local/lib/python3.5/dist-packages/tensorflow/keras
/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/keras
/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/keras/api/keras
/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras
/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras/_impl/keras
/usr/local/lib/python3.5/dist-packages/tensorflow/tools/api/generator/api/keras
/usr/share/nginx/html/projects/python/Playground/lambda/testkeras/keras
Now that you are aware of the desired packages location. Simply remove the tensorflow and keras dir's and uninstall packages using below commands
Removing dir's
sudo rm -R /usr/local/lib/python3.5/dist-packages/tensorflow/
sudo rm -R /usr/share/nginx/html/projects/python/machine-learning/objectDetection/models-master/research/syntaxnet/tensorflow
sudo rm -R /usr/local/lib/python3.5/dist-packages/keras/
sudo rm -R /usr/share/nginx/html/projects/python/Playground/lambda/testkeras/keras
Uninstall using pip3
sudo pip3 uninstall tensorflow
sudo pip3 uninstall tensorflow-gpu
sudo pip3 uninstall keras
Again Installing tensorflow, tensorflow-gpu ,keras
sudo pip3 install tensorflow==1.8.0
sudo pip3 install tensorflow-gpu==1.8.0
sudo pip3 install Keras==2.2.4

Tensorflow Image Retraining Tutorial Bazel Error

I am following the Tensorflow image retraining tutorial located here.
When I try to run this command using bazel:
bazel-bin/tensorflow/examples/image_retraining/retrain --image_dir ~/flower_photos
I get the following error:
Traceback (most recent call last):
File "/home/j/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/examples/image_retraining/retrain.py", line 108, in <module>
import tensorflow as tf
File "/home/j/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/j/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/__init__.py", line 63, in <module>
from tensorflow.python.framework.framework_lib import *
File "/home/j/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/framework/framework_lib.py", line 76, in <module>
from tensorflow.python.framework.ops import Graph
File "/home/j/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/framework/ops.py", line 28, in <module>
from autograd import core as ag_core
ModuleNotFoundError: No module named 'autograd'
However, when I run it using the python command
python tensorflow/examples/image_retraining/retrain.py --image_dir ~/flower_photos
It runs correctly and does not generate this error.
I am running both of the above commands from the ~/tensorflow directory (the top of the git repo)
Environment:
Ubuntu 17.04
Python 3.6.1
Anaconda 4.4.0
Bazel 0.5.4
Tensorflow 1.3 (no GPU) (v1.3.0-rc2-20-g0787eee 1.3.0)
I solved this issue. The autograd dependency was not installed. This can be solved by running pip install autograd
You have to configure TensorFlow before compiling, so it set up all the dependencies: ./configure

Numpy Install Mac Osx Python

I am using Python for my Linear Algebra course for programming. For the tools we need, I am trying to install NumPy. I used this website to guide me through the installation process.
I started from the links on SciPy's OS X page and eventually arrived at the SourceForge download site.
From there, I chose the Mac OS X installer numpy-1.6.1-py2.7-python.org-macosx10.3.dmg.
When I went to Idle and typed in
>>> import numpy as np
This is the error I received:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/__init__.py", line 5, in <module>
import multiarray
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so: no matching architecture in universal wrapper
I also tried it from the terminal and got the same error. I have a virtual environment installed - virtual env wrapper. I called the environment in the terminal by:
source my_new_env/bin/activate
And then I tried to import numpy in the terminal that way, but then I got the error:
(my_new_env) $ sudo python -c 'import numpy; numpy.test()'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named numpy
I am not sure if I installed NumPy incorrectly or if my virtual environment is conflicting with Nose. If anyone has suggestions let me know!
i would skip the MacOS package install and use the 'pip install' instructions, since you're already familiar with virtualenvs. use these instructions instead: http://www.scipy.org/install.html#installing-via-pip
it's easier to work with a virtualenv and pip, which will ensure post-install that your virtualenv will have access to the modules you've installed. it takes more work to do that with an external package (or .dmg) that you've downloaded. not impossible, just more work. HTH.
Try these commands:
brew update, brew doctor
, because, in my case, I didn't even have to install numpy separately. Yet I could import numpy easily. Meanwhile you can try downloading the numpy package from this website.