gpt4 book ai didi

tensorflow - 导入错误 : cannot import name 'abs' from tensorflow. python.keras._impl.keras.backend

转载 作者:行者123 更新时间:2023-12-05 03:59:14 25 4
gpt4 key购买 nike

当前版本堆栈:

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

驱动程序和机器:

Ubuntu 16.04 , NVIDIA-SMI 396.54 , CUDA - 9.0 , CuDnn 7 , libcudnn - 7.4.1

总结-

无法从 tensorflow.python.keras._impl.keras.backend 上导入 abstensorflow-gpu == 1.14.0

并且无法在 tensorflow-gpu == 1.8.0 上获取 CheckpointableBase 属性

哪个 tensorflow-gpu 和 keras 版本同时支持 CheckpointableBase 属性和来自 tensorflow.python.keras._impl.keras.backend 的“abs”?

详细信息 -

我目前正在使用 Keras==2.2.4 训练 matterport mask rcnn。根据一些threads为了获得 abs 我尝试将 tensorflow-gpu 更新为 1.8.0 ,更新 protobuf。虽然我当时能够导入 abs,但最终在 tensorflow-gpu 上收到“AttributeError: module 'tensorflow.python.training.checkpointable' has no attribute 'CheckpointableBase'”到 1.8.0。然后为了获得 CheckpointableBase 一些指向的线程再次更新 tensorflow-gpu == 1.14.0。

回溯:

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'

最佳答案

你好,

我能够通过从 dist-packages 目录本身删除所有 tensorFlow 和 keras python3 包,使用 pip3 卸载然后再次安装 tensorflow==1.8.0 来解决这个问题
tensorflow-gpu==1.8.0 , Keras==2.2.4

( 导致此特定错误的潜在原因是 python 在 dis-packages 目录中引用了多个 tensoflow-gpu、keras 版本包文件。虽然通过 pip3 安装特定的 tensoflow-gpu、keras 版本应该理想地删除以前的现有版本。但是在我的情况下没有发生。)

解决方法:

  1. 使用 $ locate --basename '\tensorflow' 命令在 dist-packages 目录中找到 tensorflow 和 keras 包(前提是您使用的是 Ubuntu)。在我的例子中是

$ locate --basename '\tensorflow'

输出-

/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'

输出-

/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
  1. 现在您已知道所需的包位置。只需使用以下命令删除 tensorflow 和 keras 目录并卸载包

删除目录

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

使用pip3卸载

sudo pip3 uninstall tensorflow
sudo pip3 uninstall tensorflow-gpu
sudo pip3 uninstall keras
  1. 再次安装tensorflow、tensorflow-gpu、keras

    sudo pip3 install tensorflow==1.8.0
    sudo pip3 安装 tensorflow-gpu==1.8.0sudo pip3 install Keras==2.2.4

关于tensorflow - 导入错误 : cannot import name 'abs' from tensorflow. python.keras._impl.keras.backend,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57406870/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com