【问题标题】:Problem when running tensorflow in venv (virtual enviromnemt)在venv(虚拟环境)中运行tensorflow时出现问题
【发布时间】:2022-01-07 11:34:05
【问题描述】:

(环境 - Windows10,使用 NVIDIA gpu,Powershell)

我想在虚拟环境中运行下面的示例代码

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense

model = Sequential()
model.add(Dense(100, activation='relu', 
                input_shape=(32,32,1)))
model.add(Dense(50, activation='relu'))
model.add(Dense(5, activation='softmax'))

model.summary()

代码执行时出现注册GPU失败的错误,但不使用GPU执行成功。

(venv) PS E:\lolol> & e:/lolol/venv/Scripts/python.exe e:/lolol/testcode2.py
2021-12-01 03:35:40.545756: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-12-01 03:35:40.546020: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2021-12-01 03:35:45.107760: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-12-01 03:35:45.108720: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cublas64_11.dll'; dlerror: cublas64_11.dll not found
2021-12-01 03:35:45.109629: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cublasLt64_11.dll'; dlerror: cublasLt64_11.dll not found
2021-12-01 03:35:45.110607: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cufft64_10.dll'; dlerror: cufft64_10.dll not found
2021-12-01 03:35:45.111655: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'curand64_10.dll'; dlerror: curand64_10.dll not found
2021-12-01 03:35:45.112802: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cusolver64_11.dll'; dlerror: cusolver64_11.dll not found
2021-12-01 03:35:45.113631: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cusparse64_11.dll'; dlerror: cusparse64_11.dll not found
2021-12-01 03:35:45.114479: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudnn64_8.dll'; dlerror: cudnn64_8.dll not found
2021-12-01 03:35:45.114979: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1850] 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...
2021-12-01 03:35:45.116383: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Model: "sequential"
_________________________________________________________________
 Layer (type)                Output Shape              Param #
=================================================================
 dense (Dense)               (None, 32, 32, 100)       200

 dense_1 (Dense)             (None, 32, 32, 50)        5050

 dense_2 (Dense)             (None, 32, 32, 5)         255

=================================================================
Total params: 5,505
Trainable params: 5,505
Non-trainable params: 0

我知道在虚拟环境中运行tensorflow的时候应该安装CUDA,所以我安装了,但是还是不能正常运行。

可能CUDA安装在默认安装路径C盘,而venv文件夹安装在另一个盘E盘,所以好像有问题。我认为 CUDA 应该安装在带有 VENV 的驱动器上,但我不确定该程序的确切安装位置。在 VENV 文件夹中? E盘的任何地方?

【问题讨论】:

  • 你安装Cudnn了吗??

标签: tensorflow virtual


【解决方案1】:

Tensorflow 表示这里需要 CUDA 11.0(在“cudartxx_110”和“cublas_110”中,“110”=11.0 是需要的版本)。你有确切的好版本吗?使用ls /usr/local/cuda* 进行检查。此外,您需要 8.0 版的 CudNN,否则您的 tensorflow 无法在 GPU 上运行。 您可以查看这个非常有用的链接以获取每个 tensorflow 版本所需的 CUDA/CuDNN 版本:https://www.tensorflow.org/install/source#gpu(这里您似乎有 tf 2.4) 我推荐你 Python>=3.7 + Cuda 11.2 + CuDNN 8.1(这是我所拥有的),然后你可以在你的环境中运行最新版本的 tf(+ Pytorch 甚至 JAX)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多