TensorFlow DeepLab教程初稿-tensorflow gpu安装教程

Summary: DeepLab需要1.10以上版本。

本日志详细记录在两台不同笔记本电脑安装/更新 TensorFlow-GPU的具体过程

这是本人第3次,4次安装tf,这两次是gpu版。

第一次是安装cpu版,第二次是在python2.7 arcpy环境下安装32位 tf,但不能运行。第三次安装成功,但电脑配置过低,只能使用cpu功能;第四次安装成功,可以正确运行,使用gpu。

向日葵2019年7月24日于长沙

Confirm tensorflow installed correctly

>>> import tensorflow as tf

>>> hello=tf.constant("Hello tf")

>>> tf.Session().run(hello)

b'Hello tf'


查看tf版本

C:\Users\think>python --version

Python 3.6.7 :: Anaconda custom (64-bit)


Anaconda3 (3.6, 64-bit) interactive window [PTVS 16.0.19074.1-16.0]

Type $help for a list of commands.

>>> import tensorflow as tf

>>> tf.VERSION

'1.12.0'

>>>


>>> tf.__version__

'1.12.0'


查看CPU GPU版本

import os

from tensorflow.python.client import device_lib

os.environ["TF_CPP_MIN_LOG_LEVEL"]="99"

device_lib.list_local_devices()


[name: "/device:CPU:0"

device_type: "CPU"

memory_limit: 268435456

locality {

}

incarnation: 5642870862507944

]

>>> if __name__ == "main":

... print(device_lib.list_local_devices)

...

>>>


查看python安装路径

>>> import sys

>>> sys.path

['.', 'D:\\ProgramData\\Anaconda3\\', 'd:\\ProgramData\\Anaconda3\\python36.zip', 'd:\\ProgramData\\Anaconda3\\DLLs', 'd:\\ProgramData\\Anaconda3\\lib', 'd:\\ProgramData\\Anaconda3', 'd:\\ProgramData\\Anaconda3\\lib\\site-packages', 'd:\\ProgramData\\Anaconda3\\lib\\site-packages\\win32', 'd:\\ProgramData\\Anaconda3\\lib\\site-packages\\win32\\lib', 'd:\\ProgramData\\Anaconda3\\lib\\site-packages\\Pythonwin']


>>> import os

>>> os.path

<module 'ntpath' from 'd:\\ProgramData\\Anaconda3\\lib\\ntpath.py'>

Python.exe的路径:

"D:\ProgramData\Anaconda3\python.exe"


TensorFlow DeepLab教程初稿-tensorflow gpu安装教程_microsoft


更新为gpu版本

Type cmd to enter dos command line and type:

pip3 install --ignore-installed --upgrade tensorflow-gpu


C:\Users\think>pip3 install --ignore-installed --upgrade tensorflow-gpu

Collecting tensorflow-gpu

Downloading https://files.pythonhosted.org/packages/c7/e8/f7ba3acc4e45bea553ef085846e0240daa71986a04e1819bafef569f055b/tensorflow_gpu-1.14.0-cp36-cp36m-win_amd64.whl (287.7MB)


由于空间原因,安装失败。

Installing collected packages: astor, wheel, wrapt, six, setuptools, protobuf, numpy, google-pasta, termcolor, grpcio, h5py, keras-applications, absl-py, keras-preprocessing, gast, tensorflow-estimator, markdown, werkzeug, tensorboard, tensorflow-gpu

Could not install packages due to an EnvironmentError: [Errno 28] No space left on device

重输入命令,可以续装,自动使用缓存。


tensorflow 1.12.0 has requirement tensorboard<1.13.0,>=1.12.0, but you'll have tensorboard 1.14.0 which is incompatible.


Installing collected packages: six, setuptools, protobuf, numpy, h5py, keras-applications, absl-py, grpcio, tensorflow-estimator, termcolor, google-pasta, wrapt, wheel, gast, werkzeug, markdown, tensorboard, astor, keras-preprocessing, tensorflow-gpu

