• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2015 The TensorFlow Authors. 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
17Programs that want to build TensorFlow Ops and Graphs without having to import
18the constructors and utilities individually can import this file:
19
20from __future__ import absolute_import
21from __future__ import division
22from __future__ import print_function
23
24import tensorflow as tf
25"""
26
27import ctypes
28import importlib
29import sys
30import traceback
31
32# TODO(drpng): write up instructions for editing this file in a doc and point to
33# the doc instead.
34# If you want to edit this file to expose modules in public tensorflow API, you
35# need to follow these steps:
36# 1. Consult with tensorflow team and get approval for adding a new API to the
37#    public interface.
38# 2. Document the module in the gen_docs_combined.py.
39# 3. Import the module in the main tensorflow namespace by adding an import
40#    statement in this file.
41# 4. Sanitize the entry point by making sure that your module does not expose
42#    transitively imported modules used for implementation, such as os, sys.
43
44# go/tf-wildcard-import
45# pylint: disable=wildcard-import,g-bad-import-order,g-import-not-at-top
46
47import numpy as np
48
49from tensorflow.python import pywrap_tensorflow
50
51# Protocol buffers
52from tensorflow.core.framework.graph_pb2 import *
53from tensorflow.core.framework.node_def_pb2 import *
54from tensorflow.core.framework.summary_pb2 import *
55from tensorflow.core.framework.attr_value_pb2 import *
56from tensorflow.core.protobuf.meta_graph_pb2 import TensorInfo
57from tensorflow.core.protobuf.meta_graph_pb2 import MetaGraphDef
58from tensorflow.core.protobuf.config_pb2 import *
59from tensorflow.core.protobuf.tensorflow_server_pb2 import *
60from tensorflow.core.util.event_pb2 import *
61
62# Framework
63from tensorflow.python.framework.framework_lib import *  # pylint: disable=redefined-builtin
64from tensorflow.python.framework.versions import *
65from tensorflow.python.framework import errors
66from tensorflow.python.framework import graph_util
67
68# Session
69from tensorflow.python.client.client_lib import *
70
71# Ops
72from tensorflow.python.ops.standard_ops import *
73
74# Namespaces
75from tensorflow.python.ops import initializers_ns as initializers
76
77# pylint: enable=wildcard-import
78
79# Bring in subpackages.
80from tensorflow.python import data
81from tensorflow.python import keras
82from tensorflow.python.estimator import estimator_lib as estimator
83from tensorflow.python.feature_column import feature_column_lib as feature_column
84from tensorflow.python.layers import layers
85from tensorflow.python.ops import bitwise_ops as bitwise
86from tensorflow.python.ops import image_ops as image
87from tensorflow.python.ops import manip_ops as manip
88from tensorflow.python.ops import metrics
89from tensorflow.python.ops import nn
90from tensorflow.python.ops import sets
91from tensorflow.python.ops import spectral_ops as spectral
92from tensorflow.python.ops.distributions import distributions
93from tensorflow.python.ops.linalg import linalg
94from tensorflow.python.ops.losses import losses
95from tensorflow.python.profiler import profiler
96from tensorflow.python.saved_model import saved_model
97from tensorflow.python.summary import summary
98from tensorflow.python.user_ops import user_ops
99from tensorflow.python.util import compat
100
101
102# Import the names from python/training.py as train.Name.
103from tensorflow.python.training import training as train
104
105# Sub-package for performing i/o directly instead of via ops in a graph.
106from tensorflow.python.lib.io import python_io
107
108# Make some application and test modules available.
109from tensorflow.python.platform import app
110from tensorflow.python.platform import flags
111from tensorflow.python.platform import gfile
112from tensorflow.python.platform import tf_logging as logging
113from tensorflow.python.platform import resource_loader
114from tensorflow.python.platform import sysconfig
115from tensorflow.python.platform import test
116
117from tensorflow.python.util.all_util import remove_undocumented
118from tensorflow.python.util.all_util import make_all
119from tensorflow.python.util.tf_export import tf_export
120
121# Import modules whose docstrings contribute, for use by remove_undocumented
122# below.
123from tensorflow.python.client import client_lib
124from tensorflow.python.framework import constant_op
125from tensorflow.python.framework import framework_lib
126from tensorflow.python.framework import subscribe
127from tensorflow.python.ops import array_ops
128from tensorflow.python.ops import check_ops
129from tensorflow.python.ops import confusion_matrix as confusion_matrix_m
130from tensorflow.python.ops import control_flow_ops
131from tensorflow.python.ops import functional_ops
132from tensorflow.python.ops import histogram_ops
133from tensorflow.python.ops import io_ops
134from tensorflow.python.ops import math_ops
135from tensorflow.python.ops import script_ops
136from tensorflow.python.ops import session_ops
137from tensorflow.python.ops import sparse_ops
138from tensorflow.python.ops import state_ops
139from tensorflow.python.ops import string_ops
140from tensorflow.python.ops import tensor_array_ops
141
142# Symbols whitelisted for export without documentation.
143# TODO(cwhipkey): review these and move to contrib, expose through
144# documentation, or remove.
145_allowed_symbols = [
146    'AttrValue',
147    'ConfigProto',
148    'ClusterDef',
149    'DeviceSpec',
150    'Event',
151    'GPUOptions',
152    'GRAPH_DEF_VERSION',
153    'GRAPH_DEF_VERSION_MIN_CONSUMER',
154    'GRAPH_DEF_VERSION_MIN_PRODUCER',
155    'GraphDef',
156    'GraphOptions',
157    'HistogramProto',
158    'LogMessage',
159    'MetaGraphDef',
160    'NameAttrList',
161    'NodeDef',
162    'OptimizerOptions',
163    'RunOptions',
164    'RunMetadata',
165    'SessionLog',
166    'Summary',
167    'SummaryMetadata',
168    'TensorInfo',  # Used for tf.saved_model functionality.
169]
170
171# Export protos
172# pylint: disable=undefined-variable
173tf_export('AttrValue')(AttrValue)
174tf_export('ConfigProto')(ConfigProto)
175tf_export('Event', 'summary.Event')(Event)
176tf_export('GPUOptions')(GPUOptions)
177tf_export('GraphDef')(GraphDef)
178tf_export('GraphOptions')(GraphOptions)
179tf_export('HistogramProto')(HistogramProto)
180tf_export('LogMessage')(LogMessage)
181tf_export('MetaGraphDef')(MetaGraphDef)
182tf_export('NameAttrList')(NameAttrList)
183tf_export('NodeDef')(NodeDef)
184tf_export('OptimizerOptions')(OptimizerOptions)
185tf_export('RunMetadata')(RunMetadata)
186tf_export('RunOptions')(RunOptions)
187tf_export('SessionLog', 'summary.SessionLog')(SessionLog)
188tf_export('Summary', 'summary.Summary')(Summary)
189tf_export('summary.SummaryDescription')(SummaryDescription)
190tf_export('SummaryMetadata')(SummaryMetadata)
191tf_export('summary.TaggedRunMetadata')(TaggedRunMetadata)
192tf_export('TensorInfo')(TensorInfo)
193# pylint: enable=undefined-variable
194
195
196# The following symbols are kept for compatibility. It is our plan
197# to remove them in the future.
198_allowed_symbols.extend([
199    'arg_max',
200    'arg_min',
201    'mul',  # use tf.multiply instead.
202    'neg',  # use tf.negative instead.
203    'sub',  # use tf.subtract instead.
204    'create_partitioned_variables',
205    'deserialize_many_sparse',
206    'lin_space',
207    'list_diff',  # Use tf.listdiff instead.
208    'listdiff',  # Use tf.listdiff instead.
209    'parse_single_sequence_example',
210    'serialize_many_sparse',
211    'serialize_sparse',
212    'sparse_matmul',  ## use tf.matmul instead.
213])
214
215# This is needed temporarily because we import it explicitly.
216_allowed_symbols.extend([
217    'pywrap_tensorflow',
218])
219
220# Dtypes exported by framework/dtypes.py.
221# TODO(cwhipkey): expose these through documentation.
222_allowed_symbols.extend([
223    'QUANTIZED_DTYPES',
224    'bfloat16',
225    'bool',
226    'complex64',
227    'complex128',
228    'double',
229    'half',
230    'float16',
231    'float32',
232    'float64',
233    'int16',
234    'int32',
235    'int64',
236    'int8',
237    'qint16',
238    'qint32',
239    'qint8',
240    'quint16',
241    'quint8',
242    'string',
243    'uint64',
244    'uint32',
245    'uint16',
246    'uint8',
247    'resource',
248    'variant',
249])
250
251# Export modules and constants.
252_allowed_symbols.extend([
253    'app',
254    'bitwise',
255    'compat',
256    'data',
257    'distributions',
258    'errors',
259    'estimator',
260    'feature_column',
261    'flags',
262    'gfile',
263    'graph_util',
264    'image',
265    'initializers',
266    'keras',
267    'layers',
268    'linalg',
269    'logging',
270    'losses',
271    'manip',
272    'metrics',
273    'newaxis',
274    'nn',
275    'profiler',
276    'python_io',
277    'resource_loader',
278    'saved_model',
279    'sets',
280    'spectral',
281    'summary',
282    'sysconfig',
283    'test',
284    'train',
285    'user_ops',
286])
287
288# Variables framework.versions:
289_allowed_symbols.extend([
290    'VERSION',
291    'GIT_VERSION',
292    'COMPILER_VERSION',
293    'CXX11_ABI_FLAG',
294    'MONOLITHIC_BUILD',
295])
296
297# Remove all extra symbols that don't have a docstring or are not explicitly
298# referenced in the whitelist.
299remove_undocumented(__name__, _allowed_symbols, [
300    framework_lib, array_ops, check_ops, client_lib, compat, constant_op,
301    control_flow_ops, confusion_matrix_m, data, distributions,
302    functional_ops, histogram_ops, io_ops, keras, layers,
303    losses, math_ops, metrics, nn, profiler, resource_loader, sets, script_ops,
304    session_ops, sparse_ops, state_ops, string_ops, summary, tensor_array_ops,
305    train
306])
307
308# Special dunders that we choose to export:
309_exported_dunders = set([
310    '__version__',
311    '__git_version__',
312    '__compiler_version__',
313    '__cxx11_abi_flag__',
314    '__monolithic_build__',
315])
316
317# Expose symbols minus dunders, unless they are whitelisted above.
318# This is necessary to export our dunders.
319__all__ = [s for s in dir() if s in _exported_dunders or not s.startswith('_')]
320