python - 如何设置虚拟环境来运行 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.
>
解决方案
刚写完问题就找到答案了。
在将 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
推荐阅读
- elasticsearch - 产生空响应的脚本字段
- javascript - 单击 dxtextbox 时,将 dxtextbox (devextreme) 设为只读
- simulation - Gem5:全系统模拟恐慌情况!e发生:未能找到内核符号“恐慌”
- node.js - 绕过 NPM 缓存,如果我要查找的模块不存在
- android - 有没有办法在我自己的 Android Studio 应用程序中使用 Geogebra Figures
- javascript - Glide.js // Glide 没有定义
- swift - 如何将数据从 Playground 页面传递到 Swift Playgrounds 中的另一个 Playground 页面?
- angular - Angular Material mat-table 不会在数据源更新时重新加载数据
- jquery - 为什么在 JQuery 脚本中返回 False 会阻止信息进入 SQL 数据库
- arrays - Ruby 无需太多代码修改即可检索具有对数的邮件