欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 幼教 > python310 安装 tensorflow-gpu2.10

python310 安装 tensorflow-gpu2.10

2025/9/23 1:21:21 来源:https://blog.csdn.net/qq_24330181/article/details/147653471  浏览:    关键词: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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词