简体   繁体   English

如何使用Python在Windows上正确安装Tensorflow?

[英]How to install Tensorflow properly on Windows using Python?

I'm trying to use tensorflow with my PC's GPU (Nvidia RTX 3070Ti) in python-conda environment.我正在尝试在 python-conda 环境中将 tensorflow 与我的 PC GPU(Nvidia RTX 3070Ti)一起使用。 I'm solving a small image-classification problem from kaggle.我正在解决来自 kaggle 的一个小图像分类问题。 I've solved it in google-collab, but now I'm intrested in solving it on my local machine.我已经在 google-collab 中解决了它,但现在我有兴趣在我的本地机器上解决它。 However TF doesn't work properly locally and I have no idea why.但是 TF 在本地无法正常工作,我不知道为什么。 I've read tons of solutions but it didn't help yet.我已经阅读了大量的解决方案,但还没有帮助。

I'm following this guide and always install proper versions of TF and CUDA: https://www.tensorflow.org/install/source_windows我遵循本指南并始终安装正确版本的 TF 和 CUDA: https://www.tensorflow.org/install/source_windows

cuda-toolkit 10.1, cudnn 7.6, tf-gpu 2.3, python 3.8 cuda-toolkit 10.1, cudnn 7.6, tf-gpu 2.3, python 3.8

Also I've installed latest NVidia drivers for videocard.我还为视频卡安装了最新的 NVidia 驱动程序。

What I've tried:我试过的:

  1. I've installed proper version CUDA-toolkit and CUDnn from nvidia site.我已经从 nvidia 站点安装了正确版本的 CUDA-toolkit 和 CUDnn。 I've installed it properly and included everything that was needed into PATH.我已正确安装它并将所需的一切包含到 PATH 中。 I've checked it - MS Visiual Studio finds both CUDA and CUDnn and can work with it.我已经检查过 - MS Visiual Studio 找到 CUDA 和 CUDnn 并且可以使用它。 I've installed proper version of Tensorflow-GPU using conda into my environment.我已经使用 conda 在我的环境中安装了正确版本的 Tensorflow-GPU。

Result: TF can't find my GPU and uses only CPU.结果: TF 找不到我的 GPU 并且只使用 CPU。

  1. I've removed all CUDA and CUDAnn drivers.我已经删除了所有 CUDA 和 CUDAnn 驱动程序。 I've installed CUDA-toolkit, CUDnn and Tensorflow-GPU python packages into my conda environment.我已经在我的 conda 环境中安装了 CUDA-toolkit、CUDnn 和 Tensorflow-GPU python 包。

Result: TF recognizes my GPU and uses it: But during DNN training happens error: Failed to launch ptxas Relying on driver to perform ptx compilation. Modify $PATH to customize ptxas location.结果: TF 识别出我的 GPU 并使用它: 但是在 DNN 训练期间发生错误: Failed to launch ptxas Relying on driver to perform ptx compilation. Modify $PATH to customize ptxas location. Failed to launch ptxas Relying on driver to perform ptx compilation. Modify $PATH to customize ptxas location. And training goes very bad - accuracy is very low and doesn't improving.训练非常糟糕——准确性非常低而且没有提高。

When I use absolutely same code and data on google-collab, everything is going smoothly - I get ~90% accuracy on 5th epoch.当我在 google-collab 上使用完全相同的代码和数据时,一切都进行得很顺利——我在第 5 个 epoch 上获得了大约 90% 的准确率。

  1. I've tried tf 2.1 and relevant cuda and cudnn, but it's still same result!我试过 tf 2.1 和相关的 cuda 和 cudnn,但结果仍然相同!

  2. I've tried to install cudatoolkit-dev, but it didn't help to solve ptxas problem.我尝试安装 cudatoolkit-dev,但它并没有帮助解决 ptxas 问题。

I'm about to give up and use PyTorch instead of Tensorflow.我即将放弃并使用 PyTorch 而不是 Tensorflow。

So here is what worked for me:所以这对我有用:

  1. Create 3.9 python environment创建 3.9 python 环境
  2. Install cuda and tensorflow packages from "Esri":从“Esri”安装 cuda 和 tensorflow 包:
 conda install -c esri cudatoolkit conda install -c esri cudnn conda install -c esri tensorflow-gpu
  1. Then install tensorflow-hub:然后安装tensorflow-hub:
 conda install -c conda-forge tensorflow-hub

It will downgrade installations from previous steps, but it works.它会从之前的步骤中降级安装,但它可以工作。 Maybe installing tensorflow-hub first could help to avoid it, but I didn't test it.也许首先安装 tensorflow-hub 可以帮助避免它,但我没有测试它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM