经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 大数据/云/AI » TensorFlow » 查看文章
win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度学习环境的方法
来源:jb51  时间:2022/6/21 12:20:46  对本文有异议

避坑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:

  1. 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)

验证成功。

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

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号