Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/_api/v2/compat/v1/compat/v2/__init__.py: 97%
349 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
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"""Bring in all of the public TensorFlow interface into this module."""
17import logging as _logging
18import os as _os
19import sys as _sys
20import typing as _typing
22from tensorflow.python.tools import module_util as _module_util
23from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
25# pylint: disable=g-bad-import-order
27from . import compat
28from tensorflow._api.v2.compat.v2 import __internal__
29from tensorflow._api.v2.compat.v2 import __operators__
30from tensorflow._api.v2.compat.v2 import audio
31from tensorflow._api.v2.compat.v2 import autodiff
32from tensorflow._api.v2.compat.v2 import autograph
33from tensorflow._api.v2.compat.v2 import bitwise
34from tensorflow._api.v2.compat.v2 import config
35from tensorflow._api.v2.compat.v2 import data
36from tensorflow._api.v2.compat.v2 import debugging
37from tensorflow._api.v2.compat.v2 import distribute
38from tensorflow._api.v2.compat.v2 import dtypes
39from tensorflow._api.v2.compat.v2 import errors
40from tensorflow._api.v2.compat.v2 import experimental
41from tensorflow._api.v2.compat.v2 import feature_column
42from tensorflow._api.v2.compat.v2 import graph_util
43from tensorflow._api.v2.compat.v2 import image
44from tensorflow._api.v2.compat.v2 import io
45from tensorflow._api.v2.compat.v2 import linalg
46from tensorflow._api.v2.compat.v2 import lite
47from tensorflow._api.v2.compat.v2 import lookup
48from tensorflow._api.v2.compat.v2 import math
49from tensorflow._api.v2.compat.v2 import mlir
50from tensorflow._api.v2.compat.v2 import nest
51from tensorflow._api.v2.compat.v2 import nn
52from tensorflow._api.v2.compat.v2 import profiler
53from tensorflow._api.v2.compat.v2 import quantization
54from tensorflow._api.v2.compat.v2 import queue
55from tensorflow._api.v2.compat.v2 import ragged
56from tensorflow._api.v2.compat.v2 import random
57from tensorflow._api.v2.compat.v2 import raw_ops
58from tensorflow._api.v2.compat.v2 import saved_model
59from tensorflow._api.v2.compat.v2 import sets
60from tensorflow._api.v2.compat.v2 import signal
61from tensorflow._api.v2.compat.v2 import sparse
62from tensorflow._api.v2.compat.v2 import strings
63from tensorflow._api.v2.compat.v2 import summary
64from tensorflow._api.v2.compat.v2 import sysconfig
65from tensorflow._api.v2.compat.v2 import test
66from tensorflow._api.v2.compat.v2 import tpu
67from tensorflow._api.v2.compat.v2 import train
68from tensorflow._api.v2.compat.v2 import types
69from tensorflow._api.v2.compat.v2 import version
70from tensorflow._api.v2.compat.v2 import xla
71from tensorflow.python.data.ops.optional_ops import OptionalSpec
72from tensorflow.python.eager.backprop import GradientTape
73from tensorflow.python.eager.context import executing_eagerly
74from tensorflow.python.eager.polymorphic_function.polymorphic_function import function
75from tensorflow.python.framework.constant_op import constant
76from tensorflow.python.framework.device_spec import DeviceSpecV2 as DeviceSpec
77from tensorflow.python.framework.dtypes import DType
78from tensorflow.python.framework.dtypes import as_dtype
79from tensorflow.python.framework.dtypes import bfloat16
80from tensorflow.python.framework.dtypes import bool
81from tensorflow.python.framework.dtypes import complex128
82from tensorflow.python.framework.dtypes import complex64
83from tensorflow.python.framework.dtypes import double
84from tensorflow.python.framework.dtypes import float16
85from tensorflow.python.framework.dtypes import float32
86from tensorflow.python.framework.dtypes import float64
87from tensorflow.python.framework.dtypes import half
88from tensorflow.python.framework.dtypes import int16
89from tensorflow.python.framework.dtypes import int32
90from tensorflow.python.framework.dtypes import int64
91from tensorflow.python.framework.dtypes import int8
92from tensorflow.python.framework.dtypes import qint16
93from tensorflow.python.framework.dtypes import qint32
94from tensorflow.python.framework.dtypes import qint8
95from tensorflow.python.framework.dtypes import quint16
96from tensorflow.python.framework.dtypes import quint8
97from tensorflow.python.framework.dtypes import resource
98from tensorflow.python.framework.dtypes import string
99from tensorflow.python.framework.dtypes import uint16
100from tensorflow.python.framework.dtypes import uint32
101from tensorflow.python.framework.dtypes import uint64
102from tensorflow.python.framework.dtypes import uint8
103from tensorflow.python.framework.dtypes import variant
104from tensorflow.python.framework.importer import import_graph_def
105from tensorflow.python.framework.indexed_slices import IndexedSlices
106from tensorflow.python.framework.indexed_slices import IndexedSlicesSpec
107from tensorflow.python.framework.load_library import load_library
108from tensorflow.python.framework.load_library import load_op_library
109from tensorflow.python.framework.ops import Graph
110from tensorflow.python.framework.ops import Operation
111from tensorflow.python.framework.ops import RegisterGradient
112from tensorflow.python.framework.ops import Tensor
113from tensorflow.python.framework.ops import control_dependencies
114from tensorflow.python.framework.ops import device_v2 as device
115from tensorflow.python.framework.ops import get_current_name_scope
116from tensorflow.python.framework.ops import init_scope
117from tensorflow.python.framework.ops import inside_function
118from tensorflow.python.framework.ops import is_symbolic_tensor
119from tensorflow.python.framework.ops import name_scope_v2 as name_scope
120from tensorflow.python.framework.ops import no_gradient
121from tensorflow.python.framework.sparse_tensor import SparseTensor
122from tensorflow.python.framework.sparse_tensor import SparseTensorSpec
123from tensorflow.python.framework.tensor import TensorSpec
124from tensorflow.python.framework.tensor_conversion import convert_to_tensor_v2_with_dispatch as convert_to_tensor
125from tensorflow.python.framework.tensor_conversion_registry import register_tensor_conversion_function
126from tensorflow.python.framework.tensor_shape import TensorShape
127from tensorflow.python.framework.tensor_util import MakeNdarray as make_ndarray
128from tensorflow.python.framework.tensor_util import constant_value as get_static_value
129from tensorflow.python.framework.tensor_util import is_tf_type as is_tensor
130from tensorflow.python.framework.tensor_util import make_tensor_proto
131from tensorflow.python.framework.type_spec import TypeSpec
132from tensorflow.python.framework.type_spec import type_spec_from_value
133from tensorflow.python.framework.versions import COMPILER_VERSION as __compiler_version__
134from tensorflow.python.framework.versions import CXX11_ABI_FLAG as __cxx11_abi_flag__
135from tensorflow.python.framework.versions import CXX_VERSION as __cxx_version__
136from tensorflow.python.framework.versions import GIT_VERSION as __git_version__
137from tensorflow.python.framework.versions import MONOLITHIC_BUILD as __monolithic_build__
138from tensorflow.python.framework.versions import VERSION as __version__
139from tensorflow.python.module.module import Module
140from tensorflow.python.ops.array_ops import batch_to_space_v2 as batch_to_space
141from tensorflow.python.ops.array_ops import boolean_mask_v2 as boolean_mask
142from tensorflow.python.ops.array_ops import broadcast_dynamic_shape
143from tensorflow.python.ops.array_ops import broadcast_static_shape
144from tensorflow.python.ops.array_ops import concat
145from tensorflow.python.ops.array_ops import edit_distance
146from tensorflow.python.ops.array_ops import expand_dims_v2 as expand_dims
147from tensorflow.python.ops.array_ops import fill
148from tensorflow.python.ops.array_ops import fingerprint
149from tensorflow.python.ops.array_ops import gather_nd_v2 as gather_nd
150from tensorflow.python.ops.array_ops import gather_v2 as gather
151from tensorflow.python.ops.array_ops import guarantee_const
152from tensorflow.python.ops.array_ops import identity
153from tensorflow.python.ops.array_ops import meshgrid
154from tensorflow.python.ops.array_ops import newaxis
155from tensorflow.python.ops.array_ops import one_hot
156from tensorflow.python.ops.array_ops import ones
157from tensorflow.python.ops.array_ops import ones_like_v2 as ones_like
158from tensorflow.python.ops.array_ops import pad_v2 as pad
159from tensorflow.python.ops.array_ops import parallel_stack
160from tensorflow.python.ops.array_ops import rank
161from tensorflow.python.ops.array_ops import repeat
162from tensorflow.python.ops.array_ops import required_space_to_batch_paddings
163from tensorflow.python.ops.array_ops import reshape
164from tensorflow.python.ops.array_ops import reverse_sequence_v2 as reverse_sequence
165from tensorflow.python.ops.array_ops import searchsorted
166from tensorflow.python.ops.array_ops import sequence_mask
167from tensorflow.python.ops.array_ops import shape_n
168from tensorflow.python.ops.array_ops import shape_v2 as shape
169from tensorflow.python.ops.array_ops import size_v2 as size
170from tensorflow.python.ops.array_ops import slice
171from tensorflow.python.ops.array_ops import space_to_batch_v2 as space_to_batch
172from tensorflow.python.ops.array_ops import split
173from tensorflow.python.ops.array_ops import squeeze_v2 as squeeze
174from tensorflow.python.ops.array_ops import stop_gradient
175from tensorflow.python.ops.array_ops import strided_slice
176from tensorflow.python.ops.array_ops import tensor_scatter_nd_update
177from tensorflow.python.ops.array_ops import transpose_v2 as transpose
178from tensorflow.python.ops.array_ops import unique
179from tensorflow.python.ops.array_ops import unique_with_counts
180from tensorflow.python.ops.array_ops import where_v2 as where
181from tensorflow.python.ops.array_ops import zeros
182from tensorflow.python.ops.array_ops import zeros_like_v2 as zeros_like
183from tensorflow.python.ops.array_ops_stack import stack
184from tensorflow.python.ops.array_ops_stack import unstack
185from tensorflow.python.ops.batch_ops import batch_function as nondifferentiable_batch_function
186from tensorflow.python.ops.check_ops import assert_equal_v2 as assert_equal
187from tensorflow.python.ops.check_ops import assert_greater_v2 as assert_greater
188from tensorflow.python.ops.check_ops import assert_less_v2 as assert_less
189from tensorflow.python.ops.check_ops import assert_rank_v2 as assert_rank
190from tensorflow.python.ops.check_ops import ensure_shape
191from tensorflow.python.ops.clip_ops import clip_by_global_norm
192from tensorflow.python.ops.clip_ops import clip_by_norm
193from tensorflow.python.ops.clip_ops import clip_by_value
194from tensorflow.python.ops.cond import cond_for_tf_v2 as cond
195from tensorflow.python.ops.control_flow_assert import Assert
196from tensorflow.python.ops.control_flow_case import case_v2 as case
197from tensorflow.python.ops.control_flow_ops import group
198from tensorflow.python.ops.control_flow_ops import tuple_v2 as tuple
199from tensorflow.python.ops.control_flow_switch_case import switch_case
200from tensorflow.python.ops.critical_section_ops import CriticalSection
201from tensorflow.python.ops.custom_gradient import custom_gradient
202from tensorflow.python.ops.custom_gradient import grad_pass_through
203from tensorflow.python.ops.custom_gradient import recompute_grad
204from tensorflow.python.ops.functional_ops import foldl_v2 as foldl
205from tensorflow.python.ops.functional_ops import foldr_v2 as foldr
206from tensorflow.python.ops.functional_ops import scan_v2 as scan
207from tensorflow.python.ops.gen_array_ops import bitcast
208from tensorflow.python.ops.gen_array_ops import broadcast_to
209from tensorflow.python.ops.gen_array_ops import extract_volume_patches
210from tensorflow.python.ops.gen_array_ops import identity_n
211from tensorflow.python.ops.gen_array_ops import reverse_v2 as reverse
212from tensorflow.python.ops.gen_array_ops import scatter_nd
213from tensorflow.python.ops.gen_array_ops import space_to_batch_nd
214from tensorflow.python.ops.gen_array_ops import tensor_scatter_add as tensor_scatter_nd_add
215from tensorflow.python.ops.gen_array_ops import tensor_scatter_max as tensor_scatter_nd_max
216from tensorflow.python.ops.gen_array_ops import tensor_scatter_min as tensor_scatter_nd_min
217from tensorflow.python.ops.gen_array_ops import tensor_scatter_sub as tensor_scatter_nd_sub
218from tensorflow.python.ops.gen_array_ops import tile
219from tensorflow.python.ops.gen_array_ops import unravel_index
220from tensorflow.python.ops.gen_control_flow_ops import no_op
221from tensorflow.python.ops.gen_data_flow_ops import dynamic_partition
222from tensorflow.python.ops.gen_data_flow_ops import dynamic_stitch
223from tensorflow.python.ops.gen_linalg_ops import matrix_square_root
224from tensorflow.python.ops.gen_logging_ops import timestamp
225from tensorflow.python.ops.gen_math_ops import acosh
226from tensorflow.python.ops.gen_math_ops import asin
227from tensorflow.python.ops.gen_math_ops import asinh
228from tensorflow.python.ops.gen_math_ops import atan
229from tensorflow.python.ops.gen_math_ops import atan2
230from tensorflow.python.ops.gen_math_ops import atanh
231from tensorflow.python.ops.gen_math_ops import cos
232from tensorflow.python.ops.gen_math_ops import cosh
233from tensorflow.python.ops.gen_math_ops import greater
234from tensorflow.python.ops.gen_math_ops import greater_equal
235from tensorflow.python.ops.gen_math_ops import less
236from tensorflow.python.ops.gen_math_ops import less_equal
237from tensorflow.python.ops.gen_math_ops import logical_and
238from tensorflow.python.ops.gen_math_ops import logical_not
239from tensorflow.python.ops.gen_math_ops import logical_or
240from tensorflow.python.ops.gen_math_ops import maximum
241from tensorflow.python.ops.gen_math_ops import minimum
242from tensorflow.python.ops.gen_math_ops import neg as negative
243from tensorflow.python.ops.gen_math_ops import real_div as realdiv
244from tensorflow.python.ops.gen_math_ops import sin
245from tensorflow.python.ops.gen_math_ops import sinh
246from tensorflow.python.ops.gen_math_ops import square
247from tensorflow.python.ops.gen_math_ops import tan
248from tensorflow.python.ops.gen_math_ops import tanh
249from tensorflow.python.ops.gen_math_ops import truncate_div as truncatediv
250from tensorflow.python.ops.gen_math_ops import truncate_mod as truncatemod
251from tensorflow.python.ops.gen_nn_ops import approx_top_k
252from tensorflow.python.ops.gen_nn_ops import conv2d_backprop_filter_v2
253from tensorflow.python.ops.gen_nn_ops import conv2d_backprop_input_v2
254from tensorflow.python.ops.gen_ragged_array_ops import ragged_fill_empty_rows
255from tensorflow.python.ops.gen_ragged_array_ops import ragged_fill_empty_rows_grad
256from tensorflow.python.ops.gen_random_index_shuffle_ops import random_index_shuffle
257from tensorflow.python.ops.gen_string_ops import as_string
258from tensorflow.python.ops.gradients_impl import HessiansV2 as hessians
259from tensorflow.python.ops.gradients_impl import gradients_v2 as gradients
260from tensorflow.python.ops.gradients_util import AggregationMethod
261from tensorflow.python.ops.histogram_ops import histogram_fixed_width
262from tensorflow.python.ops.histogram_ops import histogram_fixed_width_bins
263from tensorflow.python.ops.init_ops_v2 import Constant as constant_initializer
264from tensorflow.python.ops.init_ops_v2 import Ones as ones_initializer
265from tensorflow.python.ops.init_ops_v2 import RandomNormal as random_normal_initializer
266from tensorflow.python.ops.init_ops_v2 import RandomUniform as random_uniform_initializer
267from tensorflow.python.ops.init_ops_v2 import Zeros as zeros_initializer
268from tensorflow.python.ops.linalg_ops import eig
269from tensorflow.python.ops.linalg_ops import eigvals
270from tensorflow.python.ops.linalg_ops import eye
271from tensorflow.python.ops.linalg_ops import norm_v2 as norm
272from tensorflow.python.ops.logging_ops import print_v2 as print
273from tensorflow.python.ops.manip_ops import roll
274from tensorflow.python.ops.map_fn import map_fn_v2 as map_fn
275from tensorflow.python.ops.math_ops import abs
276from tensorflow.python.ops.math_ops import acos
277from tensorflow.python.ops.math_ops import add
278from tensorflow.python.ops.math_ops import add_n
279from tensorflow.python.ops.math_ops import argmax_v2 as argmax
280from tensorflow.python.ops.math_ops import argmin_v2 as argmin
281from tensorflow.python.ops.math_ops import cast
282from tensorflow.python.ops.math_ops import complex
283from tensorflow.python.ops.math_ops import cumsum
284from tensorflow.python.ops.math_ops import divide
285from tensorflow.python.ops.math_ops import equal
286from tensorflow.python.ops.math_ops import exp
287from tensorflow.python.ops.math_ops import floor
288from tensorflow.python.ops.math_ops import linspace_nd as linspace
289from tensorflow.python.ops.math_ops import matmul
290from tensorflow.python.ops.math_ops import multiply
291from tensorflow.python.ops.math_ops import not_equal
292from tensorflow.python.ops.math_ops import pow
293from tensorflow.python.ops.math_ops import range
294from tensorflow.python.ops.math_ops import reduce_all
295from tensorflow.python.ops.math_ops import reduce_any
296from tensorflow.python.ops.math_ops import reduce_logsumexp
297from tensorflow.python.ops.math_ops import reduce_max
298from tensorflow.python.ops.math_ops import reduce_mean
299from tensorflow.python.ops.math_ops import reduce_min
300from tensorflow.python.ops.math_ops import reduce_prod
301from tensorflow.python.ops.math_ops import reduce_sum
302from tensorflow.python.ops.math_ops import round
303from tensorflow.python.ops.math_ops import saturate_cast
304from tensorflow.python.ops.math_ops import scalar_mul_v2 as scalar_mul
305from tensorflow.python.ops.math_ops import sigmoid
306from tensorflow.python.ops.math_ops import sign
307from tensorflow.python.ops.math_ops import sqrt
308from tensorflow.python.ops.math_ops import subtract
309from tensorflow.python.ops.math_ops import tensordot
310from tensorflow.python.ops.math_ops import truediv
311from tensorflow.python.ops.parallel_for.control_flow_ops import vectorized_map
312from tensorflow.python.ops.ragged.ragged_tensor import RaggedTensor
313from tensorflow.python.ops.ragged.ragged_tensor import RaggedTensorSpec
314from tensorflow.python.ops.script_ops import eager_py_func as py_function
315from tensorflow.python.ops.script_ops import numpy_function
316from tensorflow.python.ops.sort_ops import argsort
317from tensorflow.python.ops.sort_ops import sort
318from tensorflow.python.ops.special_math_ops import einsum
319from tensorflow.python.ops.tensor_array_ops import TensorArray
320from tensorflow.python.ops.tensor_array_ops import TensorArraySpec
321from tensorflow.python.ops.unconnected_gradients import UnconnectedGradients
322from tensorflow.python.ops.variable_scope import variable_creator_scope
323from tensorflow.python.ops.variables import Variable
324from tensorflow.python.ops.variables import VariableAggregationV2 as VariableAggregation
325from tensorflow.python.ops.variables import VariableSynchronization
326from tensorflow.python.ops.while_loop import while_loop_v2 as while_loop
327from tensorflow.python.platform.tf_logging import get_logger
329# WRAPPER_PLACEHOLDER
331# Hook external TensorFlow modules.
332_current_module = _sys.modules[__name__]
333try:
334 from tensorboard.summary._tf import summary
335 _current_module.__path__ = (
336 [_module_util.get_parent_dir(summary)] + _current_module.__path__)
337 setattr(_current_module, "summary", summary)
338except ImportError:
339 _logging.warning(
340 "Limited tf.compat.v2.summary API due to missing TensorBoard "
341 "installation.")
343# Lazy-load estimator.
344_estimator_module = "tensorflow_estimator.python.estimator.api._v2.estimator"
345estimator = _LazyLoader("estimator", globals(), _estimator_module)
346_module_dir = _module_util.get_parent_dir_for_name(_estimator_module)
347if _module_dir:
348 _current_module.__path__ = [_module_dir] + _current_module.__path__
349setattr(_current_module, "estimator", estimator)
351_keras_module = "keras.api._v2.keras"
352_keras = _LazyLoader("keras", globals(), _keras_module)
353_module_dir = _module_util.get_parent_dir_for_name(_keras_module)
354if _module_dir:
355 _current_module.__path__ = [_module_dir] + _current_module.__path__
356setattr(_current_module, "keras", _keras)
358# We would like the following to work for fully enabling 2.0 in a 1.0 install:
359#
360# import tensorflow.compat.v2 as tf
361# tf.enable_v2_behavior()
362#
363# This make this one symbol available directly.
364from tensorflow.python.compat.v2_compat import enable_v2_behavior # pylint: disable=g-import-not-at-top
365setattr(_current_module, "enable_v2_behavior", enable_v2_behavior)
367# Add module aliases
368if hasattr(_current_module, 'keras'):
369 # It is possible that keras is a lazily loaded module, which might break when
370 # actually trying to import it. Have a Try-Catch to make sure it doesn't break
371 # when it doing some very initial loading, like tf.compat.v2, etc.
372 try:
373 _keras_package = "keras.api._v2.keras."
374 _losses = _LazyLoader("losses", globals(), _keras_package + "losses")
375 _metrics = _LazyLoader("metrics", globals(), _keras_package + "metrics")
376 _optimizers = _LazyLoader(
377 "optimizers", globals(), _keras_package + "optimizers")
378 _initializers = _LazyLoader(
379 "initializers", globals(), _keras_package + "initializers")
380 setattr(_current_module, "losses", _losses)
381 setattr(_current_module, "metrics", _metrics)
382 setattr(_current_module, "optimizers", _optimizers)
383 setattr(_current_module, "initializers", _initializers)
384 except ImportError:
385 pass
387# Explicitly import lazy-loaded modules to support autocompletion.
388# pylint: disable=g-import-not-at-top
389if _typing.TYPE_CHECKING:
390 from tensorflow_estimator.python.estimator.api._v2 import estimator as estimator
391 from keras.api._v2 import keras
392 from keras.api._v2.keras import losses
393 from keras.api._v2.keras import metrics
394 from keras.api._v2.keras import optimizers
395 from keras.api._v2.keras import initializers
396# pylint: enable=g-import-not-at-top