Successfully installed absl-py-0.7.1 astor-0.8.0 gast-0.2.2 google-pasta-0.1.7 grpcio-1.22.0 h5py-2.9.0 keras-applications-1.0.8 keras-preprocessing-1.1.0 markdown-3.1.1 numpy-1.16.4 protobuf-3.9.0 setuptools-41.0.1 six-1.12.0 tensorboard-1.14.0 tensorflow-estimator-1.14.0 tensorflow-gpu-1.14.0 termcolor-1.1.0 werkzeug-0.15.5 wheel-0.33.4 wrapt-1.11.2


尝试卸载

C:\Users\think>pip3 uninstall tensorflow

Uninstalling tensorflow-1.12.0:

Would remove:

d:\programdata\anaconda3\lib\site-packages\tensorflow-1.12.0.dist-info\*


Proceed (y/n)? y

Successfully uninstalled tensorflow-1.12.0

成功卸载


重新尝试安装gpu版本:

C:\Users\think>pip3 install --ignore-installed --upgrade tensorflow-gpu

Collecting tensorflow-gpu

Using cached ​​https://files.pythonhosted.org/packages/c7/e8/f7ba3acc4e45bea553ef085846e0240daa71986a04e1819bafef569f055b/tensorflow_gpu-1.14.0-cp36-cp36m-win_amd64.whl​


开始使用缓存安装

结果TensorFlow-gpu 安装成功


测试tf

C:\Users\think>python

Python 3.6.7 |Anaconda custom (64-bit)| (default, Oct 28 2018, 19:44:12) [MSC v.1915 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import tensorflow as tf

D:\ProgramData\Anaconda3\lib\site-packages\numpy\core\__init__.py:29: UserWarning: loaded more than 1 DLL from .libs:

D:\ProgramData\Anaconda3\lib\site-packages\numpy\.libs\libopenblas.CSRRD7HKRKC3T3YXA7VY7TAZGLSWDKW6.gfortran-win_amd64.dll

D:\ProgramData\Anaconda3\lib\site-packages\numpy\.libs\libopenblas.TXA6YQSD3GCQQC22GEQ54J2UDCXDXHWN.gfortran-win_amd64.dll

stacklevel=1)

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 28, in <module>

from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import

File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 47, in <module>

import numpy as np

File "D:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>

from . import core

File "D:\ProgramData\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 91, in <module>

raise ImportError(msg.format(path))

ImportError: Something is wrong with the numpy installation. While importing we detected an older version of numpy in ['D:\\ProgramData\\Anaconda3\\lib\\site-packages\\numpy']. One method of fixing this is to repeatedly uninstall numpy until none is found, then reinstall this version.


Uninstall numpy

C:\Users\think>pip3 uninstall numpy

Uninstalling numpy-1.16.4:

Would remove:

d:\programdata\anaconda3\lib\site-packages\numpy-1.16.4.dist-info\*

d:\programdata\anaconda3\lib\site-packages\numpy\*

d:\programdata\anaconda3\scripts\f2py.exe

Would not remove (might be manually added):

d:\programdata\anaconda3\lib\site-packages\numpy\.libs\libopenblas.CSRRD7HKRKC3T3YXA7VY7TAZGLSWDKW6.gfortran-win_amd64.dll

d:\programdata\anaconda3\lib\site-packages\numpy\_import_tools.py

d:\programdata\anaconda3\lib\site-packages\numpy\_mklinit.cp36-win_amd64.pyd

d:\programdata\anaconda3\lib\site-packages\numpy\add_newdocs.py

d:\programdata\anaconda3\lib\site-packages\numpy\core\multiarray.cp36-win_amd64.pyd

d:\programdata\anaconda3\lib\site-packages\numpy\core\umath.cp36-win_amd64.pyd

d:\programdata\anaconda3\lib\site-packages\numpy\distutils\environment.py

d:\programdata\anaconda3\lib\site-packages\numpy\distutils\site.cfg

d:\programdata\anaconda3\lib\site-packages\numpy\random_intel\__init__.py

d:\programdata\anaconda3\lib\site-packages\numpy\random_intel\setup.py

