Tensorflow神奇的Bug:ImportError: dlopen: cannot load any more object with static TLS

时光总嘲笑我的痴心妄想 提交于 2020-01-13 23:02:20

(转载请私信或微信联系:moses_1994,请不要原文搬运了连声招呼都不打)

1. 背景

基本环境:anaconda 3.0 + python 3.6 + tensorflow  1.5.0

2. 问题描述

在服务器上安装了tensorflow  1.5.0版本,但是在载入的时候,出现了一个神奇的Bug,详情如下:

tensorflow的相关程序在 model.py 这个文件中,如果只在 main.py 中载入这个文件 from model import *,然后训练: python main.py ,那么程序不会报错。

但是如果再载入别的文件,例如 from feature import * ,那么不论这个载入语句在 from model import * 之前还是在其之后,运行 python main.py ,程序都会报错:ImportError: dlopen: cannot load any more object with static TLS

原始错误显示如下:

Using TensorFlow backend.
Traceback (most recent call last):
  File "/data00/home/labspeech_intern/anaconda3/envs/yuanbo_tf/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/data00/home/labspeech_intern/anaconda3/envs/yuanbo_tf/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/data00/home/labspeech_intern/anaconda3/envs/yuanbo_tf/lib/python3.6/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 "/data00/home/labspeech_intern/anaconda3/envs/yuanbo_tf/lib/python3.6/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "/data00/home/labspeech_intern/anaconda3/envs/yuanbo_tf/lib/python3.6/imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: dlopen: cannot load any more object with static TLS

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 11, in <module>
    from framework.model import train
  File "/data00/home/labspeech_intern/yuanbo/5_baseline_singing_voice_detection/framework/model.py", line 4, in <module>
    from keras.layers import Input, merge, Reshape, Dense
  File "/data00/home/labspeech_intern/.local/lib/python3.6/site-packages/keras/__init__.py", line 3, in <module>
    from . import utils
  File "/data00/home/labspeech_intern/.local/lib/python3.6/site-packages/keras/utils/__init__.py", line 6, in <module>
    from . import conv_utils
  File "/data00/home/labspeech_intern/.local/lib/python3.6/site-packages/keras/utils/conv_utils.py", line 9, in <module>
    from .. import backend as K
  File "/data00/home/labspeech_intern/.local/lib/python3.6/site-packages/keras/backend/__init__.py", line 87, in <module>
    from .tensorflow_backend import *
  File "/data00/home/labspeech_intern/.local/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 5, in <module>
    import tensorflow as tf
  File "/data00/home/labspeech_intern/anaconda3/envs/yuanbo_tf/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/data00/home/labspeech_intern/anaconda3/envs/yuanbo_tf/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/data00/home/labspeech_intern/anaconda3/envs/yuanbo_tf/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/data00/home/labspeech_intern/anaconda3/envs/yuanbo_tf/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/data00/home/labspeech_intern/anaconda3/envs/yuanbo_tf/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/data00/home/labspeech_intern/anaconda3/envs/yuanbo_tf/lib/python3.6/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 "/data00/home/labspeech_intern/anaconda3/envs/yuanbo_tf/lib/python3.6/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "/data00/home/labspeech_intern/anaconda3/envs/yuanbo_tf/lib/python3.6/imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: dlopen: cannot load any more object with static TLS


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

这个问题导致 main.py 主函数文件中只能导入 model.py 一个函数文件,意思是只能有 from model import * 这个语句,其他的都不能有。。。。。。这显然是不可能的,肯定还要调入别的函数文件啊

3. 解决方案

搜索了很多别的方法,大多说是和载入的顺序有关系,且这个问题大多出现在 pytorch 或 torch 的调用过程中,有时候 Matlab 好像也会有这个问题。但是我就是使用了简单的python啊,而且这是个纯 tensorflow 的环境,也没有安装 torch 或 pytorch 啊,更关键的是,相同的配置在别的服务器上从没遇到过这个问题啊,真是见了鬼了。

最终解决办法,升级 tensorflow 到 1.6 版本,就没有这个 Bug 了。

conda install --channel https://conda.anaconda.org/anaconda tensorflow=1.6.0

(在激活tensorflow环境后:source activate tensorflow,执行上面的语句,就没有问题了,Bug神奇的消失了)

真怀疑是不是 tensorflow 1.5 版本特有的问题。。。

如果大家有别的解决办法,欢迎留言交流。

 

 

 

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!