LD_LIBRARY_PATH, sys.path, tf.load_op_library的一个bug

python 中,

compute_depth_module = tf.load_op_library('libcompute_depth.so')

On POSIX platforms, TF_LoadLibrary just calls dlopen, 所以

1 要设置LD_LIBRARY_PATH, 来解决路径

2 根据当前工作路径,设置相对路径,可以load

3.设置全路径,发现在python中,有时候会有问题。如在项目https://github.com/cogaplex-bts/bts, 中,models/bts_nyu/bts_nyu.py中,

compute_depth_module = tf.load_op_library('libcompute_depth.so'),把so设置为全路径,在一个进程中,第一次会成功,第二次tf.load_op_library, load tensorflow op_list就为空, 如果换成相对路径就没有问题,如

/mnt/c/silva/work/aiex/depth/custom_layer/build/libcompute_depth.so

compute_depth_module {'__name__': '670cc8cfec5b6d3b8635f39bd583d769', '__doc__': 'Python wrappers around TensorFlow ops.\n\nThis file is MACHINE GENERATED! Do not edit.\n', '__package__': None, '__loader__': None, '__spec__': None, '__builtins__': {'__name__': 'builtins', '__doc__': "Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is the `nil' object; Ellipsis represents `...' in slices.", '__package__': '', '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__': ModuleSpec(name='builtins', loader=<class '_frozen_importlib.BuiltinImporter'>), '__build_class__': <built-in function __build_class__>, '__import__': <built-in function __import__>, 'abs': <built-in function abs>, 'all': <built-in function all>, 'any': <built-in function any>, 'ascii': <built-in function ascii>, 'bin': <built-in function bin>, 'breakpoint': <built-in function breakpoint>, 'callable': <built-in function callable>, 'chr': <built-in function chr>, 'compile': <built-in function compile>, 'delattr': <built-in function delattr>, 'dir': <built-in function dir>, 'divmod': <built-in function divmod>, 'eval': <built-in function eval>, 'exec': <built-in function exec>, 'format': <built-in function format>, 'getattr': <built-in function getattr>, 'globals': <built-in function globals>, 'hasattr': <built-in function hasattr>, 'hash': <built-in function hash>, 'hex': <built-in function hex>, 'id': <built-in function id>, 'input': <built-in function input>, 'isinstance': <built-in function isinstance>, 'issubclass': <built-in function issubclass>, 'iter': <built-in function iter>, 'len': <built-in function len>, 'locals': <built-in function locals>, 'max': <built-in function max>, 'min': <built-in function min>, 'next': <built-in function next>, 'oct': <built-in function oct>, 'ord': <built-in function ord>, 'pow': <built-in function pow>, 'print': <built-in function print>, 'repr': <built-in function repr>, 'round': <built-in function round>, 'setattr': <built-in function setattr>, 'sorted': <built-in function sorted>, 'sum': <built-in function sum>, 'vars': <built-in function vars>, 'None': None, 'Ellipsis': Ellipsis, 'NotImplemented': NotImplemented, 'False': False, 'True': True, 'bool': <class 'bool'>, 'memoryview': <class 'memoryview'>, 'bytearray': <class 'bytearray'>, 'bytes': <class 'bytes'>, 'classmethod': <class 'classmethod'>, 'complex': <class 'complex'>, 'dict': <class 'dict'>, 'enumerate': <class 'enumerate'>, 'filter': <class 'filter'>, 'float': <class 'float'>, 'frozenset': <class 'frozenset'>, 'property': <class 'property'>, 'int': <class 'int'>, 'list': <class 'list'>, 'map': <class 'map'>, 'object': <class 'object'>, 'range': <class 'range'>, 'reversed': <class 'reversed'>, 'set': <class 'set'>, 'slice': <class 'slice'>, 'staticmethod': <class 'staticmethod'>, 'str': <class 'str'>, 'super': <class 'super'>, 'tuple': <class 'tuple'>, 'type': <class 'type'>, 'zip': <class 'zip'>, '__debug__': True, 'BaseException': <class 'BaseException'>, 'Exception': <class 'Exception'>, 'TypeError': <class 'TypeError'>, 'StopAsyncIteration': <class 'StopAsyncIteration'>, 'StopIteration': <class 'StopIteration'>, 'GeneratorExit': <class 'GeneratorExit'>, 'SystemExit': <class 'SystemExit'>, 'KeyboardInterrupt': <class 'KeyboardInterrupt'>, 'ImportError': <class 'ImportError'>, 'ModuleNotFoundError': <class 'ModuleNotFoundError'>, 'OSError': <class 'OSError'>, 'EnvironmentError': <class 'OSError'>, 'IOError': <class 'OSError'>, 'EOFError': <class 'EOFError'>, 'RuntimeError': <class 'RuntimeError'>, 'RecursionError': <class 'RecursionError'>, 'NotImplementedError': <class 'NotImplementedError'>, 'NameError': <class 'NameError'>, 'UnboundLocalError': <class 'UnboundLocalError'>, 'AttributeError': <class 'AttributeError'>, 'SyntaxError': <class 'SyntaxError'>, 'IndentationError': <class 'IndentationError'>, 'TabError': <class 'TabError'>, 'LookupError': <class 'LookupError'>, 'IndexError': <class 'IndexError'>, 'KeyError': <class 'KeyError'>, 'ValueError': <class 'ValueError'>, 'UnicodeError': <class 'UnicodeError'>, 'UnicodeEncodeError': <class 'UnicodeEncodeError'>, 'UnicodeDecodeError': <class 'UnicodeDecodeError'>, 'UnicodeTranslateError': <class 'UnicodeTranslateError'>, 'AssertionError': <class 'AssertionError'>, 'ArithmeticError': <class 'ArithmeticError'>, 'FloatingPointError': <class 'FloatingPointError'>, 'OverflowError': <class 'OverflowError'>, 'ZeroDivisionError': <class 'ZeroDivisionError'>, 'SystemError': <class 'SystemError'>, 'ReferenceError': <class 'ReferenceError'>, 'MemoryError': <class 'MemoryError'>, 'BufferError': <class 'BufferError'>, 'Warning': <class 'Warning'>, 'UserWarning': <class 'UserWarning'>, 'DeprecationWarning': <class 'DeprecationWarning'>, 'PendingDeprecationWarning': <class 'PendingDeprecationWarning'>, 'SyntaxWarning': <class 'SyntaxWarning'>, 'RuntimeWarning': <class 'RuntimeWarning'>, 'FutureWarning': <class 'FutureWarning'>, 'ImportWarning': <class 'ImportWarning'>, 'UnicodeWarning': <class 'UnicodeWarning'>, 'BytesWarning': <class 'BytesWarning'>, 'ResourceWarning': <class 'ResourceWarning'>, 'ConnectionError': <class 'ConnectionError'>, 'BlockingIOError': <class 'BlockingIOError'>, 'BrokenPipeError': <class 'BrokenPipeError'>, 'ChildProcessError': <class 'ChildProcessError'>, 'ConnectionAbortedError': <class 'ConnectionAbortedError'>, 'ConnectionRefusedError': <class 'ConnectionRefusedError'>, 'ConnectionResetError': <class 'ConnectionResetError'>, 'FileExistsError': <class 'FileExistsError'>, 'FileNotFoundError': <class 'FileNotFoundError'>, 'IsADirectoryError': <class 'IsADirectoryError'>, 'NotADirectoryError': <class 'NotADirectoryError'>, 'InterruptedError': <class 'InterruptedError'>, 'PermissionError': <class 'PermissionError'>, 'ProcessLookupError': <class 'ProcessLookupError'>, 'TimeoutError': <class 'TimeoutError'>, 'open': <built-in function open>, 'quit': Use quit() or Ctrl-D (i.e. EOF) to exit, 'exit': Use exit() or Ctrl-D (i.e. EOF) to exit, 'copyright': Copyright (c) 2001-2019 Python Software Foundation.
All Rights Reserved.

Copyright (c) 2000 BeOpen.com.
All Rights Reserved.

Copyright (c) 1995-2001 Corporation for National Research Initiatives.
All Rights Reserved.

Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
All Rights Reserved., 'credits':     Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information., 'license': Type license() to see the full license text, 'help': Type help() for interactive help, or help(object) for help about object.}, '_collections': <module 'collections' from '/home/silva/anaconda3/envs/py372/lib/python3.7/collections/__init__.py'>, '_six': <module 'six' from '/home/silva/anaconda3/envs/py372/lib/python3.7/site-packages/six.py'>, '_pywrap_tensorflow': <module 'tensorflow.python.pywrap_tensorflow' from '/home/silva/anaconda3/envs/py372/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow.py'>, '_context': <module 'tensorflow.python.eager.context' from '/home/silva/anaconda3/envs/py372/lib/python3.7/site-packages/tensorflow/python/eager/context.py'>, '_core': <module 'tensorflow.python.eager.core' from '/home/silva/anaconda3/envs/py372/lib/python3.7/site-packages/tensorflow/python/eager/core.py'>, '_execute': <module 'tensorflow.python.eager.execute' from '/home/silva/anaconda3/envs/py372/lib/python3.7/site-packages/tensorflow/python/eager/execute.py'>, '_dtypes': <module 'tensorflow.python.framework.dtypes' from '/home/silva/anaconda3/envs/py372/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py'>, '_errors': <module 'tensorflow.python.framework.errors' from '/home/silva/anaconda3/envs/py372/lib/python3.7/site-packages/tensorflow/python/framework/errors.py'>, '_tensor_shape': <module 'tensorflow.python.framework.tensor_shape' from '/home/silva/anaconda3/envs/py372/lib/python3.7/site-packages/tensorflow/python/framework/tensor_shape.py'>, '_op_def_pb2': <module 'tensorflow.core.framework.op_def_pb2' from '/home/silva/anaconda3/envs/py372/lib/python3.7/site-packages/tensorflow/core/framework/op_def_pb2.py'>, '_common_shapes': <module 'tensorflow.python.framework.common_shapes' from '/home/silva/anaconda3/envs/py372/lib/python3.7/site-packages/tensorflow/python/framework/common_shapes.py'>, '_op_def_registry': <module 'tensorflow.python.framework.op_def_registry' from '/home/silva/anaconda3/envs/py372/lib/python3.7/site-packages/tensorflow/python/framework/op_def_registry.py'>, '_ops': <module 'tensorflow.python.framework.ops' from '/home/silva/anaconda3/envs/py372/lib/python3.7/site-packages/tensorflow/python/framework/ops.py'>, '_op_def_library': <module 'tensorflow.python.framework.op_def_library' from '/home/silva/anaconda3/envs/py372/lib/python3.7/site-packages/tensorflow/python/framework/op_def_library.py'>, 'deprecated_endpoints': <function deprecated_endpoints at 0x7f4cc150d710>, '_dispatch': <module 'tensorflow.python.util.dispatch' from '/home/silva/anaconda3/envs/py372/lib/python3.7/site-packages/tensorflow/python/util/dispatch.py'>, 'tf_export': functools.partial(<class 'tensorflow.python.util.tf_export.api_export'>, api_name='tensorflow'), '_InitOpDefLibrary': <function _InitOpDefLibrary at 0x7f4c8fadb560>, '_op_def_lib': <tensorflow.python.framework.op_def_library.OpDefLibrary object at 0x7f4c8fad6a90>, 'LIB_HANDLE': <Swig Object of type 'TF_Library *' at 0x7f4c8fac57b0>, 'OP_LIST': }

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值