移动端 3060 6G 配置 TensorFlow 和 Torch

前置条件

硬件条件

  R7-6800H + RTX3060(移动端)

检查方法

  检测 Tensorflow 是否检测得到 GPU,运行以下 Python 代码

import tensorflow as tf
gpus = tf.config.experimental.list_physical_devices(device_type='GPU')
cpus = tf.config.experimental.list_physical_devices(device_type='CPU')
print(gpus, cpus)

  如果运行结果为

[] [PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU')]

则说明 TF 没有检测到 GPU。

  检测 Pytorch 是否检测得到 GPU,运行以下 Python 代码

import torch
print(torch.cuda.is_available())  # 判断是否可以使用gpu计算
print(torch.cuda.device_count())  # 显示gpu数量

  如果运行结果为

False
0

则说明 Pytorch 没有检测到 GPU。

解决方法

  我是看了别的大佬的文章整理的1 2,作为笔记总结供自己日后参考,所以以下我只会直接给出对应的版本和安装指令。

  所有的包如果之前有下载过不同版本的,最好是先卸载再安装。

GPU 驱动

CUDA==10.1

  用 conda 下载安装,pip 不行,具体原因未知

conda install cudatoolkit=10.1

cudnn==7.6.5

  同样只能用 conda 下载安装

conda install cudnn=7.6

Tensorflow

tensorflow==2.3.0

  这里可以稍微注意一下,用 pip 安装 tensorflow 之前,最好确保 Python 版本在 3.5~3.8 之间3,否则可能会出现报错。

  这里就只能用 pip 下载安装了

pip install tensorflow-gpu==2.3.0

Pytorch

torch==1.8.1+cu101

  Pytorch 官网其实有提供官方的版本对齐文档4,由于上面我们的 CUDA 版本为 10.1,所以我直接选择了最新的对应 CUDA 10.1 的 torch 版本。

  这里可以在网页上 Ctrl+F 调出搜索框,然后直接搜索你要的版本。
在这里插入图片描述

# CUDA 10.1
pip install torch==1.8.1+cu101 torchvision==0.9.1+cu101 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

结果

  再次检查,Tensorflow 对应的输出变为

[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')] [PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU')]

Pytorch 对应的输出变为

True
1

则代表都检测成功了。


  1. RTX 3060 快速配置GPU版本tensorflow ↩︎

  2. 各版本对照表 ↩︎

  3. 安装tensorflow的Python版本要求 ↩︎

  4. CUDA 版本对应的 Pytorch 版本 ↩︎

最近更新

  1. TCP协议是安全的吗?

    2024-03-23 11:44:04       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-23 11:44:04       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-23 11:44:04       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-23 11:44:04       18 阅读

热门阅读

  1. Sql中如何添加数据

    2024-03-23 11:44:04       19 阅读
  2. 牛客笔试|美团2024春招第一场【测试方向】

    2024-03-23 11:44:04       31 阅读
  3. Learning to summarize from human feedback

    2024-03-23 11:44:04       17 阅读
  4. 红黑树(Red-Black Tree)

    2024-03-23 11:44:04       19 阅读
  5. linux docker镜像初始化

    2024-03-23 11:44:04       22 阅读
  6. THINKPHP仿Word 统计字数的方法

    2024-03-23 11:44:04       17 阅读
  7. Go使用Terraform 库

    2024-03-23 11:44:04       20 阅读
  8. tcp/ip中的粘包问题的处理逻辑

    2024-03-23 11:44:04       19 阅读
  9. 质量模型、软件测试流程和测试用例

    2024-03-23 11:44:04       22 阅读