win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度学习环境的方法
作者:末世灯光 发布时间:2023-02-12 14:02:00
标签:win10,RTX3050ti,TensorFlow,cudn,cudnn,深度学习
避坑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


猜你喜欢
- 今天遇到多条件搜索,其中需要用到in查询,但是laravel不支持 [ 'type', 'in', '
- SQL Server如何通过SQL语句直接操作另一个SQL SERVER的数据1、 现在执行SQL语句的数据库服务器开启Ad Hoc Dis
- 在安装mha4mysql时,大概步骤是:解压,perl Makefile.PL,make, make install。在执行 perl Ma
- 简介pygame模块用于变换Surface,Surface变换是一种移动或调整像素大小的操作。所有这些函数都是对一个Surface进行操作,
- 存储过程简介----------------------------------------------------------------
- 搭建FTP,或者是搭建网络文件系统,这些方法都能够实现Linux的目录共享。但是FTP和网络文件系统的功能都过于强大,因此它们都有一些不够方
- Pytorch 使用GPU训练使用 GPU 训练只需要在原来的代码中修改几处就可以了。我们有两种方式实现代码在 GPU 上进行训练方法一 .
- 1. 前言由于公司的一个项目是基于B/S架构与WEB服务通信,使用XML数据作为通信数据,在添加新功能时,WEB端与客户端分别由不同的部门负
- 前言在本文中,您将学习如何使用 OpenCV 进行人脸识别。文章分三部分介绍:第一,将首先执行人脸检测,使用深度学习从每个人脸中提取人脸量化
- 每位SQL Server开发员都有自己的首选操作方法。我的方法叫做分子查询。这些是由原子查询组合起来的查询,通过它们我可以处理一个表格。将原
- 在python中,文件使用十分频繁,本文将向大家介绍python文件路径的操作:得到指定文件路径、得到当前文件名、判断文件路径是否存在、获得
- 偶然在Google发现了他们的用户体验设计原则,因此翻译作一下记录。1.以人为本 —他们的生活、他们的工作和他们的梦想2.珍惜每一毫秒的时间
- 一、认识h函数Vue推荐在绝大数情况下使用模板来创建你的HTML,然后一些特殊的场景,你真的需要JavaScript的完全编程的能力,这个时
- "合成大西瓜"这个游戏在年前很火热,还上过微博热搜,最近便玩了一阵还挺有意思的,所以研究了一下小球碰撞原理,自己亲自手写
- 一、闭包1.1 三要素 必须有一个内嵌函数内嵌函数必须引用外部函数中变量外部函数返回值必须是内嵌函数1.2 语法# 语法def 外部函数名(
- 如下所示:from PIL import Image########获取图片指定像素点的像素def getPngPix(pngPath =
- oracle排序后如何获取第一条数据场景想要获取下列sql的数据的第一条select NEXT_FOLLOWUP_DATE fr
- 实现代码如下:# -*- coding: utf-8 -*-import math, random,timeimport threading
- 本文实例分析了python字典排序的方法。分享给大家供大家参考。具体如下:1、 准备知识:在python里,字典dictionary是内置的
- 一、python线程的模块1.thread和threading模块thread模块提供了基本的线程和锁的支持threading提供了更高级别