简体   繁体   中英

Error when using tensorflow-gpu 2.0.0-alpha0 in python3.7

I have followed the instructions shown on tensorflow's website to the absolute letter, yet I still get the following error when trying to import tensorflow in python:

Traceback (most recent call last):
File "C:\Users\redacted\source\Repos\TFTest1\TFTest1\tf2-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module> from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\redacted\source\Repos\TFTest1\TFTest1\tf2-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>     _pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\redacted\source\Repos\TFTest1\TFTest1\tf2-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper     _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\imp.py", line 242, in load_module     return load_dynamic(name, filename, file)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\imp.py", line 342, in load_dynamic     return _load(spec) ImportError: DLL load failed: The specified module could not be found.
Failed to load the native TensorFlow runtime.  See https://www.tensorflow.org/install/errors  for some common reasons and solutions.  Include the entire stack trace above this error message when asking for help.

which is thrown when I run the following code

import tensorflow as tf

My setup is as follows:

  • Windows 10
  • AMD 2700X CPU
  • Nvidia RTX 2080 GPU
  • Python 3.7 (64bit)
  • CUDA Toolkit 10.0
  • CUDAnn 7.5.1 (for CUDA 10.0)

I have the following in my User-Scoped PATH environment variable:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\extras\CUPTI\libx64
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include
C:\tools\cuda\bin

I have then been able to confirm that CUDA is properly installed by running the following in the command line:

nvcc -V

which shows me

nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2018 NVIDIA
Corporation Built on Sat_Aug_25_21:08:04_Central_Daylight_Time_2018
Cuda compilation tools, release 10.0, V10.0.130

I'm using Visual Studio 2019 to run the python scripts in a fresh virtual environment (With python version 3.7). In that environment I have run the following command:

pip install tensorflow-gpu==2.0.0-alpha0

which installed various packages, and in that environment I get the aforementioned error.

As a side note my script runs just fine when using CPU only tensorflow. In a python 3.7 environment with the added package pip install tensorflow==2.0.0-alpha0 it all works, but it's running on my CPU, and slowly!

The Two-fold Question:

  • How can I get tensorflow 2.0 to do its work on the GPU rather than the CPU?
  • Is my setup correct for tensorflow 2.0 GPU?

I was able to solve my problem by having the exact same setup as I described in my original post, but instead used Python 3.6 instead of 3.7. All other variables remained the same. (Thank to Peter for helping find the answer!)

I started with a fresh environment in Visual Studio 2019 and ran the following imports:

pip install tensorflow-gpu==2.0.0-alpha0

I was then able to run my code on the CPU and GPU. I confirmed the GPU was available to tensorflow by running:

from tensorflow.python.client import device_lib

print(device_lib.list_local_devices())

which displayed

[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 18233115335171708614
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 6588081767
locality {
  bus_id: 1
  links {
  }
}
incarnation: 12253248400045769946
physical_device_desc: "device: 0, name: GeForce RTX 2080, pci bus id: 0000:1d:00.0, compute capability: 7.5"
]

I could also see that CPU usage was at 25% and the GPU usage was at 10% using Task Manager. I suppose my neural network is somewhat linear and cannot really make full use of the GPU quite yet.

Problem solved!

New GPU? Had the same problem couple of weeks ago. Took me hours to find the problem. Here are some ideas:

As of April 2019, I solved the "DLL load failed" problem under Windows 10 / Python 3.6.x / GPU RTX 20xx by installing CUDA 10.0 ( not 10.1 or 9.x!!! ) with cuDNN 7.5.0. I also have Visual Studio 2015 installed.

Make sure its CUDA 10.0!! Place the files from cuDNN in the respective dirs of your CUDA installation. Don't forget to add the location of your cuDNN *.dll files (the /bin/ folder of your CUDA installation) to your PATH (win environment variables).

Tensorflow can be installed using pip install tensorflow-gpu (as of April version 1.13.1). TF 2.0 should work the same way. Your problem seems to be related to CUDA. However, if there is no specific reason why you need TF 2.0, I would go with the standard installation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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