当前位置: 首页>>代码示例>>Python>>正文


Python tensorflow.__file__方法代码示例

本文整理汇总了Python中tensorflow.__file__方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.__file__方法的具体用法?Python tensorflow.__file__怎么用?Python tensorflow.__file__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow的用法示例。


在下文中一共展示了tensorflow.__file__方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _custom_cpp_op

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import __file__ [as 别名]
def _custom_cpp_op(op: CompilableOp, stateful, name):
    """ Compiles and registers a custom C++ Tensorflow operator """
    # Compile the .so file
    tf_path = os.path.abspath(os.path.dirname(tf.__file__))
    
    so_file = TFCompiler().compile_op(op.name, op.files, 
        op.inputs, op.outputs,
        any([f.endswith('.cu') for f in op.files]), op.live_output,  
        additional_cmake_options=['-DTENSORFLOW_PATH=' + tf_path] + op.cmake_options,
        additional_definitions=op.defs, output_folder=op.output_folder)

    # Load the compiled library into Tensorflow
    op_module = tf.load_op_library(so_file)
    op_func = getattr(op_module, 'tf_op' + op.name)
    op_grad_func = getattr(op_module, 'tf_op_grad' + op.name)
    
    # Create the deep500 custom op object
    lib = ctypes.CDLL(so_file)
    if not getattr(lib, 'create_new_op', False):
        raise ValueError('Invalid custom operator library file')
    lib.create_new_op.restype = ctypes.c_int64
    lib.is_cuda_supported.restype = ctypes.c_bool
    lib.report.restype = ctypes.c_int64

    return TFCompiledOp(op, op_func, op_grad_func, lib) 
开发者ID:deep500,项目名称:deep500,代码行数:27,代码来源:tf.py

示例2: get_include

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import __file__ [as 别名]
def get_include():
  """Get the directory containing the TensorFlow C++ header files.

  Returns:
    The directory as string.
  """
  # Import inside the function.
  # sysconfig is imported from the tensorflow module, so having this
  # import at the top would cause a circular import, resulting in
  # the tensorflow module missing symbols that come after sysconfig.
  import tensorflow as tf
  return _os_path.join(_os_path.dirname(tf.__file__), 'include') 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:14,代码来源:sysconfig.py

示例3: get_lib

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import __file__ [as 别名]
def get_lib():
  """Get the directory containing the TensorFlow framework library.

  Returns:
    The directory as string.
  """
  import tensorflow as tf
  return _os_path.join(_os_path.dirname(tf.__file__), 'core') 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:10,代码来源:sysconfig.py

示例4: create_wrapper

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import __file__ [as 别名]
def create_wrapper(self, opname: str, dirname: str,
                       input_tensors: List[TensorDescriptor], 
                       output_tensors: List[TensorDescriptor],
                       is_cuda: bool, files: List[str]):
        curpath = os.path.abspath(os.path.dirname(__file__))
        ext = ('.cpp' if not is_cuda else '.cu')

        # Read wrapper template
        template_file = os.path.join(curpath, 'tf.tmpl.cpp')
        with open(template_file, 'r') as f:
            tmpl = Template(f.read())

        # Render template with tensor types
        pfile = tmpl.render(input_tensors=_ctup(input_tensors, 'inp'), 
            output_tensors=_ctup(output_tensors, 'out'),
            output_shapes=[s.shape for s in output_tensors],
            nextop_grads=_ctup(output_tensors, 'nxtgrad'),
            input_grads=_ctup(input_tensors, 'inpgrad'),
            input_shapes=[s.shape for s in input_tensors],
            platforms=([('DEVICE_CPU', ''), ('DEVICE_GPU', 'Cuda')] if is_cuda else [('DEVICE_CPU', '')]),
            opfile='"' + os.path.abspath(files[0]) + '"',
            opname=opname)

        # Try to create a directory for the wrapper file
        try:
            os.makedirs(dirname)
        except (OSError, FileExistsError):
            pass

        wrapper_filename = os.path.join(dirname, 'tf' + ext)
        with open(wrapper_filename, 'w') as fp:
            fp.write(pfile)

        return [os.path.abspath(wrapper_filename)] 
开发者ID:deep500,项目名称:deep500,代码行数:36,代码来源:tf.py

示例5: compile_op

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import __file__ [as 别名]
def compile_op(self, name: str, files: List[str],
                   input_tensors: List[TensorDescriptor], 
                   output_tensors: List[TensorDescriptor],
                   is_cuda: bool,
                   live_output: bool, 
                   additional_cmake_options: List[str], 
                   additional_definitions: Dict[str, str],
                   output_folder: str):
        cmakelists_path = os.path.dirname(os.path.abspath(__file__))

        # Create output folder
        dirname = os.path.join(output_folder, '%s_%s_build' % (name, 'tf'))
    
        # CUDA-specific macro
        defs = {}
        defs.update(additional_definitions)
        if is_cuda:
            defs.update({'__D500_OPHASCUDA': 1})
        print('iscuda', is_cuda)
    
        # Create wrapper template
        wrapper_files = self.create_wrapper(name, dirname, input_tensors, 
                                            output_tensors, 
                                            is_cuda, files)

        # Compile dynamic library (and ignore main file, which is part of the wrapper)
        return cmake(name, files[1:] + wrapper_files, cmakelists_path, dirname,
                     live_output=live_output, 
                     additional_cmake_options=additional_cmake_options,
                     additional_definitions=defs) 
