首页 > 解决方案 > 如何设置虚拟环境来运行 tensorflow 基准测试

问题描述

我的目的是设置虚拟环境来运行tensorflow 基准测试,但是在运行以下代码后,我在最后一条语句中遇到错误。请问我应该怎么做才能解决这个问题?仅供参考:我使用的 Python 3.6.7 仅安装了 pip 和 virtualenv 包和 CUDA 9.2/cuDNN7(系统路径中的所有 dll)。

virtualenv venv
venv\scripts\activate
#now you should be in virtual environment
#install using pip
pip install tf-nightly-gpu

python
import tensorflow

错误信息:

>>> import tensorflow
Traceback (most recent call last):
  File "C:\MyWork\testarea\testvirtualenv\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\MyWork\testarea\testvirtualenv\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\MyWork\testarea\testvirtualenv\venv\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:\MyWork\testarea\testvirtualenv\venv\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "C:\MyWork\testarea\testvirtualenv\venv\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\MyWork\testarea\testvirtualenv\venv\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "C:\MyWork\testarea\testvirtualenv\venv\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\MyWork\testarea\testvirtualenv\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\MyWork\testarea\testvirtualenv\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\MyWork\testarea\testvirtualenv\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\MyWork\testarea\testvirtualenv\venv\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:\MyWork\testarea\testvirtualenv\venv\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "C:\MyWork\testarea\testvirtualenv\venv\lib\imp.py", line 343, 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.
>

标签: pythontensorflowbenchmarking

解决方案


刚写完问题就找到答案了。

在将 cudnn64_7.dll(CUDA 9.0 的 cuDNN 7.3.1)复制到 CUDA bin 目录之前将 CUDA 9.2 降级到 9.0 使其工作。

最后,以下脚本从两台不同的机器产生了两种不同的结果。

virtualenv venv
venv\scripts\activate
pip install tf-nightly-gpu    
python tf_cnn_benchmarks.py --num_gpus=1 --batch_size=32 --model=resnet50 --variable_update=parameter_server

带有 GTX 970 的第 7 代四核 i7

总图像/秒:78.16

AMD 1920X 与 GTX 1080

总图像/秒:147.77


推荐阅读