AttributeError:模块“ tensorflow”在conda提示符中没有属性“ keras” [英] AttributeError: module 'tensorflow' has no attribute 'keras' in conda prompt

查看:96
本文介绍了AttributeError:模块“ tensorflow”在conda提示符中没有属性“ keras”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

*我尝试安装tensorflow和keras

*I try to install tensorflow and keras

我安装了tensorflow并正确导入了

I installed tensorflow and I imported it with no errors

已经安装了keras,但是我无法导入它
*

Keras is installed but I can't import it *

(base) C:\Windows\system32>pip uninstall keras
Found existing installation: Keras 2.3.1
Uninstalling Keras-2.3.1:
  Would remove:
    c:\users\asus\anaconda3\anaconda\lib\site-packages\docs\*
    c:\users\asus\anaconda3\anaconda\lib\site-packages\keras-2.3.1.dist-info\*
    c:\users\asus\anaconda3\anaconda\lib\site-packages\keras\*
Proceed (y/n)? y
  Successfully uninstalled Keras-2.3.1

(base) C:\Windows\system32>pip install keras
Collecting keras
  Using cached Keras-2.3.1-py2.py3-none-any.whl (377 kB)
Requirement already satisfied: six>=1.9.0 in c:\users\asus\anaconda3\anaconda\lib\site-packages (from keras) (1.14.0)
Requirement already satisfied: numpy>=1.9.1 in c:\users\asus\anaconda3\anaconda\lib\site-packages (from keras) (1.18.4)
Requirement already satisfied: keras-applications>=1.0.6 in c:\users\asus\anaconda3\anaconda\lib\site-packages (from keras) (1.0.8)
Requirement already satisfied: keras-preprocessing>=1.0.5 in c:\users\asus\anaconda3\anaconda\lib\site-packages (from keras) (1.1.2)
Requirement already satisfied: scipy>=0.14 in c:\users\asus\anaconda3\anaconda\lib\site-packages (from keras) (1.4.1)
Requirement already satisfied: pyyaml in c:\users\asus\anaconda3\anaconda\lib\site-packages (from keras) (5.3.1)
Requirement already satisfied: h5py in c:\users\asus\anaconda3\anaconda\lib\site-packages (from keras) (2.10.0)
Installing collected packages: keras
Successfully installed keras-2.3.1

然后我尝试

(base) C:\Windows\system32>python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

>>> from keras.models import sequential
Using TensorFlow backend.
2020-05-21 10:03:38.204077: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-05-21 10:03:38.210602: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\ASUS\Anaconda3\Anaconda\lib\site-packages\keras\__init__.py", line 3, in <module>
    from . import utils
  File "C:\Users\ASUS\Anaconda3\Anaconda\lib\site-packages\keras\utils\__init__.py", line 26, in <module>
    from .vis_utils import model_to_dot
  File "C:\Users\ASUS\Anaconda3\Anaconda\lib\site-packages\keras\utils\vis_utils.py", line 7, in <module>
    from ..models import Model
  File "C:\Users\ASUS\Anaconda3\Anaconda\lib\site-packages\keras\models.py", line 10, in <module>
    from .engine.input_layer import Input
  File "C:\Users\ASUS\Anaconda3\Anaconda\lib\site-packages\keras\engine\__init__.py", line 8, in <module>
    from .training import Model
  File "C:\Users\ASUS\Anaconda3\Anaconda\lib\site-packages\keras\engine\training.py", line 14, in <module>
    from . import training_utils
  File "C:\Users\ASUS\Anaconda3\Anaconda\lib\site-packages\keras\engine\training_utils.py", line 17, in <module>
    from .. import metrics as metrics_module
  File "C:\Users\ASUS\Anaconda3\Anaconda\lib\site-packages\keras\metrics.py", line 1850, in <module>
    BaseMeanIoU = tf.keras.metrics.MeanIoU
AttributeError: module 'tensorflow' has no attribute 'keras'
>>> from keras.models import Sequential
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\ASUS\Anaconda3\Anaconda\lib\site-packages\keras\__init__.py", line 3, in <module>
    from . import utils
  File "C:\Users\ASUS\Anaconda3\Anaconda\lib\site-packages\keras\utils\__init__.py", line 26, in <module>
    from .vis_utils import model_to_dot
  File "C:\Users\ASUS\Anaconda3\Anaconda\lib\site-packages\keras\utils\vis_utils.py", line 7, in <module>
    from ..models import Model
  File "C:\Users\ASUS\Anaconda3\Anaconda\lib\site-packages\keras\models.py", line 12, in <module>
    from .engine.training import Model
  File "C:\Users\ASUS\Anaconda3\Anaconda\lib\site-packages\keras\engine\__init__.py", line 8, in <module>
    from .training import Model
  File "C:\Users\ASUS\Anaconda3\Anaconda\lib\site-packages\keras\engine\training.py", line 14, in <module>
    from . import training_utils
  File "C:\Users\ASUS\Anaconda3\Anaconda\lib\site-packages\keras\engine\training_utils.py", line 17, in <module>
    from .. import metrics as metrics_module
  File "C:\Users\ASUS\Anaconda3\Anaconda\lib\site-packages\keras\metrics.py", line 1850, in <module>
    BaseMeanIoU = tf.keras.metrics.MeanIoU
AttributeError: module 'tensorflow' has no attribute 'keras'




我尝试:
pip install --upgrade --no-deps --force-reinstall tensorflow

I try : pip install --upgrade --no-deps --force-reinstall tensorflow

pip install --upgrade pip setuptools wheel

pip install --upgrade pip setuptools wheel

pip卸载protobuf

pip uninstall protobuf

pip install protobuf

pip install protobuf

pip install termcolor

pip install termcolor

**我有:
keras 2.3。 1 pypi_0 pypi

**I have: keras 2.3.1 pypi_0 pypi

keras应用程序1.0.8 pypi_0 pypi

keras-applications 1.0.8 pypi_0 pypi

keras预处理1.1.2 pypi_0 pypi

keras-preprocessing 1.1.2 pypi_0 pypi

钥匙串21.1.1 py36_2

keyring 21.1.1 py36_2

kivy 1.10.1.dev0 pypi_0 pypi

kivy 1.10.1.dev0 pypi_0 pypi

kivy-deps-glew 0.2.0 pypi_0 pypi

kivy-deps-glew 0.2.0 pypi_0 pypi

kivy-deps-gstreamer 0 .2.0 pypi_0 pypi

kivy-deps-gstreamer 0.2.0 pypi_0 pypi

kivy-deps-sdl2 0.2.0 pypi_0 pypi

kivy-deps-sdl2 0.2.0 pypi_0 pypi

kivy-garden 0.1.4 pypi_0 pypi

kivy-garden 0.1.4 pypi_0 pypi

kiwisolver 1.2.0 py36h74a9793_0

kiwisolver 1.2.0 py36h74a9793_0

惰性对象代理1.4.3 py36he774522_0
**

lazy-object-proxy 1.4.3 py36he774522_0 **

我有numpy,pytorch,pip,tensorflow和大多数DL,ML,CV,Ai,DS库

(base) C:\Users\ASUS>python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

>>> import tensorflow
2020-05-22 06:23:19.327748: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-05-22 06:23:19.343057: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
>>> print(tensorflow)
<module 'tensorflow' from 'C:\\Users\\ASUS\\Anaconda3\\Anaconda\\lib\\site-packages\\tensorflow\\__init__.py'>
>>>

运行tensorflow时

When I run tensorflow