d:\programdata\anaconda3\lib\site-packages\numpy\testing\_private\pytesttester.py

Proceed (y/n)? y

Successfully uninstalled numpy-1.16.4


Install numpy

C:\Users\think>pip3 install numpy

Requirement already satisfied: numpy in d:\programdata\anaconda3\lib\site-packages (1.15.4)


测试tf

>>> import tensorflow as tf

Traceback (most recent call last):

File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\platform\self_check.py", line 75, in preload_check

ctypes.WinDLL(build_info.cudart_dll_name)

File "D:\ProgramData\Anaconda3\lib\ctypes\__init__.py", line 348, in __init__

self._handle = _dlopen(self._name, mode)

OSError: [WinError 126] The specified module could not be found


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 28, in <module>

from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import

File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>

from tensorflow.python import pywrap_tensorflow

File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 30, in <module>

self_check.preload_check()

File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\platform\self_check.py", line 82, in preload_check

% (build_info.cudart_dll_name, build_info.cuda_version_number))

ImportError: Could not find 'cudart64_100.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 10.0 from this URL: ​​https://developer.nvidia.com/cuda-90-download-archive​​​(tf提示错误:应为​​https://developer.nvidia.com/cuda-100-download-archive) ​

​结果: ​

​1. 找不到cuda v10.0 ​

​2. tf安装程序的提示版本错误,但提示的dll版本信息是正确的。 ​

​由于已经安装了最新版的cuda,查看版本及文件名 ​

​G:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin ​

​cudart64_101.dll ​




​结果:已安装cuda版本过高。 ​

​重新安装cuda v10.0 ​

​查看环境变量: ​

​path ​

​G:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\V10.0\bin ​

​G:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\V10.0\libnvvp ​


​CUDA_PATH ​

​G:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\V10.0 ​


​CUDA_PATH_V10_0 ​

​G:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\V10.0 ​



​Test tensorflow ​

​>>> import tensorflow as tf ​

​Traceback (most recent call last): ​

​ File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module> ​

​ from tensorflow.python.pywrap_tensorflow_internal import * ​

​ File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module> ​

​ _pywrap_tensorflow_internal = swig_import_helper() ​

​ File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper ​

​ _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) ​

​ File "D:\ProgramData\Anaconda3\lib\imp.py", line 243, in load_module ​

​ return load_dynamic(name, filename, file) ​

​ File "D:\ProgramData\Anaconda3\lib\imp.py", line 343, in load_dynamic ​

​ return _load(spec) ​

​ImportError: DLL load failed: The specified procedure could not be found. ​


​During handling of the above exception, another exception occurred: ​


​Traceback (most recent call last): ​

​ File "<stdin>", line 1, in <module> ​

​ File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 28, in <module> ​

​ from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import ​

​ File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module> ​

​ from tensorflow.python import pywrap_tensorflow ​

​ File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module> ​

​ raise ImportError(msg) ​

​ImportError: Traceback (most recent call last): ​

​ File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module> ​

​ from tensorflow.python.pywrap_tensorflow_internal import * ​

​ File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module> ​

​ _pywrap_tensorflow_internal = swig_import_helper() ​

​ File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper ​

​ _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) ​

​ File "D:\ProgramData\Anaconda3\lib\imp.py", line 243, in load_module ​

​ return load_dynamic(name, filename, file) ​

​ File "D:\ProgramData\Anaconda3\lib\imp.py", line 343, in load_dynamic ​

​ return _load(spec) ​

​ImportError: DLL load failed: The specified procedure 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. ​


​Reinstall cudnn ​

​安装cuDNN ​

​官网下载好后可以直接解压文件夹。然后将这个文件夹下的文件按照如下操作复制到CUDA路径下: ​


​Copy <installpath>\cuda\bin\cudnn64_*.dll to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\ v10.0\bin. ​

​Copy <installpath>\cuda\ include\cudnn.h to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\ v10.0\include. ​

​Copy <installpath>\cuda\lib\x64\cudnn.lib to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64. ​


​测试: ​

​>>> import tensorflow as tf ​

​Traceback (most recent call last): ​

​ File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module> ​

