windows10 安装tensorflow2.0, tensorlayer2.0填坑记

windows10 安装tensorflow2.0, tensorlayer2.0填坑记

文章目录

  • windows10 安装tensorflow2.0, tensorlayer2.0填坑记
    • 前言
    • 一. Nvidia环境
      • 1.先安装CUDA
      • 2.再安装Nvidia驱动
      • 3.安装CuDnn
    • 二. tensorflow,tensorlayer安装
      • 1.创建虚拟环境
      • 2.安装tensorflow2.0
      • 3.安装tensorflow2.0-gpu
      • 4.安装tensorlayer2.0

前言

系统要求

硬件要求

系统支持以下支持 GPU 的设备:

  • CUDA® 计算能力为 3.5 或更高的 NVIDIA® GPU 卡。请参阅支持 CUDA 的 GPU 卡列表。

软件要求

必须在系统中安装以下 NVIDIA® 软件:

  • NVIDIA® GPU 驱动程序 - CUDA 10.0 需要 410.x 或更高版本。
  • CUDA® 工具包 - TensorFlow 支持 CUDA 10.0(TensorFlow 1.13.0 及更高版本)
  • CUDA 工具包附带的 CUPTI。
  • cuDNN SDK(7.4.1 及更高版本)
  • (可选)TensorRT 5.0,可缩短在某些模型上进行推断的延迟并提高吞吐量。

在几经失败之后,按照这里的指南

SUCCESS
tensorflow-gpu==2.0.0-alpha0
python 3.6.8
CUDA v10.0
cudnn 7.4.1.5

一. Nvidia环境

假设Anaconda已安装好

1.先安装CUDA

2.再安装Nvidia驱动

cuda自带的驱动版本比较旧,后安装可以更新驱动

3.安装CuDnn

二. tensorflow,tensorlayer安装

1.创建虚拟环境

conda create -n tf2 python==3.6.8

注意:python须指定3.6.8,之前指定为3.6.0时,出现以下错误

import tensorflow as tf
Traceback (most recent call last):
File "", line 1, in <module>
File "C:\Users\enbo\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:\Users\enbo\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "C:\Users\enbo\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\core\framework\graph_pb2.py", line 6, in <module>
from google.protobuf import descriptor as _descriptor
File "C:\Users\enbo\Anaconda3\envs\tensorflow\lib\site-packages\google\protobuf\descriptor.py", line 47, in <module>
from google.protobuf.pyext import _message
ImportError: DLL load failed: 找不到指定的程序。

解决方案在这,将python3.6.0换掉即可

On my PC, updating python 3.6.0 to 3.6.1 solved the problem of " from google.protobuf.pyext import _message "

2.安装tensorflow2.0

pip install tensorflow==2.0.0-alpha0

如果出现权限错误,使用下面的命令

pip install --user tensorflow==2.0.0-alpha0

安装完成后,测试出现下面的结果表示安装成功

>>> import tensorflow as tf
>>> print(tf.__version__)
2.0.0-alpha0

3.安装tensorflow2.0-gpu

pip install tensorflow-gpu==2.0.0-alpha0

测试,出现下面信息表示安装成功。垃圾笔记本显卡

>>> import tensorflow as tf
>>> tf.compat.v1.Session()
2019-06-20 21:36:35.137355: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2019-06-20 21:36:35.159280: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library nvcuda.dll
2019-06-20 21:36:35.785670: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1467] Found device 0 with properties:
name: GeForce GTX 860M major: 5 minor: 0 memoryClockRate(GHz): 1.0195
pciBusID: 0000:01:00.0
totalMemory: 2.00GiB freeMemory: 1.64GiB
2019-06-20 21:36:35.793615: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1546] Adding visible gpu devices: 0

4.安装tensorlayer2.0

pip install --user tensorlayer

测试,出现以下问题

>>> import tensorlayer as tl
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
ImportError: numpy.core.multiarray failed to import

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "", line 968, in _find_and_load
SystemError: <class '_frozen_importlib._ModuleLockManager'> returned a result with an error set
ImportError: numpy.core._multiarray_umath failed to import
ImportError: numpy.core.umath failed to import
2019-06-20 21:42:59.885527: F tensorflow/python/lib/core/bfloat16.cc:675] Check failed: PyBfloat16_Type.tp_base != nullptr

解决方案,输入以下命令。

pip install -U numpy -i https://pypi.tuna.tsinghua.edu.cn/simple/

测试,出现以下问题,查看tensorlayer版本为1.9.0,可能是tl与tf版本不匹配导致的

>>> import tensorlayer as tl
Traceback (most recent call last):
  File "", line 1, in <module>
  File "C:\Users\Avins\AppData\Roaming\Python\Python36\site-packages\tensorlayer\__init__.py", line 35, in <module>
    from . import initializers
  File "C:\Users\Avins\AppData\Roaming\Python\Python36\site-packages\tensorlayer\initializers.py", line 7, in <module>
    from tensorlayer.layers.core import LayersConfig
  File "C:\Users\Avins\AppData\Roaming\Python\Python36\site-packages\tensorlayer\layers\__init__.py", line 12, in <module>
    from .activation import *
  File "C:\Users\Avins\AppData\Roaming\Python\Python36\site-packages\tensorlayer\layers\activation.py", line 6, in <module>
    from tensorlayer.layers.core import Layer
  File "C:\Users\Avins\AppData\Roaming\Python\Python36\site-packages\tensorlayer\layers\core.py", line 37, in <module>
    TF_GRAPHKEYS_VARIABLES = tf.GraphKeys.GLOBAL_VARIABLES
AttributeError: module 'tensorflow' has no attribute 'GraphKeys'

删除tensorlayer1.9.0 安装tensorlayer新版本,当前最新版本为2.1.0

pip uninstall tensorlayer
pip install --user https://github.com/tensorlayer/tensorlayer/archive/master.zip

测试成功

>>> import tensorlayer as tl
>>> print(tl.__version__)
2.1.0

你可能感兴趣的:(教程,tensorflow,教程,tensorflow)