(base) C:\Users\ASUS>python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow.compat.v1 as tf
2020-05-22 06:18:12.900849: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-05-22 06:18:12.914907: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
>>> tf.disable_v2_behavior()
WARNING:tensorflow:From C:\Users\ASUS\Anaconda3\Anaconda\lib\site-packages\tensorflow\python\compat\v2_compat.py:96: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.
Instructions for updating:
non-resource variables are not supported in the long term
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.compat.v1.Session()
2020-05-22 06:20:28.305196: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2020-05-22 06:20:29.278356: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: GeForce GTX 1050 computeCapability: 6.1
coreClock: 1.493GHz coreCount: 5 deviceMemorySize: 4.00GiB deviceMemoryBandwidth: 104.43GiB/s
2020-05-22 06:20:29.295408: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-05-22 06:20:29.305186: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cublas64_10.dll'; dlerror: cublas64_10.dll not found
2020-05-22 06:20:29.314235: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cufft64_10.dll'; dlerror: cufft64_10.dll not found
2020-05-22 06:20:29.323997: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'curand64_10.dll'; dlerror: curand64_10.dll not found
2020-05-22 06:20:29.336231: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cusolver64_10.dll'; dlerror: cusolver64_10.dll not found
2020-05-22 06:20:29.349522: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cusparse64_10.dll'; dlerror: cusparse64_10.dll not found
2020-05-22 06:20:29.362633: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudnn64_7.dll'; dlerror: cudnn64_7.dll not found
2020-05-22 06:20:29.372823: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1598] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
2020-05-22 06:20:29.392493: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2020-05-22 06:20:29.413844: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x18bf4dc2f60 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-05-22 06:20:29.424116: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-05-22 06:20:29.432117: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-05-22 06:20:29.446877: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]
>>> print(sess.run(hello))
b'Hello, TensorFlow!'




问题解决后
在下面检查我的答案

After I Solve it Check my answer below



(base) C:\Users\ASUS>python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2020-05-29 17:59:47.814562: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
>>> import keras
Using TensorFlow backend.
>>> from keras.models import Sequential
>>> tf.test.is_built_with_cuda()
True
>>> tf.config.list_physical_devices('GPU')
2020-05-29 18:02:56.764618: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2020-05-29 18:02:57.602680: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: GeForce GTX 1050 computeCapability: 6.1
coreClock: 1.493GHz coreCount: 5 deviceMemorySize: 4.00GiB deviceMemoryBandwidth: 104.43GiB/s
2020-05-29 18:02:57.607142: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2020-05-29 18:02:57.703213: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2020-05-29 18:02:57.766722: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2020-05-29 18:02:57.797062: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2020-05-29 18:02:57.872961: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2020-05-29 18:02:57.920469: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2020-05-29 18:02:58.035860: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-05-29 18:02:58.148699: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
>>> tf.test.is_gpu_available(cuda_only=False, min_cuda_compute_capability=None)
2020-05-29 18:03:43.187834: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: GeForce GTX 1050 computeCapability: 6.1
coreClock: 1.493GHz coreCount: 5 deviceMemorySize: 4.00GiB deviceMemoryBandwidth: 104.43GiB/s
2020-05-29 18:03:43.200093: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2020-05-29 18:03:43.205083: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2020-05-29 18:03:43.214701: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2020-05-29 18:03:43.217616: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2020-05-29 18:03:43.229945: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2020-05-29 18:03:43.238134: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2020-05-29 18:03:43.247848: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-05-29 18:03:43.256302: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-05-29 18:03:43.264822: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-05-29 18:03:43.269994: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0
2020-05-29 18:03:43.271951: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N
2020-05-29 18:03:43.275672: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/device:GPU:0 with 2993 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1)
True
>>>


推荐答案

感谢所有答案,但是我解决了使用CUDA 10.1的教程 https: //towardsdatascience.com/installing-tensorflow-with-cuda-cudnn-and-gpu-support-on-windows-10-60693e46e781 。在完成本教程后,我卸载了此Lib,然后再次安装 pip install keras pip install --upup setuptools pip install cmake pip install keras模型 pip install keras应用程序 pip install keras预处理并下载Visual Studio2015。然后从我的问题中运行代码,例如从keras.models 导入Sequential 并检查pathon路径。

Thanks for all answers But I solve it I follow this tutorial with CUDA 10.1 https://towardsdatascience.com/installing-tensorflow-with-cuda-cudnn-and-gpu-support-on-windows-10-60693e46e781 .After this tutorial I uninstall this Libs and install it againpip install keras, pip install --upgrade setuptools, pip install cmake, pip install keras-models, pip install keras-applications, pip install keras-preprocessing and download Visual studio 2015. Then Run Code from my quesion like from keras.models import Sequential and check pathon path.

这篇关于AttributeError:模块“ tensorflow”在conda提示符中没有属性“ keras”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