CPU:i7-4790k

显卡:GTX2060

Cuda 版本:11.3

Cunn版本: 11.6

Python版本:3.7.7

不想用anacoda,直接装 tensorflow

1.准备工作

  • 安装python3.7.7(之前安装好的)
  • 可以根据需要安装相应的版本,不建议安装最新版,python版本之间的代码兼容度不好。3.6~3.8可能比较合适。

  • 安装cuda和cudnn,参考:CUDA安装教程(超详细)_Billie使劲学的博客-CSDN博客_cuda安装
  • 我安装的是11.3版本。

    deviceQuery.exe 和 bandwithTest.exe测试通过。

  • 下载Tensorflow
  • 到官方下载  tensorflow · PyPI

    我下载的是 tensorflow-2.9.1-cp37-cp37m-win_amd64.whl

  •  安装组件
  • 安装Tensorflow之前,安装好以下支持模块

        A.Numpy: pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple

        B.mkl: pip install mkl -i https://pypi.tuna.tsinghua.edu.cn/simple

        C.protobuf pip install protobuf -i https://pypi.tuna.tsinghua.edu.cn/simple

    2.安装Tensorflow

       把 tensorflow-2.9.1-cp37-cp37m-win_amd64.whl 放到d盘根目录,打开命令行并转到D:\

       pip install tensorflow-2.9.1-cp37-cp37m-win_amd64.whl -i https://pypi.tuna.tsinghua.edu.cn/simple

    这样在安装过程中加载其他模块的时候,速度会非常快。

    3.测试

    import tensorflow as tf
    print("Tensorflow version:")
    print(tf.__version__)
    
    print("CPU/GPU devices for Tensorflow:")
    gpus = tf.config.experimental.list_physical_devices(device_type='GPU')
    cpus = tf.config.experimental.list_physical_devices(device_type='CPU')
    print(gpus)
    print(cpus)

    运行结果:

    Tensorflow version:
    2.9.1
    CPU/GPU devices for Tensorflow:
    [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
    [PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU')]

    至此安装完毕。

    IDE可以使用Visual Studio Code(小规模测试)

    或者Pycharm(程序较大很方便)

    来源:st01lsp

    物联沃分享整理
    物联沃-IOTWORD物联网 » Tensorflow 2.9.1安装笔记

    发表评论