​ from tensorflow.python.pywrap_tensorflow_internal import * ​

​ File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module> ​

​ _pywrap_tensorflow_internal = swig_import_helper() ​

​ File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper ​

​ _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) ​

​ File "D:\ProgramData\Anaconda3\lib\imp.py", line 243, in load_module ​

​ return load_dynamic(name, filename, file) ​

​ File "D:\ProgramData\Anaconda3\lib\imp.py", line 343, in load_dynamic ​

​ return _load(spec) ​

​ImportError: DLL load failed: The specified procedure could not be found. ​


​During handling of the above exception, another exception occurred: ​


​Traceback (most recent call last): ​

​ File "<stdin>", line 1, in <module> ​

​ File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 28, in <module> ​

​ from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import ​

​ File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module> ​

​ from tensorflow.python import pywrap_tensorflow ​

​ File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module> ​

​ raise ImportError(msg) ​

​ImportError: Traceback (most recent call last): ​

​ File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module> ​

​ from tensorflow.python.pywrap_tensorflow_internal import * ​

​ File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module> ​

​ _pywrap_tensorflow_internal = swig_import_helper() ​

​ File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper ​

​ _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) ​

​ File "D:\ProgramData\Anaconda3\lib\imp.py", line 243, in load_module ​

​ return load_dynamic(name, filename, file) ​

​ File "D:\ProgramData\Anaconda3\lib\imp.py", line 343, in load_dynamic ​

​ return _load(spec) ​

​ImportError: DLL load failed: The specified procedure 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. ​

​结果:依然出错 ​

​卸载 ​

​C:\Users\think>pip3 uninstall tensorflow-gpu ​

​Uninstalling tensorflow-gpu-1.14.0: ​

​ Would remove: ​

​ d:\programdata\anaconda3\lib\site-packages\tensorflow\* ​

​ d:\programdata\anaconda3\lib\site-packages\tensorflow_gpu-1.14.0.dist-info\* ​

​ d:\programdata\anaconda3\scripts\freeze_graph.exe ​

​ d:\programdata\anaconda3\scripts\saved_model_cli.exe ​

​ d:\programdata\anaconda3\scripts\tensorboard.exe ​

​ d:\programdata\anaconda3\scripts\tf_upgrade_v2.exe ​

​ d:\programdata\anaconda3\scripts\tflite_convert.exe ​

​ d:\programdata\anaconda3\scripts\toco.exe ​

​d:\programdata\anaconda3\scripts\toco_from_protos.exe ​


​​Run python3.7 installed with vs ​​

​pythonpath ​

​C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64 ​


​C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Scripts ​



​​重装 ​​

​C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Scripts>pip3 install tensorflow-gpu ​

​Collecting tensorflow-gpu ​

​ Downloading https://files.pythonhosted.org/packages/81/d1/9222b9aac2fa27dccaef38917cde84c24888f3cd0dd139c7e12be9f49a7a/tensorflow_gpu-1.14.0-cp37-cp37m-win_amd64.whl (287.7MB) ​


Installing collected packages: tensorflow-estimator, google-pasta, numpy, six, grpcio, astor, wheel, wrapt, gast, absl-py, setuptools, werkzeug, protobuf, markdown, tensorboard, h5py, keras-applications, keras-preprocessing, termcolor, tensorflow-gpu

Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: 'c:\\program files (x86)\\microsoft visual studio\\shared\\python37_64\\Lib\\site-packages\\tensorflow_estimator'

Consider using the `--user` option or check the permissions.


​You are using pip version 18.1, however version 19.2.1 is available. ​

​You should consider upgrading via the 'python -m pip install --upgrade pip' command. ​




​​更新pip ​​

​结果:失败 ​

​C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64>python -m pip install --upgrade pip ​

​Collecting pip ​

​ Downloading https://files.pythonhosted.org/packages/62/ca/94d32a6516ed197a491d17d46595ce58a83cbb2fca280414e57cd86b84dc/pip-19.2.1-py2.py3-none-any.whl (1.4MB) ​

​ 100% |████████████████████████████████| 1.4MB 6.0MB/s ​