开发者ID:deep500,项目名称:deep500,代码行数:32,代码来源:tf.py

示例6: get_lib

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import __file__ [as 别名]
def get_lib():
  """Get the directory containing the TensorFlow framework library.

  Returns:
    The directory as string.
  """
  import tensorflow as tf
  return _os_path.join(_os_path.dirname(tf.__file__)) 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:10,代码来源:sysconfig.py

示例7: main

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import __file__ [as 别名]
def main():
  cmd_args = argparse.ArgumentParser()
  cmd_args.add_argument("--include-tensorflow", action="store_true")
  cmd_args.add_argument("--output-dir", required=True)
  args = cmd_args.parse_args()
  if not os.path.isdir(args.output_dir):
    raise EnvironmentError(
        "Output directory {} doesn't exist".format(args.output_dir))
  elif not args.output_dir.startswith("/"):
    raise EnvironmentError("Please pass an absolute path to --output-dir.")

  tmp_packaging = tempfile.mkdtemp()
  runfiles, = (path for path in sys.path
               if path.endswith("build_pip_package.runfiles"))

  # Use the dragnn and tensorflow modules to resolve specific paths in the
  # runfiles directory. Current Bazel puts dragnn in a __main__ subdirectory,
  # for example.
  lib_path = os.path.abspath(dragnn.__file__)
  if runfiles not in lib_path:
    raise EnvironmentError("WARNING: Unexpected PYTHONPATH set by Bazel :(")
  base_dir = os.path.dirname(os.path.dirname(lib_path))
  tensorflow_dir = os.path.dirname(tensorflow.__file__)
  if runfiles not in tensorflow_dir:
    raise EnvironmentError("WARNING: Unexpected tf PYTHONPATH set by Bazel :(")

  # Copy the files.
  subprocess.check_call([
      "cp", "-r", os.path.join(base_dir, "dragnn"), os.path.join(
          base_dir, "syntaxnet"), tmp_packaging
  ])
  if args.include_tensorflow:
    subprocess.check_call(
        ["cp", "-r", tensorflow_dir, tmp_packaging])
  shutil.copy(
      os.path.join(base_dir, "dragnn/tools/oss_setup.py"),
      os.path.join(tmp_packaging, "setup.py"))
  subprocess.check_output(
      ["python", "setup.py", "bdist_wheel"], cwd=tmp_packaging)
  wheel, = glob.glob("{}/*.whl".format(os.path.join(tmp_packaging, "dist")))

  shutil.move(wheel, args.output_dir)
  print(
      "Wrote {}".format(os.path.join(args.output_dir, os.path.basename(wheel)))) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:46,代码来源:build_pip_package.py

示例8: main

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import __file__ [as 别名]
def main():
  cmd_args = argparse.ArgumentParser()
  cmd_args.add_argument("--include-tensorflow", action="store_true")
  cmd_args.add_argument("--output-dir", required=True)
  args = cmd_args.parse_args()
  if not os.path.isdir(args.output_dir):
    raise EnvironmentError(
        "Output directory {} doesn't exist".format(args.output_dir))
  elif not args.output_dir.startswith("/"):
    raise EnvironmentError("Please pass an absolute path to --output-dir.")

  tmp_packaging = tempfile.mkdtemp()
  runfiles, = (path for path in sys.path
               if path.endswith("build_pip_package.runfiles"))

  # Use the dragnn and tensorflow modules to resolve specific paths in the
  # runfiles directory. Current Bazel puts dragnn in a __main__ subdirectory,
  # for example.
  lib_path = os.path.abspath(dragnn.__file__)
  if runfiles not in lib_path:
    raise EnvironmentError("WARNING: Unexpected PYTHONPATH set by Bazel :(")
  base_dir = os.path.dirname(os.path.dirname(lib_path))
  tensorflow_dir = os.path.dirname(tensorflow.__file__)
  if runfiles not in tensorflow_dir:
    raise EnvironmentError("WARNING: Unexpected tf PYTHONPATH set by Bazel :(")

  # Copy the files.
  subprocess.check_call([
      "cp", "-r",
      "--no-preserve=all", os.path.join(base_dir, "dragnn"), os.path.join(
          base_dir, "syntaxnet"), tmp_packaging
  ])
  if args.include_tensorflow:
    subprocess.check_call(
        ["cp", "-r", "--no-preserve=all", tensorflow_dir, tmp_packaging])
  shutil.copy(
      os.path.join(base_dir, "dragnn/tools/oss_setup.py"),
      os.path.join(tmp_packaging, "setup.py"))
  subprocess.check_output(
      ["python", "setup.py", "bdist_wheel"], cwd=tmp_packaging)
  wheel, = glob.glob("{}/*.whl".format(os.path.join(tmp_packaging, "dist")))

  shutil.move(wheel, args.output_dir)
  print(
      "Wrote {}".format(os.path.join(args.output_dir, os.path.basename(wheel)))) 
开发者ID:ymao1993,项目名称:HumanRecognition,代码行数:47,代码来源:build_pip_package.py


注:本文中的tensorflow.__file__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。