PageRenderTime 144ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/tensorflow/python/__init__.py

https://gitlab.com/1851616111/tensorflow
Python | 219 lines | 180 code | 5 blank | 34 comment | 2 complexity | 5d355276196966b855222618908bbcc2 MD5 | raw file
  1. # Copyright 2015 Google Inc. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ==============================================================================
  15. """Import core names of TensorFlow.
  16. Programs that want to build TensorFlow Ops and Graphs without having to import
  17. the constructors and utilities individually can import this file:
  18. from __future__ import absolute_import
  19. from __future__ import division
  20. from __future__ import print_function
  21. import tensorflow as tf
  22. """
  23. import ctypes
  24. import inspect
  25. import sys
  26. import traceback
  27. # go/tf-wildcard-import
  28. # pylint: disable=wildcard-import,g-bad-import-order,g-import-not-at-top
  29. # pywrap_tensorflow is a SWIG generated python library that dynamically loads
  30. # _pywrap_tensorflow.so. The default mode for loading keeps all the symbol
  31. # private and not visible to other libraries that may be loaded. Setting
  32. # the mode to RTLD_GLOBAL to make the symbols visible, so libraries such
  33. # as the ones implementing custom ops can have access to tensorflow
  34. # framework's symbols.
  35. _default_dlopen_flags = sys.getdlopenflags()
  36. sys.setdlopenflags(_default_dlopen_flags | ctypes.RTLD_GLOBAL)
  37. from tensorflow.python import pywrap_tensorflow
  38. sys.setdlopenflags(_default_dlopen_flags)
  39. try:
  40. from tensorflow.core.framework.graph_pb2 import *
  41. except ImportError:
  42. msg = """%s\n\nError importing tensorflow. Unless you are using bazel,
  43. you should not try to import tensorflow from its source directory;
  44. please exit the tensorflow source tree, and relaunch your python interpreter
  45. from there.""" % traceback.format_exc()
  46. raise ImportError(msg)
  47. from tensorflow.core.framework.summary_pb2 import *
  48. from tensorflow.core.framework.attr_value_pb2 import *
  49. from tensorflow.core.protobuf.config_pb2 import *
  50. from tensorflow.core.util.event_pb2 import *
  51. # Import things out of contrib
  52. import tensorflow.contrib as contrib
  53. # Framework
  54. from tensorflow.python.framework.framework_lib import *
  55. from tensorflow.python.framework.versions import *
  56. from tensorflow.python.framework import errors
  57. # Session
  58. from tensorflow.python.client.client_lib import *
  59. # Ops
  60. from tensorflow.python.ops.standard_ops import *
  61. # Bring in subpackages
  62. from tensorflow.python.ops import nn
  63. from tensorflow.python.ops import image_ops as image
  64. from tensorflow.python.user_ops import user_ops
  65. from tensorflow.python.util import compat
  66. # Import the names from python/training.py as train.Name.
  67. from tensorflow.python.training import training as train
  68. # Sub-package for performing i/o directly instead of via ops in a graph.
  69. from tensorflow.python.lib.io import python_io
  70. # Make some application and test modules available.
  71. from tensorflow.python.platform import app
  72. from tensorflow.python.platform import flags
  73. from tensorflow.python.platform import gfile
  74. from tensorflow.python.platform import logging
  75. from tensorflow.python.platform import resource_loader
  76. from tensorflow.python.platform import sysconfig
  77. from tensorflow.python.platform import test
  78. from tensorflow.python.util.all_util import make_all
  79. # Import modules whose docstrings contribute, for use by make_all below.
  80. from tensorflow.python.client import client_lib
  81. from tensorflow.python.framework import framework_lib
  82. from tensorflow.python.ops import array_ops
  83. from tensorflow.python.ops import constant_op
  84. from tensorflow.python.ops import control_flow_ops
  85. from tensorflow.python.ops import functional_ops
  86. from tensorflow.python.ops import histogram_ops
  87. from tensorflow.python.ops import io_ops
  88. from tensorflow.python.ops import math_ops
  89. from tensorflow.python.ops import script_ops
  90. from tensorflow.python.ops import sparse_ops
  91. from tensorflow.python.ops import state_ops
  92. # Don't export modules except for the few we really want
  93. _whitelist = set([app, compat, contrib, errors, flags, gfile, image,
  94. logging, nn, python_io, resource_loader, sysconfig, test,
  95. train, user_ops])
  96. # Export all symbols directly accessible from 'tf.' by drawing on the doc
  97. # strings of other modules.
  98. __all__ = make_all(__name__,
  99. [framework_lib, array_ops, client_lib, constant_op,
  100. control_flow_ops, functional_ops, histogram_ops, io_ops,
  101. math_ops, nn, script_ops, sparse_ops, state_ops, train])
  102. # Symbols whitelisted for export without documentation.
  103. # TODO(cwhipkey): review these and move to contrib, expose through
  104. # documentation, or remove.
  105. __all__.extend([
  106. 'AttrValue',
  107. 'ConfigProto',
  108. 'Event',
  109. 'GPUOptions',
  110. 'GRAPH_DEF_VERSION',
  111. 'GRAPH_DEF_VERSION_MIN_CONSUMER',
  112. 'GRAPH_DEF_VERSION_MIN_PRODUCER',
  113. 'GraphDef',
  114. 'GraphOptions',
  115. 'HistogramProto',
  116. 'LogMessage',
  117. 'NameAttrList',
  118. 'NodeDef',
  119. 'OptimizerOptions',
  120. 'PaddingFIFOQueue',
  121. 'RunOptions',
  122. 'RunMetadata',
  123. 'SessionLog',
  124. 'Summary',
  125. 'arg_max',
  126. 'arg_min',
  127. 'assign',
  128. 'assign_add',
  129. 'assign_sub',
  130. 'bitcast',
  131. 'bytes',
  132. 'compat',
  133. 'create_partitioned_variables',
  134. 'deserialize_many_sparse',
  135. 'initialize_all_tables',
  136. 'lin_space',
  137. 'list_diff',
  138. 'parse_single_sequence_example',
  139. 'py_func',
  140. 'scalar_mul',
  141. 'serialize_many_sparse',
  142. 'serialize_sparse',
  143. 'shape_n',
  144. 'sparse_matmul',
  145. 'sparse_segment_mean_grad',
  146. 'sparse_segment_sqrt_n_grad',
  147. 'string_to_hash_bucket',
  148. 'unique_with_counts',
  149. 'user_ops',
  150. ])
  151. # Dtypes exported by framework/dtypes.py.
  152. # TODO(cwhipkey): expose these through documentation.
  153. __all__.extend([
  154. 'QUANTIZED_DTYPES',
  155. 'bfloat16', 'bfloat16_ref',
  156. 'bool', 'bool_ref',
  157. 'complex64', 'complex64_ref',
  158. 'complex128', 'complex128_ref',
  159. 'double', 'double_ref',
  160. 'half', 'half_ref',
  161. 'float16', 'float16_ref',
  162. 'float32', 'float32_ref',
  163. 'float64', 'float64_ref',
  164. 'int16', 'int16_ref',
  165. 'int32', 'int32_ref',
  166. 'int64', 'int64_ref',
  167. 'int8', 'int8_ref',
  168. 'qint16', 'qint16_ref',
  169. 'qint32', 'qint32_ref',
  170. 'qint8', 'qint8_ref',
  171. 'quint16', 'quint16_ref',
  172. 'quint8', 'quint8_ref',
  173. 'string', 'string_ref',
  174. 'uint16', 'uint16_ref',
  175. 'uint8', 'uint8_ref',
  176. ])
  177. # Export modules.
  178. __all__.extend([
  179. 'app',
  180. 'contrib',
  181. 'errors',
  182. 'flags',
  183. 'gfile',
  184. 'image',
  185. 'logging',
  186. 'nn',
  187. 'python_io',
  188. 'resource_loader',
  189. 'sysconfig',
  190. 'test',
  191. 'train',
  192. ])
  193. __all__.append('__version__')