​Installing collected packages: pip ​

​ Found existing installation: pip 18.1 ​

​ Uninstalling pip-18.1: ​

​Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: 'c:\\program files (x86)\\microsoft visual studio\\shared\\python37_64\\lib\\site-packages\\pip-18.1.dist-info\\entry_points.txt' ​

​Consider using the `--user` option or check the permissions. ​


​You are using pip version 18.1, however version 19.2.1 is available. ​

​You should consider upgrading via the 'python -m pip install --upgrade pip' command. ​


​设置所有权限 ​

​重新更新pip ​

​结果:成功 ​

​C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64>python -m pip install --upgrade pip ​

​Collecting pip ​

​ Using cached https://files.pythonhosted.org/packages/62/ca/94d32a6516ed197a491d17d46595ce58a83cbb2fca280414e57cd86b84dc/pip-19.2.1-py2.py3-none-any.whl ​

​Installing collected packages: pip ​

​ Found existing installation: pip 18.1 ​

​ Uninstalling pip-18.1: ​

​ Successfully uninstalled pip-18.1 ​

​Successfully installed pip-19.2.1 ​



​重新安装tf-gpu ​

​C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64>cd C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Scripts ​


​C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Scripts>pip3 install tensorflow-gpu ​

​Collecting tensorflow-gpu ​

​ Using cached ​​​​https://files.pythonhosted.org/packages/81/d1/9222b9aac2fa27dccaef38917cde84c24888f3cd0dd139c7e12be9f49a7a/tensorflow_gpu-1.14.0-cp37-cp37m-win_amd64.whl​


WARNING: The script f2py.exe is installed in 'c:\program files (x86)\microsoft visual studio\shared\python37_64\Scripts' which is not on PATH.

Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

Running setup.py install for wrapt ... done

Found existing installation: setuptools 40.6.2

Uninstalling setuptools-40.6.2:

Successfully uninstalled setuptools-40.6.2

WARNING: The script wheel.exe is installed in 'c:\program files (x86)\microsoft visual studio\shared\python37_64\Scripts' which is not on PATH.

Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

Running setup.py install for absl-py ... done

WARNING: The script markdown_py.exe is installed in 'c:\program files (x86)\microsoft visual studio\shared\python37_64\Scripts' which is not on PATH.

Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

WARNING: The script tensorboard.exe is installed in 'c:\program files (x86)\microsoft visual studio\shared\python37_64\Scripts' which is not on PATH.

Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

Running setup.py install for termcolor ... done

Running setup.py install for gast ... done

WARNING: The scripts freeze_graph.exe, saved_model_cli.exe, tensorboard.exe, tf_upgrade_v2.exe, tflite_convert.exe, toco.exe and toco_from_protos.exe are installed in 'c:\program files (x86)\microsoft visual studio\shared\python37_64\Scripts' which is not on PATH.

Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

Successfully installed absl-py-0.7.1 astor-0.8.0 gast-0.2.2 google-pasta-0.1.7 grpcio-1.22.0 h5py-2.9.0 keras-applications-1.0.8 keras-preprocessing-1.1.0 markdown-3.1.1 numpy-1.16.4 protobuf-3.9.0 setuptools-41.0.1 six-1.12.0 tensorboard-1.14.0 tensorflow-estimator-1.14.0 tensorflow-gpu-1.14.0 termcolor-1.1.0 werkzeug-0.15.5 wheel-0.33.4 wrapt-1.11.2


添加path环境变量

c:\program files (x86)\microsoft visual studio\shared\python37_64\Scripts



测试tf

>>> import tensorflow as tf

>>> tf.__version__

'1.14.0'

结果:成功


测试cpu还是gpu

>>> import os

>>> from tensorflow.python.client import device_lib

>>> os.environ["TF_CPP_MIN_LOG_LEVEL"]="99"

>>> device_lib.list_local_devices()

[name: "/device:CPU:0"

device_type: "CPU"

memory_limit: 268435456

locality {

}

incarnation: 11073789457534317226

]


测试是否在gpu上运行

>>> import tensorflow as tf

