• 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会自动设置,如果没有的补全):

    查看是否安装成功:

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

     

     安装tensorflow-gpu:

    pip install tensorflow-gpu==2.5

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

    第一步:

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

    第二步:

    1. # _*_ coding=utf-8 _*_
    2. '''
    3. @author: crazy jums
    4. @time: 2021-01-24 20:55
    5. @desc: 添加描述
    6. '''
    7. # 指定GPU训练
    8. import os
    9. os.environ["CUDA_VISIBLE_DEVICES"]="0" ##表示使用GPU编号为0的GPU进行计算
    10. import numpy as np
    11. from tensorflow.keras.models import Sequential # 采用贯序模型
    12. from tensorflow.keras.layers import Dense, Dropout, Conv2D, MaxPool2D, Flatten
    13. from tensorflow.keras.datasets import mnist
    14. from tensorflow.keras.utils import to_categorical
    15. from tensorflow.keras.callbacks import TensorBoard
    16. import time
    17. def create_model():
    18. model = Sequential()
    19. model.add(Conv2D(32, (5, 5), activation='relu', input_shape=[28, 28, 1])) # 第一卷积层
    20. model.add(Conv2D(64, (5, 5), activation='relu')) # 第二卷积层
    21. model.add(MaxPool2D(pool_size=(2, 2))) # 池化层
    22. model.add(Flatten()) # 平铺层
    23. model.add(Dropout(0.5))
    24. model.add(Dense(128, activation='relu'))
    25. model.add(Dropout(0.5))
    26. model.add(Dense(10, activation='softmax'))
    27. return model
    28. def compile_model(model):
    29. model.compile(loss='categorical_crossentropy', optimizer="adam", metrics=['acc'])
    30. return model
    31. def train_model(model, x_train, y_train, batch_size=32, epochs=10):
    32. tbCallBack = TensorBoard(log_dir="model", histogram_freq=1, write_grads=True)
    33. history = model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, shuffle=True, verbose=2,
    34. validation_split=0.2, callbacks=[tbCallBack])
    35. return history, model
    36. if __name__ == "__main__":
    37. import tensorflow as tf
    38. print(tf.__version__)
    39. from tensorflow.python.client import device_lib
    40. print(device_lib.list_local_devices())
    41. (x_train, y_train), (x_test, y_test) = mnist.load_data() # mnist的数据我自己已经下载好了的
    42. print(np.shape(x_train), np.shape(y_train), np.shape(x_test), np.shape(y_test))
    43. x_train = np.expand_dims(x_train, axis=3)
    44. x_test = np.expand_dims(x_test, axis=3)
    45. y_train = to_categorical(y_train, num_classes=10)
    46. y_test = to_categorical(y_test, num_classes=10)
    47. print(np.shape(x_train), np.shape(y_train), np.shape(x_test), np.shape(y_test))
    48. model = create_model()
    49. model = compile_model(model)
    50. print("start training")
    51. ts = time.time()
    52. history, model = train_model(model, x_train, y_train, epochs=2)
    53. print("start training", time.time() - ts)

     

    验证成功。

     这些资料请关注微信公众号:小王搬运工,后台回复22617,获取百度网盘链接。

     

     

  • 相关阅读:
    WPF实现类似ChatGPT的逐字打印效果
    在vscode运行java代码
    改element的单选框的样式,改成方形有勾的样式
    分布式软件架构——服务端缓存的三种属性
    LeetCode 695. 岛屿的最大面积
    Sketch for mac v98.3(ui设计矢量绘图)
    MySQL锁概述
    Prometheus简单理解
    图书管理系统 数据结构先导课暨C语言大作业复习 | JorbanS
    CHATGPT它它它它它崩了~
  • 原文地址:https://blog.csdn.net/qq_25368751/article/details/125331026