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

文章讲述了在Windows10上创建conda虚拟环境并安装Tensorflow-GPU、Keras,以及遇到的numpy版本警告和GPU加载问题。通过conda命令行工具安装cudatoolkit、cuDNN,然后安装特定版本的tensorflow-gpu和keras,最后展示了检查GPU是否成功加载的代码片段。
摘要由CSDN通过智能技术生成

怎么说捏,搞了一天好不容易安装成功,后来又需要安装其他的东西(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的版本导致的,解决方案可以查看这个
在这里插入图片描述

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

查看是否安装成功
在这里插入图片描述
也可以在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())

在这里插入图片描述

参考文档

CSDN- win10如何安装tensorflow-gpu

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值