繁体   English   中英

无法在 jupyter 笔记本中为张量流 GPU 导入 keras

[英]not able to import keras for tensor flow gpu in jupyter notebook

我正在按照以下链接中给出的步骤安装 tensorflow gpu 后尝试导入 keras 库,

https://docs.anaconda.com/anaconda/user-guide/tasks/tensorflow/

并创建了一个环境 tf-gpu。

然后我在该环境中使用 pip install keras 安装了 keras。 但是当我尝试在 jupyter notebook 中导入 keras 时,它给出了以下错误,

'''

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
~\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>
     63   try:
---> 64     from tensorflow.python._pywrap_tensorflow_internal import *
     65   # This try catch logic is because there is no bazel equivalent for py_extension.

ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
~\anaconda3\lib\site-packages\keras\__init__.py in <module>
      2 try:
----> 3     from tensorflow.keras.layers.experimental.preprocessing import RandomRotation
      4 except ImportError:

~\anaconda3\lib\site-packages\tensorflow\__init__.py in <module>
     40 
---> 41 from tensorflow.python.tools import module_util as _module_util
     42 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader

~\anaconda3\lib\site-packages\tensorflow\python\__init__.py in <module>
     39 
---> 40 from tensorflow.python.eager import context
     41 

~\anaconda3\lib\site-packages\tensorflow\python\eager\context.py in <module>
     34 from tensorflow.core.protobuf import rewriter_config_pb2
---> 35 from tensorflow.python import pywrap_tfe
     36 from tensorflow.python import tf2

~\anaconda3\lib\site-packages\tensorflow\python\pywrap_tfe.py in <module>
     27 # pylint: disable=invalid-import-order,g-bad-import-order, wildcard-import, unused-import
---> 28 from tensorflow.python import pywrap_tensorflow
     29 from tensorflow.python._pywrap_tfe import *

~\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>
     82 above this error message when asking for help.""" % traceback.format_exc()
---> 83   raise ImportError(msg)
     84 

ImportError: Traceback (most recent call last):
  File "C:\Users\Mayank\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in <module>
    from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-4-88d96843a926> in <module>
----> 1 import keras

~\anaconda3\lib\site-packages\keras\__init__.py in <module>
      3     from tensorflow.keras.layers.experimental.preprocessing import RandomRotation
      4 except ImportError:
----> 5     raise ImportError(
      6         'Keras requires TensorFlow 2.2 or higher. '
      7         'Install TensorFlow via `pip install tensorflow`')

ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`

'''

当我检查 tensorflow 的版本时,它显示“2.1.0”

你能帮我们解决这个问题吗?

最好的方法是卸载 keras 和 tensorflow,这样你就可以重新开始或者只是创建一个新环境。 然后使用 conda 安装 tensorflow。 Conda 将安装 tensorflow 2.1.0、cuda 工具包 10.1.243 和 cudnn 7.6.5。 Pip 不安装工具包或 cudnn,您必须下载这些并更改环境路径变量以指向存储它们的目录。 如果要安装 tensorflow 2.2,请先使用 conda 安装 tensorflow 2.1.0,然后使用 pip install tensorflow ==2.2.0 安装 tensorflow 2.2。 Tensorflow 2.2 与 2.1 安装的工具包和 cudnn 版本兼容。 Conda 最多只能安装 2.1.0 的 tensorflow。 请注意,您可能希望使用 python 3.7 创建新环境。 用户在使用 conda 安装 tensorflow 时报告了 3.8 的问题。 Tensorflow 2.0 及更高版本包括 Keras。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM