Win10安装tensorflow-gpu以及对应版本的keras

怎么说捏,搞了一天好不容易安装成功,后来又需要安装其他的东西(matplotlib)把环境搞崩溃了,于是只能再来一次

Step1:创建虚拟环境

conda create -n gpuKeras python=3.6

Step2:进入虚拟环境,安装对应版本的cudatoolkit

conda install cudatoolkit=10.1

Step3:安装对应版本的cuDNN

conda install cudnn=7.2

Step4:安装指定版本的tensorflow-gpu

conda install tensorflow-gpu==1.12.0

接着可以输入python进入python环境查看是否可以正常导入tf模块,发现有警告,这是由于numpy的版本导致的,解决方案可以查看这个
Win10安装tensorflow-gpu以及对应版本的keras_第1张图片

Python 3.6.13 |Anaconda, Inc.| (default, Mar 16 2021, 11:37:27) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
D:\Myapp\Anaconda\anconda\envs\gpuKeras\lib\site-packages\tensorflow\python\framework\dtypes.py:523: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
D:\Myapp\Anaconda\anconda\envs\gpuKeras\lib\site-packages\tensorflow\python\framework\dtypes.py:524: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
D:\Myapp\Anaconda\anconda\envs\gpuKeras\lib\site-packages\tensorflow\python\framework\dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
D:\Myapp\Anaconda\anconda\envs\gpuKeras\lib\site-packages\tensorflow\python\framework\dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
D:\Myapp\Anaconda\anconda\envs\gpuKeras\lib\site-packages\tensorflow\python\framework\dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
D:\Myapp\Anaconda\anconda\envs\gpuKeras\lib\site-packages\tensorflow\python\framework\dtypes.py:532: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])

Step5:安装keras

pip install keras==2.2.0

查看是否安装成功
Win10安装tensorflow-gpu以及对应版本的keras_第2张图片
也可以在cmd运行以下文件test_code.py
在文件路径下python test_code.py即可,我自己遇到的问题是,powershell报错(numpy版本的问题,实在是懒得改了,cmd够用了~)
文件内容如下:

# 忽略对机器的警告
import warnings
warnings.filterwarnings('ignore', category=FutureWarning)

# 查看GPU是否成功加载
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

from keras import backend as K
print(K.tensorflow_backend._get_available_gpus())

Win10安装tensorflow-gpu以及对应版本的keras_第3张图片

参考文档

CSDN- win10如何安装tensorflow-gpu

你可能感兴趣的:(关于编程工具们的bug记录,tensorflow,python,keras)