是什么导致tensorflow导入如此缓慢? [英] What can cause the tensorflow import to be so slow?

查看:553
本文介绍了是什么导致tensorflow导入如此缓慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Tensorflow了一段时间了.最近,我的脚本运行得非常慢(> 80秒),而运行时间更早(<1秒).我将问题范围缩小到import tensorflow,仅此一项就耗费了所有时间(所有其他lib和ops都运行了<<<< <1秒).

I've been using tensorflow for quite some time. Recently my scripts run very slow (> 80 sec) as to earlier (< 1 sec). I narrowed the issue down to import tensorflow, which alone is taking all the time (all other libs and ops are running << 1 sec).

我可能有踪迹,但是我不知道该怎么做:当我在80秒的导入过程中键盘中断(Strg + C)执行时,通常是这样:

I might have a trace, but I don't know what to do with it: When I keyboard-interrupt (Strg+C) the execution during the 80 sec import, usually this is what comes up:

Traceback (most recent call last):
  File "/.../py_env/tf_unet/lib/python3.5/site.py", line 703, in <module>
    main()
  File "/.../py_env/tf_unet/lib/python3.5/site.py", line 694, in main
    execsitecustomize()
  File "/.../py_env/tf_unet/lib/python3.5/site.py", line 548, in execsitecustomize
    import sitecustomize
  File "/usr/lib/python3.5/sitecustomize.py", line 3, in <module>
    import apport_python_hook
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 954, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 896, in _find_spec
  File "<frozen importlib._bootstrap_external>", line 1139, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1113, in _get_spec
  File "<frozen importlib._bootstrap_external>", line 1225, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1264, in _fill_cache
KeyboardInterrupt

这是否意味着带有填充缓存"(_fill_cache)的内容是错误的?任何人都经历过吗?我可以以某种方式解决此问题吗?

Does this mean, something with "filling the caches" (_fill_cache) is wrong? Anyone experience with this? Can I fix this somehow?

到目前为止我已经尝试过的:

What I've tried so far:

我将import tensorflow分解为仅我需要的模块(from tensorflow import train/python_io/compat),没有任何改善.

I broke down import tensorflow to only modules I need (from tensorflow import train / python_io / compat), with no improvement.

我发现其他人抱怨import tensorflow速度过长在这里此处

I found other people complaining about long import tensorflow speed here, here and in the corresponding SO question, but in the range of < 10 sec and referring to specific modules (tf.contrib or tf.learn). So not much to learn from there. Also I am using tensorflow 1.4.0 which apparently fixed the problems described there.

仅供参考,我正在使用这段小代码来确定速度:

Just for reference, I am using this little piece of code to determine the speed:

from timeit import default_timer as timer
print('import tensorflow')
start = timer()
import tensorflow
end = timer()
print('Elapsed time: ' + str(end - start))

推荐答案

这可能不是导致此问题的唯一原因,但以我的经验当然可以发挥作用.由于我的TF虚拟环境位于网络驱动器上,因此导入Tensorflow时遇到了严重的问题.在这方面,将虚拟环境移动到本地硬盘上起到了很大的作用.

This is probably not the only reason that can cause this, but in my experience certainly plays a role. I had serious slowness in importing Tensorflow due to the fact that I had my TF virtual environment on a network drive. Moving the virtual environment to a local hard drive helped quite a bit in this respect.

您可以尝试执行适用于您的环境的类似操作.

You could try doing something similar that applies in your environment.

这篇关于是什么导致tensorflow导入如此缓慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