本文整理汇总了Python中tensorflow.python.framework.load_library.load_op_library方法的典型用法代码示例。如果您正苦于以下问题:Python load_library.load_op_library方法的具体用法?Python load_library.load_op_library怎么用?Python load_library.load_op_library使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.framework.load_library
的用法示例。
在下文中一共展示了load_library.load_op_library方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _load_library
# 需要导入模块: from tensorflow.python.framework import load_library [as 别名]
# 或者: from tensorflow.python.framework.load_library import load_op_library [as 别名]
def _load_library(name, op_list=None):
"""Loads a .so file containing the specified operators.
Args:
name: The name of the .so file to load.
op_list: A list of names of operators that the library should have. If None
then the .so file's contents will not be verified.
Raises:
NameError if one of the required ops is missing.
NotFoundError if were not able to load .so file.
"""
filename = resource_loader.get_path_to_datafile(name)
library = load_library.load_op_library(filename)
for expected_op in (op_list or []):
for lib_op in library.OP_LIST.op:
if lib_op.name == expected_op:
break
else:
raise NameError(
'Could not find operator %s in dynamic library %s' %
(expected_op, name))
return library
示例2: load_op_library
# 需要导入模块: from tensorflow.python.framework import load_library [as 别名]
# 或者: from tensorflow.python.framework.load_library import load_op_library [as 别名]
def load_op_library(path):
"""Loads a contrib op library from the given path.
NOTE(mrry): On Windows, we currently assume that contrib op
libraries are statically linked into the main TensorFlow Python
extension DLL.
Args:
path: An absolute path to a shared object file.
Returns:
A Python module containing the Python wrappers for Ops defined in the
plugin.
"""
if os.name != 'nt':
path = resource_loader.get_path_to_datafile(path)
ret = load_library.load_op_library(path)
assert ret, 'Could not load %s' % path
return ret
else:
# NOTE(mrry):
return None
示例3: _load_library
# 需要导入模块: from tensorflow.python.framework import load_library [as 别名]
# 或者: from tensorflow.python.framework.load_library import load_op_library [as 别名]
def _load_library(name, op_list=None):
"""Loads a .so file containing the specified operators.
Args:
name: The name of the .so file to load.
op_list: A list of names of operators that the library should have. If None
then the .so file's contents will not be verified.
Raises:
NameError if one of the required ops is missing.
"""
try:
filename = resource_loader.get_path_to_datafile(name)
library = load_library.load_op_library(filename)
for expected_op in (op_list or []):
for lib_op in library.OP_LIST.op:
if lib_op.name == expected_op:
break
else:
raise NameError('Could not find operator %s in dynamic library %s' %
(expected_op, name))
except errors.NotFoundError:
logging.warning('%s file could not be loaded.', name)
示例4: get_tf_libs
# 需要导入模块: from tensorflow.python.framework import load_library [as 别名]
# 或者: from tensorflow.python.framework.load_library import load_op_library [as 别名]
def get_tf_libs(build_ext, lib_dirs, cpp_flags):
last_err = None
for tf_libs in [['tensorflow_framework'], []]:
try:
lib_file = test_compile(build_ext, 'test_tensorflow_libs',
library_dirs=lib_dirs, libraries=tf_libs,
extra_preargs=cpp_flags,
code=textwrap.dedent('''\
void test() {
}
'''))
from tensorflow.python.framework import load_library
load_library.load_op_library(lib_file)
return tf_libs
except (CompileError, LinkError):
last_err = 'Unable to determine -l link flags to use with TensorFlow (see error above).'
except Exception:
last_err = 'Unable to determine -l link flags to use with TensorFlow. ' \
'Last error:\n\n%s' % traceback.format_exc()
raise DistutilsPlatformError(last_err)
示例5: load_op_library
# 需要导入模块: from tensorflow.python.framework import load_library [as 别名]
# 或者: from tensorflow.python.framework.load_library import load_op_library [as 别名]
def load_op_library(path):
"""Loads a contrib op library from the given path.
NOTE(mrry): On Windows, we currently assume that some contrib op
libraries are statically linked into the main TensorFlow Python
extension DLL - use dynamically linked ops if the .so is present.
Args:
path: An absolute path to a shared object file.
Returns:
A Python module containing the Python wrappers for Ops defined in the
plugin.
"""
if os.name == 'nt':
# To avoid makeing every user_ops aware of windows, re-write
# the file extension from .so to .dll.
path = re.sub(r'\.so$', '.dll', path)
# Currently we have only some user_ops as dlls on windows - don't try
# to load them if the dll is not found.
# TODO(mrry): Once we have all of them this check should be removed.
if not os.path.exists(path):
return None
path = resource_loader.get_path_to_datafile(path)
ret = load_library.load_op_library(path)
assert ret, 'Could not load %s' % path
return ret
示例6: Load
# 需要导入模块: from tensorflow.python.framework import load_library [as 别名]
# 或者: from tensorflow.python.framework.load_library import load_op_library [as 别名]
def Load():
"""Load training ops library and return the loaded module."""
with _ops_lock:
global _training_ops
if not _training_ops:
ops_path = resource_loader.get_path_to_datafile(TRAINING_OPS_FILE)
logging.info('data path: %s', ops_path)
_training_ops = load_library.load_op_library(ops_path)
assert _training_ops, 'Could not load _training_ops.so'
return _training_ops
示例7: get_tf_abi
# 需要导入模块: from tensorflow.python.framework import load_library [as 别名]
# 或者: from tensorflow.python.framework.load_library import load_op_library [as 别名]
def get_tf_abi(build_ext, include_dirs, lib_dirs, libs, cpp_flags):
last_err = None
cxx11_abi_macro = '_GLIBCXX_USE_CXX11_ABI'
for cxx11_abi in ['0', '1']:
try:
lib_file = test_compile(build_ext, 'test_tensorflow_abi',
macros=[(cxx11_abi_macro, cxx11_abi)],
include_dirs=include_dirs, library_dirs=lib_dirs,
libraries=libs, extra_preargs=cpp_flags,
code=textwrap.dedent('''\
#include <string>
#include "tensorflow/core/framework/op.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/shape_inference.h"
void test() {
auto ignore = tensorflow::strings::StrCat("a", "b");
}
'''))
from tensorflow.python.framework import load_library
load_library.load_op_library(lib_file)
return cxx11_abi_macro, cxx11_abi
except (CompileError, LinkError):
last_err = 'Unable to determine CXX11 ABI to use with TensorFlow (see error above).'
except Exception:
last_err = 'Unable to determine CXX11 ABI to use with TensorFlow. ' \
'Last error:\n\n%s' % traceback.format_exc()
raise DistutilsPlatformError(last_err)
示例8: Load
# 需要导入模块: from tensorflow.python.framework import load_library [as 别名]
# 或者: from tensorflow.python.framework.load_library import load_op_library [as 别名]
def Load():
"""Load the data ops library and return the loaded module."""
with _ops_lock:
global _data_ops
if not _data_ops:
ops_path = resource_loader.get_path_to_datafile(DATA_OPS_FILE)
logging.info('data path: %s', ops_path)
_data_ops = load_library.load_op_library(ops_path)
assert _data_ops, 'Could not load _data_ops.so'
return _data_ops
示例9: Load
# 需要导入模块: from tensorflow.python.framework import load_library [as 别名]
# 或者: from tensorflow.python.framework.load_library import load_op_library [as 别名]
def Load():
"""Load the inference ops library and return the loaded module."""
with _ops_lock:
global _inference_ops
if not _inference_ops:
ops_path = resource_loader.get_path_to_datafile(INFERENCE_OPS_FILE)
logging.info('data path: %s', ops_path)
_inference_ops = load_library.load_op_library(ops_path)
assert _inference_ops, 'Could not load inference_ops.so'
return _inference_ops
示例10: load_library
# 需要导入模块: from tensorflow.python.framework import load_library [as 别名]
# 或者: from tensorflow.python.framework.load_library import load_op_library [as 别名]
def load_library(name):
"""Loads a .so file containing the specified operators.
Args:
name: The name of the .so file to load.
Raises:
NotFoundError if were not able to load .so file.
"""
filename = resource_loader.get_path_to_datafile(name)
library = _load_library.load_op_library(filename)
return library
示例11: get_tf_libs
# 需要导入模块: from tensorflow.python.framework import load_library [as 别名]
# 或者: from tensorflow.python.framework.load_library import load_op_library [as 别名]
def get_tf_libs(build_ext, lib_dirs, cpp_flags):
for tf_libs in [['tensorflow_framework'], []]:
try:
lib_file = test_compile(
build_ext,
'test_tensorflow_libs',
library_dirs=lib_dirs,
libraries=tf_libs,
extra_compile_preargs=cpp_flags,
code=textwrap.dedent('''\
void test() {
}
'''))
from tensorflow.python.framework import load_library
load_library.load_op_library(lib_file)
return tf_libs
except (CompileError, LinkError):
last_err = 'Unable to determine -l link flags to use with TensorFlow (see error above).'
except Exception:
last_err = 'Unable to determine -l link flags to use with TensorFlow. Last error:\n\n%s' % \
traceback.format_exc()
raise DistutilsPlatformError(last_err)
示例12: get_tf_abi
# 需要导入模块: from tensorflow.python.framework import load_library [as 别名]
# 或者: from tensorflow.python.framework.load_library import load_op_library [as 别名]
def get_tf_abi(build_ext, include_dirs, lib_dirs, libs, cpp_flags):
cxx11_abi_macro = '_GLIBCXX_USE_CXX11_ABI'
for cxx11_abi in ['0', '1']:
try:
lib_file = test_compile(build_ext, 'test_tensorflow_abi',
macros=[(cxx11_abi_macro, cxx11_abi)],
include_dirs=include_dirs,
library_dirs=lib_dirs,
libraries=libs,
extra_compile_preargs=cpp_flags,
code=textwrap.dedent('''\
#include <string>
#include "tensorflow/core/framework/op.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/shape_inference.h"
void test() {
auto ignore = tensorflow::strings::StrCat("a", "b");
}
''')
)
from tensorflow.python.framework import load_library
load_library.load_op_library(lib_file)
return cxx11_abi_macro, cxx11_abi
except (CompileError, LinkError):
last_err = 'Unable to determine CXX11 ABI to use with TensorFlow (see error above).'
except Exception:
last_err = 'Unable to determine CXX11 ABI to use with TensorFlow. ' \
'Last error:\n\n%s' % traceback.format_exc()
raise DistutilsPlatformError(last_err)
示例13: _load_platform_specific_library
# 需要导入模块: from tensorflow.python.framework import load_library [as 别名]
# 或者: from tensorflow.python.framework.load_library import load_op_library [as 别名]
def _load_platform_specific_library(self, lib_name):
system = platform.system()
if system == "Darwin":
lib_file_name = lib_name + ".dylib"
elif system == "Windows":
lib_file_name = lib_name + ".dll"
else:
lib_file_name = lib_name + ".so"
return load_library.load_op_library(lib_file_name)