• Tensorflow安装GPU版本的一些问题处理


    好的习惯还是在虚拟环境中安装,先使用conda创建一个
    conda create -n tfgpu python=3.7

    然后进入环境
    activate tfgpu

    安装带GPU的Tensorflow,当然也可以指定版本来安装,指定镜像站点要快
    pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com --trusted-host pypi.douban.com tensorflow_gpu

    然后就来测试下是否安装成功

    1. import tensorflow as tf
    2. # 查看gpu和cpu的数量
    3. gpus = tf.config.experimental.list_physical_devices(device_type='GPU')
    4. cpus = tf.config.experimental.list_physical_devices(device_type='CPU')
    5. print(gpus, cpus)

     不出所料的话,一般都是如下的错误信息:

    2022-10-21 12:39:38.439442: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudnn64_8.dll'; dlerror: cudnn64_8.dll not found
    2022-10-21 12:39:38.439689: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1934] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
    Skipping registering GPU devices...

    cudnn64_8.dll没有找到,我们可以来到这个地方复制:

    C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin

    当然这里看自己安装的版本不一样有点区别,我这里是v10.2版本,你们根据自己的情况去找。

    将cudnn64_8.dll文件拷贝到 C:\Windows\System

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

     如果还不可以的话,那就重新安装cudnn
    conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0

    1. from tensorflow.python.client import device_lib
    2. # 列出全部的本地机器设备
    3. local_device_protos = device_lib.list_local_devices()
    4. print(local_device_protos)
    5. '''
    6. [name: "/device:CPU:0"
    7. device_type: "CPU"
    8. memory_limit: 268435456
    9. locality {
    10. }
    11. incarnation: 1203727834508357835
    12. xla_global_id: -1
    13. , name: "/device:GPU:0"
    14. device_type: "GPU"
    15. memory_limit: 1389330023
    16. locality {
    17. bus_id: 1
    18. links {
    19. }
    20. }
    21. incarnation: 4726776883789372381
    22. physical_device_desc: "device: 0, name: NVIDIA GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1"
    23. xla_global_id: 416903419
    24. ]
    25. '''
    1. # 只打印GPU设备
    2. [x for x in local_device_protos if x.device_type == 'GPU']
    3. '''
    4. [name: "/device:GPU:0"
    5. device_type: "GPU"
    6. memory_limit: 1389330023
    7. locality {
    8. bus_id: 1
    9. links {
    10. }
    11. }
    12. incarnation: 4726776883789372381
    13. physical_device_desc: "device: 0, name: NVIDIA GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1"
    14. xla_global_id: 416903419
    15. ]
    16. '''
  • 相关阅读:
    相机标定和双目相机标定标定原理推导及效果展示
    如何用工业智能网关/数据采集器采集西门子PLC
    实验四:面向对象编程实验(2)—封装、继承和包
    3.1 OrCAD中怎么创建新的原理图工程文件?OrCAD中原理图的设计纸张大小应该怎么设置?
    自动化测试下拉框选项定位报错
    CompletableFuture异步编程详解
    吴恩达深度学习笔记(二)——浅层神经网络
    突破“三个九”!离子阱量子计算再创新高
    【自动化测试】selenium工具
    数据分析:数据分析篇
  • 原文地址:https://blog.csdn.net/weixin_41896770/article/details/127444808