ImportError: cannot import name 'abs'

元气小坏坏 提交于 2019-11-30 08:27:08

问题


I got problem while doing object detection using tensorflow-gpu

I was follwing the youtube tutorials :https://www.youtube.com/watch?v=Rgpfk6eYxJA

I'm trying to detect object using tensorflow-gpu with virtual environment.

I added python, cuda, tensorflow to system environment variables, and also did make training models with labels.

I converted xml labels to csv using xml_to_csv.py.

The problem is when I try to generate tfrecord using generate_tfrecord.py, that error appear. Please help

Here's the code

(tensorflow) C:\Users\ice305\tensorflow\models\research\object_detection>python generate_tfrecord.py --csv_input=images\train_labels.csv --image_dir=images\train --output_path=train.record
Traceback (most recent call last):
  File "generate_tfrecord.py", line 17, in <module>
    import tensorflow as tf
  File "C:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\__init__.py", line 22, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "C:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\__init__.py", line 81, in <module>
    from tensorflow.python import keras
  File "C:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\keras\__init__.py", line 24, in <module>
    from tensorflow.python.keras import activations
  File "C:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\keras\activations\__init__.py", line 22, in <module>
    from tensorflow.python.keras._impl.keras.activations import elu
  File "C:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\keras\_impl\keras\__init__.py", line 21, in <module>
    from tensorflow.python.keras._impl.keras import activations
  File "C:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\keras\_impl\keras\activations.py", line 23, in <module>
from tensorflow.python.keras._impl.keras import backend as K
  File "C:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\keras\_impl\keras\backend.py", line 38, in <module>
    from tensorflow.python.layers import base as tf_base_layers
  File "C:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\layers\base.py", line 25, in <module>
    from tensorflow.python.keras.engine import base_layer
  File "C:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\keras\engine\__init__.py", line 21, in <module>
    from tensorflow.python.keras.engine.base_layer import InputSpec
  File "C:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 33, in <module>
    from tensorflow.python.keras import backend
  File "C:\Anaconda3\envs\tensorflow\lib\site-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'
(tensorflow) C:\Users\ice305\tensorflow\models\research\object_detection>

I don't understand what 'abs' is. Please help


回答1:


This worked for me in ubuntu 18.0.4

pip uninstall tensorflow protobuf --yes
find $CONDA_PREFIX -name "tensorflow" | xargs -Ipkg rm -rfv pkg
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.9.0-cp36-cp36m-linux_x86_64.whl --no-cache-dir

Solution found from GitHub: ImportError: cannot import name 'abs' #20778.




回答2:


OS : Ubuntu 18.04.1

Python Version 3.6

Solution :

Uninstalled tensorflow 1.10

python3 -m pip uninstall tensorflow

Re-installed it again

python3 -m pip install tensorflow==1.8.0

This issue is created cause of older versions of tensorflow dependencies like protobuff and others which gets installed during tensorflow installation, So if you wanna use tensorflow 1.10 you have to uninstall rest of the dependencies or upgrade them.

In case you want to install 1.10.1 then you have to remove these packages

absl-py
astor
gast 
grpcio 
markdown 
numpy 
protobuf 
setuptools 
six 
tensorboard 
tensorflow 
termcolor 
werkzeug 
wheel
protobuf

then do sudo python3 -m pip uninstall tensorflow In case a tensorflow is installed in root user then install it using python3 -m pip install tensorflow --user --no-cache

IF you still face this problem then repeat all the steps above and do find ~/ -name tensorflow and delete every folder that pops up and retry installation.




回答3:


It seems to be a problem if there is a previous installation of tensorflow available. These steps seems to solve the problem.

1) uninstalling tensorflow 2) uninstalling protobuf 3) reinstalling tensorflow (which should come along with the correct protobuf version.

Also need to go to

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\Lib\site-packages

and delete all tensorflow related folders

Source : https://github.com/tensorflow/tensorflow/issues/20778




回答4:


If you use Win10+cuda_10.0+cuDNNv7.4.2.24, follow this will help you!

  1. uninstall all tensorflow and keras related.
  2. uninstall all protobuf related.
  3. delete tensorflow, keras, protobuf related folds in your 'Anaconda3_install_path'\Lib\site-packages, e.g.E:\ProgramData\Anaconda3\Lib\site-packages.
  4. install tensorflow and keras showed below in picture.



回答5:


I encountered the same error messages while trying seq2seq tutorial. I used tensorflow-cpu, python3.6, Anaconda3 and Ubuntu16.04.

The problem was that the path of tensorflow was not variable on my PC. I couldn't import tensorflow, though I could a few hours before. Try "import tensorflow" on python interactive shell. If you cannot import it, your problem would be the same as mine.

How to solve the problem was deleting everything about tensorflow on your computer and re-install them.

By the way, 'abs' is a function defined in the following file: ~/anaconda3/envs/tensorflow/lib/python3.6/site\ -packages/tensorflow/python/keras/_impl/keras/backend.py

And after re-installing tensorflow, I don't know why, "_impl" directory was disappeared.




回答6:


Suggested solution on the following link worked for me

https://github.com/tensorflow/tensorflow/issues/20778#issuecomment-410962482

The full solution to this issue is to clean up all TF installation files from your system. Here is how to do that. Run the following first:

$ pyhthon
> import tensorflow as tf
> tf.__file__
'path/to/your/python/installation/site-packages/tensorflow/__init__.pyc'

From the above command, you need to go and remove the folder

path/to/your/python/installation/site-packages/tensorflow

Finally, you need to run

$ pip uninstall tensorflow # Also add -gpu if you installed the GPU version
$ pip install tensorflow # Also add -gpu if you installed the GPU version

Then it should work.



回答7:


Had same problem in windows 10 when installing using anaconda Navigator and selecting all packages available for tensorflow and keras.

Solution was to clean up and install from command line, using "conda install" selecting only "gpu" packages:

conda remove keras*
conda remove tensorflow*
conda remove protobuf 
pip uninstall tensorflow*
pip uninstall protobuf
conda install tensorflow-gpu
conda install keras-gpu



回答8:


This is because that you have install some library and some dependencies of the tensorflow had changes by the installed library.

do the following command it will solve the problem

sudo pip install --upgrade tensorflow-gpu


来源:https://stackoverflow.com/questions/51299194/importerror-cannot-import-name-abs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!