当前位置: 首页 > news >正文

python310 安装 tensorflow-gpu2.10

python310 安装 tensorflow-gpu2.10

工具 miniconda

环境准备

  1. 升级依赖库

    conda update --all
    
  2. 创建目录

    mkdir gpu-tf
    
  3. 进入目录

    cd gpu-tf
    
  4. 创建虚拟环境

    conda create -p tf210-310 python==3.10.16
    
  5. 激活虚拟环境

    conda activate D:\gpu-tf\tf210-310
    
  6. 重新安装pip

    python -m pip uninstall pip
    python -m ensurepip --upgrade
    
  7. 升级 setuptools wheel

    python -m pip install --upgrade pip setuptools wheel
    

安装cudacudnn

conda install cudatoolkit==11.3.1 cudnn==8.2.1

安装 numpy

解决版本兼容

pip install numpy==1.26.4

安装 tensorflow-gpu

pip install tensorflow-gpu==2.10.1

tensorflow-gpu

测试

  1. 控制台输入 python 进入 python 环境后输入以下内容:

    import tensorflow as tf# 打印TensorFlow版本信息
    print("TensorFlow version:", tf.__version__)# 检查GPU是否可用
    print("GPU is available:", end='\t' )
    print(tf.config.list_physical_devices('GPU'))
  2. 编写 python 文件,代码如下:

    import tensorflow as tf# 打印TensorFlow版本信息
    print("TensorFlow version:", tf.__version__)# 检查GPU是否可用
    if tf.config.list_physical_devices('GPU'):print("GPU is available")
    else:print("GPU is not available")# 使用tf.function装饰器自动将操作分配到GPU(如果可用)
    @tf.function
    def test_gpu():a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])c = tf.matmul(a, b)return c# 调用函数并打印结果
    result = test_gpu()
    print(result)
  3. 运行刚刚编写的 python 文件,输入内容如下: python310 安装 tensorflow-gpu2.10

相关文章:

  • 【c语言】字符函数和字符串函数
  • PostgreSQL数据表操作SQL
  • python3GUI--视频监控管理平台 By:PyQt5(详细讲解)
  • Python-pandas-json格式的数据操作(读取数据/写入数据)
  • 天车定位技术方案(基于无线脉冲技术)
  • C++11新特性_范围-based for 循环
  • 长成一个西瓜
  • 【业务领域】电脑网卡是主板还是cpu(主板的网卡是什么意思)
  • Sigmoid函数导数推导详解
  • 拆解 browser-use 项目——深入理解 Agent 层
  • CUDA从入门到放弃
  • 小结:ipsec-ike
  • 使用 MCP(模型上下文协议)和 Claude 在 Node.js 中构建聊天应用程序
  • Learning vtkjs之DepthTest
  • 21.2Linux中的LCD驱动实验(驱动)_csdn
  • [操作系统] 线程互斥
  • 大模型 Function Call
  • Unity SpriteEditor(精灵图片编辑器)
  • 24.Linux中RTC的驱动实验_csdn
  • 1.67g 雨晨 22635.5305 Windows 11 企业版 23H2 极速增强版
  • 保险经纪公司元保在纳斯达克挂牌上市,去年净赚4.36亿元
  • 国务院安委办、应急管理部进一步调度部署“五一”假期安全防范工作
  • 软硬件企业集中发布未成年人模式使用手册
  • 五一“拼假”催热超长假期,热门酒店民宿一房难求
  • 发布亮眼一季度报后,东阿阿胶股价跌停:现金流隐忧引发争议
  • 书业观察|一本书的颜值革命:从毛边皮面到爆火的刷边书