win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度学习环境的方法


Posted in Servers onJune 25, 2022

避坑1:RTX30系列显卡不支持cuda11.0以下版本,具体上限版本可自行查阅:

方法一,在cmd中输入nvidia-smi查看

win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度学习环境的方法

方法二:

win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度学习环境的方法

win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度学习环境的方法

win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度学习环境的方法

win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度学习环境的方法

由此可以看出本电脑最高适配cuda11.2.1版本;

win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度学习环境的方法

注意需要版本适配,这里我们选择TensorFlow-gpu = 2.5,cuda=11.2.1,cudnn=8.1,python3.7

接下来可以下载cudn和cundnn:

官网:https://developer.nvidia.com/cuda-toolkit-archive

 下载对应版本exe文件打开默认安装就可;

验证是否安装成功:

win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度学习环境的方法

官网:cuDNN Archive | NVIDIA Developer

win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度学习环境的方法

把下载文件进行解压把bin+lib+include文件复制到C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2文件下;

进入环境变量设置(cuda会自动设置,如果没有的补全):

win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度学习环境的方法

查看是否安装成功:

cd C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\extras\demo_suite
bandwidthTest.exe

win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度学习环境的方法

 安装tensorflow-gpu:

pip install tensorflow-gpu==2.5

最后我们找相关程序来验证一下:

第一步:

import tensorflow as tf
print(tf.__version__)
print('GPU', tf.test.is_gpu_available())

win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度学习环境的方法

第二步:

# _*_ coding=utf-8 _*_
'''
@author: crazy jums
@time: 2021-01-24 20:55
@desc: 添加描述
'''
# 指定GPU训练
import os
os.environ["CUDA_VISIBLE_DEVICES"]="0"  ##表示使用GPU编号为0的GPU进行计算
import numpy as np
from tensorflow.keras.models import Sequential  # 采用贯序模型
from tensorflow.keras.layers import Dense, Dropout, Conv2D, MaxPool2D, Flatten
from tensorflow.keras.datasets import mnist
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.callbacks import TensorBoard
import time
def create_model():
    model = Sequential()
    model.add(Conv2D(32, (5, 5), activation='relu', input_shape=[28, 28, 1]))  # 第一卷积层
    model.add(Conv2D(64, (5, 5), activation='relu'))  # 第二卷积层
    model.add(MaxPool2D(pool_size=(2, 2)))  # 池化层
    model.add(Flatten())  # 平铺层
    model.add(Dropout(0.5))
    model.add(Dense(128, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(10, activation='softmax'))
    return model
def compile_model(model):
    model.compile(loss='categorical_crossentropy', optimizer="adam", metrics=['acc'])
    return model
def train_model(model, x_train, y_train, batch_size=32, epochs=10):
    tbCallBack = TensorBoard(log_dir="model", histogram_freq=1, write_grads=True)
    history = model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, shuffle=True, verbose=2,
                        validation_split=0.2, callbacks=[tbCallBack])
    return history, model
if __name__ == "__main__":
    import tensorflow as tf
    print(tf.__version__)
    from tensorflow.python.client import device_lib
    print(device_lib.list_local_devices())
    (x_train, y_train), (x_test, y_test) = mnist.load_data()  # mnist的数据我自己已经下载好了的
    print(np.shape(x_train), np.shape(y_train), np.shape(x_test), np.shape(y_test))
    x_train = np.expand_dims(x_train, axis=3)
    x_test = np.expand_dims(x_test, axis=3)
    y_train = to_categorical(y_train, num_classes=10)
    y_test = to_categorical(y_test, num_classes=10)
    print(np.shape(x_train), np.shape(y_train), np.shape(x_test), np.shape(y_test))
    model = create_model()
    model = compile_model(model)
    print("start training")
    ts = time.time()
    history, model = train_model(model, x_train, y_train, epochs=2)
    print("start training", time.time() - ts)

win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度学习环境的方法

验证成功。

以上就是win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度学习环境的详细内容,更多关于win10+RTX3050ti+TensorFlow+cudn+cudnn深度学习的资料请关注三水点靠木其它相关文章!


Tags in this post...