>>> sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

2019-07-24 18:55:42.319137: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

2019-07-24 18:55:42.324349: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library nvcuda.dll

2019-07-24 18:55:42.859900: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties:

name: Quadro K1100M major: 3 minor: 0 memoryClockRate(GHz): 0.7055

pciBusID: 0000:01:00.0

2019-07-24 18:55:42.864411: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.

2019-07-24 18:55:42.869847: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1717] Ignoring visible gpu device (device: 0, name: Quadro K1100M, pci bus id: 0000:01:00.0, compute capability: 3.0) with Cuda compute capability 3.0. The minimum required Cuda capability is 3.5.

2019-07-24 18:55:42.902715: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix:

2019-07-24 18:55:42.905383: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187] 0

2019-07-24 18:55:42.907013: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0: N

Device mapping: no known devices.

2019-07-24 18:55:42.910171: I tensorflow/core/common_runtime/direct_session.cc:296] Device mapping:

结果:

由于tf 最小cuda计算能力要求为3.5,本gpu(device: 0, name: Quadro K1100M, pci bus id: 0000:01:00.0, compute capability: 3.0)不满足要求。


换台电脑,在python3.6上安装tf-gpu

主要内容:

1. 添加权限

2 安装cuda,cudnn

3 根据提示更新pip

4 安装tf-gpu


测试是否在gpu上运行

>>> import tensorflow as tf

>>> sess=tf.Session(config=tf.ConfigProto(log_device_placement=True))

2019-07-24 19:05:52.174361: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

2019-07-24 19:05:52.180939: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library nvcuda.dll

2019-07-24 19:05:52.309641: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties:

name: GeForce 940MX major: 5 minor: 0 memoryClockRate(GHz): 1.2415

pciBusID: 0000:01:00.0

2019-07-24 19:05:52.317307: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.

2019-07-24 19:05:52.322696: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0

2019-07-24 19:05:53.599442: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix:

2019-07-24 19:05:53.603636: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187] 0

2019-07-24 19:05:53.605884: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0: N

2019-07-24 19:05:53.608481: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1391 MB memory) -> physical GPU (device: 0, name: GeForce 940MX, pci bus id: 0000:01:00.0, compute capability: 5.0)

Device mapping:

/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce 940MX, pci bus id: 0000:01:00.0, compute capability: 5.0

2019-07-24 19:05:53.618489: I tensorflow/core/common_runtime/direct_session.cc:296] Device mapping:

/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce 940MX, pci bus id: 0000:01:00.0, compute capability: 5.0

进一步测试

>>> import os

>>> from tensorflow.python.client import device_lib

>>> os.environ["TF_CPP_MIN_LOG_LEVEL"] = "99"

>>> print(device_lib.list_local_devices())

[name: "/device:CPU:0"

device_type: "CPU"

memory_limit: 268435456

locality {

}

incarnation: 2949566760586279955

,


name: "/device:GPU:0"

device_type: "GPU"

memory_limit: 1459018137

locality {

bus_id: 1

links {

}

}

incarnation: 14182985404273149922

physical_device_desc: "device: 0, name: GeForce 940MX, pci bus id: 0000:01:00.0, compute capability: 5.0"

]


总结

在anaconda3.6安装最新版(未指定版本)tf-gpu,失败。因为没有提示具体错误,难以分析具体原因,所以拟在别的位置的python上重新安装。

失败的原因可能是在本python下已经安装了tf cpu '1.12.0'

找到vs安装的python3.7,添加环境变量和权限后,更新pip命令,未指定版本, '1.14.0',安装成功,发现下载速度很快,一会儿就安装好了,但不能正确运行。

之后换位置安装好,但gpu版本太低,无法应用gpu加速。

最后换电脑安装,终于成功。

结论:

1. 查看gpu-cuda计算能力,是否大于3.5

2. 如果python安装c盘,需要添加权限

3 更新pip

4. 安装tf-gpu,目前最新版为1.14.0

5.安装cuda和cudnn,需要完全核定版本,这一步可以根据运行tf的结果来确认版本。