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 相关文章推荐
destoon在各个服务器下设置URL Rewrite(伪静态)的方法
Jun 21 Servers
Nginx的反向代理实例详解
Mar 31 Servers
Nginx反向代理及负载均衡如何实现(基于linux)
Mar 31 Servers
提升Nginx性能的一些建议
Mar 31 Servers
nginx部署多前端项目的几种方法
May 25 Servers
nginx的zabbix 5.0安装部署的方法步骤
Jul 16 Servers
Nginx配置https的实现
Nov 27 Servers
Apache Linkis 中间件架构及快速安装步骤
Mar 16 Servers
tomcat的catalina.out日志按自定义时间格式进行分割的操作方法
Apr 02 Servers
忘记Grafana不要紧2种Grafana重置admin密码方法详细步骤
Apr 07 Servers
Ubuntu Server 安装Tomcat并配置systemctl
Apr 28 Servers
Linux在两个服务器直接传文件的操作方法
Aug 05 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 应用程序安全防范技术研究
2009/09/25 PHP
用PHP实现Ftp用户的在线管理
2012/02/16 PHP
ASP和PHP实现生成网站快捷方式并下载到桌面的方法
2014/05/08 PHP
跟我学Laravel之视图 & Response
2014/10/15 PHP
PHP递归遍历指定目录的文件并统计文件数量的方法
2015/03/24 PHP
php调用淘宝开放API实现根据卖家昵称获取卖家店铺ID的方法
2015/07/29 PHP
Yii操作数据库实现动态获取表名的方法
2016/03/29 PHP
Laravel框架定时任务2种实现方式示例
2018/12/08 PHP
关于Laravel-admin的基础用法总结和自定义model详解
2019/10/08 PHP
PhpStorm 如何优雅的调试Hyperf的方法步骤
2019/11/24 PHP
PHP使用gearman进行异步的邮件或短信发送操作详解
2020/02/27 PHP
JavaScript 学习点滴记录
2009/04/24 Javascript
仿百度输入框智能提示的js代码
2013/08/22 Javascript
script标签属性用type还是language
2015/01/21 Javascript
javascript实现博客园页面右下角返回顶部按钮
2015/02/22 Javascript
jQuery使用ajax跨域获取数据的简单实例
2016/05/18 Javascript
jQuery如何获取动态添加的元素
2016/06/24 Javascript
微信小程序 数据封装,参数传值等经验分享
2017/01/09 Javascript
彻底弄懂 JavaScript 执行机制
2018/10/23 Javascript
微信小程序地图(map)组件点击(tap)获取经纬度的方法
2019/01/10 Javascript
[15:09]DOTA2国际邀请赛采访专栏:Loda
2013/08/06 DOTA
[50:11]2018DOTA2亚洲邀请赛 4.7总决赛 LGD vs Mineski 第三场
2018/04/09 DOTA
TensorFlow基于MNIST数据集实现车牌识别(初步演示版)
2019/08/05 Python
python+openCV调用摄像头拍摄和处理图片的实现
2019/08/06 Python
Django中的用户身份验证示例详解
2019/08/07 Python
python 图片二值化处理(处理后为纯黑白的图片)
2019/11/01 Python
Tensorflow 使用pb文件保存(恢复)模型计算图和参数实例详解
2020/02/11 Python
VLAN和VPN有什么区别?分别实现在OSI的第几层?
2014/12/23 面试题
软件工程师面试题
2012/06/25 面试题
公务员平时考核实施方案
2014/03/11 职场文书
关于教师节的广播稿
2014/09/10 职场文书
行政人事主管岗位职责
2015/04/11 职场文书
开除通知书范本
2015/04/25 职场文书
初中数学课堂教学反思
2016/02/17 职场文书
写好Python代码的几条重要技巧
2021/05/21 Python
Spring Boot 使用 Spring-Retry 进行重试框架
2022/04/24 Java/Android