當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。