win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度学习环境的方法
作者:末世灯光 时间:2023-02-12 14:02:00
避坑1:RTX30系列显卡不支持cuda11.0以下版本,具体上限版本可自行查阅:
方法一,在cmd中输入nvidia-smi查看
方法二:
由此可以看出本电脑最高适配cuda11.2.1版本;
注意需要版本适配,这里我们选择TensorFlow-gpu = 2.5,cuda=11.2.1,cudnn=8.1,python3.7
接下来可以下载cudn和cundnn:
官网:https://developer.nvidia.com/cuda-toolkit-archive
下载对应版本exe文件打开默认安装就可;
验证是否安装成功:
官网:cuDNN Archive | NVIDIA Developer
把下载文件进行解压把bin+lib+include文件复制到C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2文件下;
进入环境变量设置(cuda会自动设置,如果没有的补全):
查看是否安装成功:
cd C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\extras\demo_suite
bandwidthTest.exe
安装tensorflow-gpu:
pip install tensorflow-gpu==2.5
最后我们找相关程序来验证一下:
第一步:
import tensorflow as tf
print(tf.__version__)
print('GPU', tf.test.is_gpu_available())
第二步:
# _*_ 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)
验证成功。
来源:https://blog.csdn.net/qq_25368751/article/details/125331026
标签:win10,RTX3050ti,TensorFlow,cudn,cudnn,深度学习
0
投稿
猜你喜欢
深入了解Vue组件七种通信方式
2024-04-27 16:03:01
Windows10下mysql 8.0.19 安装配置方法图文教程
2024-01-21 06:33:27
Python操作Excel插入删除行的方法
2023-08-05 21:13:50
python批量下载壁纸的实现代码
2023-11-09 18:13:05
python实现数字炸弹游戏程序
2021-09-29 18:44:24
python读取hdfs上的parquet文件方式
2021-04-07 11:54:31
利用Pytorch实现ResNet网络构建及模型训练
2022-02-24 19:57:59
Python将文字转成语音并读出来的实例详解
2021-11-08 21:23:34
带你快速搞定Mysql优化
2024-01-26 19:25:37
如何通过Python的pyttsx3库将文字转为音频
2023-01-11 19:54:59
Go语言实现RSA加解密算法详解
2024-02-08 12:20:55
SQL语句(T-SQL汇总) 用T-SQL画出这些图形
2024-01-13 15:24:35
详解Python模块化编程与装饰器
2023-06-30 19:49:07
验证码-挑战你的智慧
2008-09-10 13:08:00
PHP获取表单所有复选框的值的方法
2024-05-13 09:24:34
asp文章中随机插入网站版权文字的实现代码
2011-04-15 11:11:00
Python利用openpyxl库遍历Sheet的实例
2023-10-20 20:19:01
CentOS安装mysql5.7 及简单配置教程详解
2024-01-21 08:18:51
Django中提供的6种缓存方式详解
2023-03-24 14:55:49
Python模块介绍与使用详细讲解
2022-08-31 02:38:33