Servers 相关文章推荐
Nginx源码编译安装过程记录
Nov 17 Servers
Nginx动静分离配置实现与说明
Apr 07 Servers
在Docker容器中部署SQL Server
Apr 11 Servers
nginx实现多geoserver服务的负载均衡
May 15 Servers
聊聊配置 Nginx 访问与错误日志的问题
May 25 Servers
Linux中文件的基本属性介绍
Jun 01 Servers
基于docker安装zabbix的详细教程
Jun 05 Servers
V Rising 服务器搭建图文教程
Jun 16 Servers
Docker与K8s关系介绍不会Docker也可以使用K8s
Jun 25 Servers
解决Git推送错误non-fast-forward的方法
Jun 25 Servers
在windows server 2012 r2中安装mysql的详细步骤
Jul 23 Servers
django项目、vue项目部署云服务器的详细过程
Jul 23 Servers
git stash(储藏)的用法总结
Jun 25 #Servers
git中cherry-pick命令的使用教程
Jun 25 #Servers
解决Git推送错误non-fast-forward的方法
Jun 25 #Servers
Win2008系统搭建DHCP服务器
windows server2008 开启端口的实现方法
Windows10安装Apache2.4的方法步骤
Linux下搭建SFTP服务器的命令详解
Jun 25 #Servers
You might like
PHP合并discuz用户脚本的方法
2015/08/04 PHP
Yii中CGridView禁止列排序的设置方法
2016/07/12 PHP
ThinkPHP5.1表单令牌Token失效问题的解决
2019/03/22 PHP
PHP实现chrome表单请求数据转换为接口使用的json数据
2021/03/04 PHP
JavaScript 基于原型的对象(创建、调用)
2009/10/16 Javascript
jquery datatable后台封装数据示例代码
2014/08/07 Javascript
基于Flowplayer打造一款免费的WEB视频播放器附源码
2015/09/06 Javascript
Angular.js自定义指令学习笔记实例
2017/02/24 Javascript
ES6学习之变量的两种命名方法示例
2017/07/18 Javascript
BootStrap模态框和select2合用时input无法获取焦点的解决方法
2017/09/01 Javascript
vue计算属性时v-for处理数组时遇到的一个bug问题
2018/01/21 Javascript
vue-cli中安装方法(图文详细步骤)
2018/12/12 Javascript
微信小程序公用参数与公用方法用法示例
2019/01/09 Javascript
JavaScript实现网页计算器功能
2020/10/29 Javascript
Vue——解决报错 Computed property "****" was assigned to but it has no setter.
2020/12/19 Vue.js
Python使用combinations实现排列组合的方法
2018/11/13 Python
python设置环境变量的作用和实例
2019/07/09 Python
Django import export实现数据库导入导出方式
2020/04/03 Python
解决keras模型保存h5文件提示无此目录问题
2020/07/01 Python
Python faker生成器生成虚拟数据代码实例
2020/07/20 Python
python实现三壶谜题的示例详解
2020/11/02 Python
Selenium环境变量配置(火狐浏览器)及验证实现
2020/12/07 Python
举例详解CSS3中的Transition
2015/07/15 HTML / CSS
CSS3哪些新特性值得称赞
2016/03/02 HTML / CSS
世界上最大的餐具公司:Oneida
2016/12/17 全球购物
Melissa鞋马来西亚官方网站:MDreams马来西亚
2018/04/05 全球购物
Travelstart沙特阿拉伯:廉价航班、豪华酒店和实惠的汽车租赁优惠
2019/04/06 全球购物
Interflora澳大利亚:同日鲜花速递
2019/06/25 全球购物
以太网Ethernet IEEE802.3
2013/08/05 面试题
广告业务员岗位职责
2014/02/06 职场文书
办公室领导干部作风整顿个人整改措施
2014/09/17 职场文书
安娜卡列尼娜观后感
2015/06/11 职场文书
2015初中团支部工作总结
2015/07/21 职场文书
高二语文教学反思
2016/02/16 职场文书
Promise面试题详解之控制并发
2021/05/14 面试题
PHP使用QR Code生成二维码实例
2021/07/07 PHP