Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/__init__.py: 2%
417 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-10-05 06:32 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-10-05 06:32 +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"""
16Top-level module of TensorFlow. By convention, we refer to this module as
17`tf` instead of `tensorflow`, following the common practice of importing
18TensorFlow via the command `import tensorflow as tf`.
20The primary function of this module is to import all of the public TensorFlow
21interfaces into a single place. The interfaces themselves are located in
22sub-modules, as described below.
24Note that the file `__init__.py` in the TensorFlow source code tree is actually
25only a placeholder to enable test cases to run. The TensorFlow build replaces
26this file with a file generated from [`api_template.__init__.py`](https://www.github.com/tensorflow/tensorflow/blob/master/tensorflow/api_template.__init__.py)
27"""
29import distutils as _distutils
30import importlib
31import inspect as _inspect
32import logging as _logging
33import os as _os
34import site as _site
35import sys as _sys
36import typing as _typing
38from tensorflow.python.tools import module_util as _module_util
39from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
41# Make sure code inside the TensorFlow codebase can use tf2.enabled() at import.
42_os.environ["TF2_BEHAVIOR"] = "1"
43from tensorflow.python import tf2 as _tf2
44_tf2.enable()
46from ._api.v2 import __internal__
47from ._api.v2 import __operators__
48from ._api.v2 import audio
49from ._api.v2 import autodiff
50from ._api.v2 import autograph
51from ._api.v2 import bitwise
52from ._api.v2 import compat
53from ._api.v2 import config
54from ._api.v2 import data
55from ._api.v2 import debugging
56from ._api.v2 import distribute
57from ._api.v2 import dtypes
58from ._api.v2 import errors
59from ._api.v2 import experimental
60from ._api.v2 import feature_column
61from ._api.v2 import graph_util
62from ._api.v2 import image
63from ._api.v2 import io
64from ._api.v2 import linalg
65from ._api.v2 import lite
66from ._api.v2 import lookup
67from ._api.v2 import math
68from ._api.v2 import mlir
69from ._api.v2 import nest
70from ._api.v2 import nn
71from ._api.v2 import profiler
72from ._api.v2 import quantization
73from ._api.v2 import queue
74from ._api.v2 import ragged
75from ._api.v2 import random
76from ._api.v2 import raw_ops
77from ._api.v2 import saved_model
78from ._api.v2 import sets
79from ._api.v2 import signal
80from ._api.v2 import sparse
81from ._api.v2 import strings
82from ._api.v2 import summary
83from ._api.v2 import sysconfig
84from ._api.v2 import test
85from ._api.v2 import tpu
86from ._api.v2 import train
87from ._api.v2 import types
88from ._api.v2 import version
89from ._api.v2 import xla
90from tensorflow.python.data.ops.optional_ops import OptionalSpec
91from tensorflow.python.eager.backprop import GradientTape
92from tensorflow.python.eager.context import executing_eagerly
93from tensorflow.python.eager.polymorphic_function.polymorphic_function import function
94from tensorflow.python.framework.constant_op import constant
95from tensorflow.python.framework.device_spec import DeviceSpecV2 as DeviceSpec
96from tensorflow.python.framework.dtypes import DType
97from tensorflow.python.framework.dtypes import as_dtype
98from tensorflow.python.framework.dtypes import bfloat16
99from tensorflow.python.framework.dtypes import bool
100from tensorflow.python.framework.dtypes import complex128
101from tensorflow.python.framework.dtypes import complex64
102from tensorflow.python.framework.dtypes import double
103from tensorflow.python.framework.dtypes import float16
104from tensorflow.python.framework.dtypes import float32
105from tensorflow.python.framework.dtypes import float64
106from tensorflow.python.framework.dtypes import half
107from tensorflow.python.framework.dtypes import int16
108from tensorflow.python.framework.dtypes import int32
109from tensorflow.python.framework.dtypes import int64
110from tensorflow.python.framework.dtypes import int8
111from tensorflow.python.framework.dtypes import qint16
112from tensorflow.python.framework.dtypes import qint32
113from tensorflow.python.framework.dtypes import qint8
114from tensorflow.python.framework.dtypes import quint16
115from tensorflow.python.framework.dtypes import quint8
116from tensorflow.python.framework.dtypes import resource
117from tensorflow.python.framework.dtypes import string
118from tensorflow.python.framework.dtypes import uint16
119from tensorflow.python.framework.dtypes import uint32
120from tensorflow.python.framework.dtypes import uint64
121from tensorflow.python.framework.dtypes import uint8
122from tensorflow.python.framework.dtypes import variant
123from tensorflow.python.framework.importer import import_graph_def
124from tensorflow.python.framework.indexed_slices import IndexedSlices
125from tensorflow.python.framework.indexed_slices import IndexedSlicesSpec
126from tensorflow.python.framework.load_library import load_library
127from tensorflow.python.framework.load_library import load_op_library
128from tensorflow.python.framework.ops import Graph
129from tensorflow.python.framework.ops import Operation
130from tensorflow.python.framework.ops import RegisterGradient
131from tensorflow.python.framework.ops import control_dependencies
132from tensorflow.python.framework.ops import device_v2 as device
133from tensorflow.python.framework.ops import get_current_name_scope
134from tensorflow.python.framework.ops import init_scope
135from tensorflow.python.framework.ops import inside_function
136from tensorflow.python.framework.ops import is_symbolic_tensor
137from tensorflow.python.framework.ops import name_scope_v2 as name_scope
138from tensorflow.python.framework.ops import no_gradient
139from tensorflow.python.framework.sparse_tensor import SparseTensor
140from tensorflow.python.framework.sparse_tensor import SparseTensorSpec
141from tensorflow.python.framework.tensor import Tensor
142from tensorflow.python.framework.tensor import TensorSpec
143from tensorflow.python.framework.tensor_conversion import convert_to_tensor_v2_with_dispatch as convert_to_tensor
144from tensorflow.python.framework.tensor_conversion_registry import register_tensor_conversion_function
145from tensorflow.python.framework.tensor_shape import TensorShape
146from tensorflow.python.framework.tensor_util import MakeNdarray as make_ndarray
147from tensorflow.python.framework.tensor_util import constant_value as get_static_value
148from tensorflow.python.framework.tensor_util import is_tf_type as is_tensor
149from tensorflow.python.framework.tensor_util import make_tensor_proto
150from tensorflow.python.framework.type_spec import TypeSpec
151from tensorflow.python.framework.type_spec import type_spec_from_value
152from tensorflow.python.framework.versions import COMPILER_VERSION as __compiler_version__
153from tensorflow.python.framework.versions import CXX11_ABI_FLAG as __cxx11_abi_flag__
154from tensorflow.python.framework.versions import CXX_VERSION as __cxx_version__
155from tensorflow.python.framework.versions import GIT_VERSION as __git_version__
156from tensorflow.python.framework.versions import MONOLITHIC_BUILD as __monolithic_build__
157from tensorflow.python.framework.versions import VERSION as __version__
158from tensorflow.python.module.module import Module
159from tensorflow.python.ops.array_ops import batch_to_space_v2 as batch_to_space
160from tensorflow.python.ops.array_ops import boolean_mask_v2 as boolean_mask
161from tensorflow.python.ops.array_ops import broadcast_dynamic_shape
162from tensorflow.python.ops.array_ops import broadcast_static_shape
163from tensorflow.python.ops.array_ops import concat
164from tensorflow.python.ops.array_ops import edit_distance
165from tensorflow.python.ops.array_ops import expand_dims_v2 as expand_dims
166from tensorflow.python.ops.array_ops import fill
167from tensorflow.python.ops.array_ops import fingerprint
168from tensorflow.python.ops.array_ops import gather_nd_v2 as gather_nd
169from tensorflow.python.ops.array_ops import gather_v2 as gather
170from tensorflow.python.ops.array_ops import guarantee_const
171from tensorflow.python.ops.array_ops import identity
172from tensorflow.python.ops.array_ops import meshgrid
173from tensorflow.python.ops.array_ops import newaxis
174from tensorflow.python.ops.array_ops import one_hot
175from tensorflow.python.ops.array_ops import ones
176from tensorflow.python.ops.array_ops import ones_like_v2 as ones_like
177from tensorflow.python.ops.array_ops import pad_v2 as pad
178from tensorflow.python.ops.array_ops import parallel_stack
179from tensorflow.python.ops.array_ops import rank
180from tensorflow.python.ops.array_ops import repeat
181from tensorflow.python.ops.array_ops import required_space_to_batch_paddings
182from tensorflow.python.ops.array_ops import reshape
183from tensorflow.python.ops.array_ops import reverse_sequence_v2 as reverse_sequence
184from tensorflow.python.ops.array_ops import searchsorted
185from tensorflow.python.ops.array_ops import sequence_mask
186from tensorflow.python.ops.array_ops import shape_n
187from tensorflow.python.ops.array_ops import shape_v2 as shape
188from tensorflow.python.ops.array_ops import size_v2 as size
189from tensorflow.python.ops.array_ops import slice
190from tensorflow.python.ops.array_ops import space_to_batch_v2 as space_to_batch
191from tensorflow.python.ops.array_ops import split
192from tensorflow.python.ops.array_ops import squeeze_v2 as squeeze
193from tensorflow.python.ops.array_ops import stop_gradient
194from tensorflow.python.ops.array_ops import strided_slice
195from tensorflow.python.ops.array_ops import tensor_scatter_nd_update
196from tensorflow.python.ops.array_ops import transpose_v2 as transpose
197from tensorflow.python.ops.array_ops import unique
198from tensorflow.python.ops.array_ops import unique_with_counts
199from tensorflow.python.ops.array_ops import where_v2 as where
200from tensorflow.python.ops.array_ops import zeros
201from tensorflow.python.ops.array_ops import zeros_like_v2 as zeros_like
202from tensorflow.python.ops.array_ops_stack import stack
203from tensorflow.python.ops.array_ops_stack import unstack
204from tensorflow.python.ops.batch_ops import batch_function as nondifferentiable_batch_function
205from tensorflow.python.ops.check_ops import assert_equal_v2 as assert_equal
206from tensorflow.python.ops.check_ops import assert_greater_v2 as assert_greater
207from tensorflow.python.ops.check_ops import assert_less_v2 as assert_less
208from tensorflow.python.ops.check_ops import assert_rank_v2 as assert_rank
209from tensorflow.python.ops.check_ops import ensure_shape
210from tensorflow.python.ops.clip_ops import clip_by_global_norm
211from tensorflow.python.ops.clip_ops import clip_by_norm
212from tensorflow.python.ops.clip_ops import clip_by_value
213from tensorflow.python.ops.cond import cond_for_tf_v2 as cond
214from tensorflow.python.ops.control_flow_assert import Assert
215from tensorflow.python.ops.control_flow_case import case_v2 as case
216from tensorflow.python.ops.control_flow_ops import group
217from tensorflow.python.ops.control_flow_ops import tuple_v2 as tuple
218from tensorflow.python.ops.control_flow_switch_case import switch_case
219from tensorflow.python.ops.critical_section_ops import CriticalSection
220from tensorflow.python.ops.custom_gradient import custom_gradient
221from tensorflow.python.ops.custom_gradient import grad_pass_through
222from tensorflow.python.ops.custom_gradient import recompute_grad
223from tensorflow.python.ops.functional_ops import foldl_v2 as foldl
224from tensorflow.python.ops.functional_ops import foldr_v2 as foldr
225from tensorflow.python.ops.functional_ops import scan_v2 as scan
226from tensorflow.python.ops.gen_array_ops import bitcast
227from tensorflow.python.ops.gen_array_ops import broadcast_to
228from tensorflow.python.ops.gen_array_ops import extract_volume_patches
229from tensorflow.python.ops.gen_array_ops import identity_n
230from tensorflow.python.ops.gen_array_ops import reverse_v2 as reverse
231from tensorflow.python.ops.gen_array_ops import scatter_nd
232from tensorflow.python.ops.gen_array_ops import space_to_batch_nd
233from tensorflow.python.ops.gen_array_ops import tensor_scatter_add as tensor_scatter_nd_add
234from tensorflow.python.ops.gen_array_ops import tensor_scatter_max as tensor_scatter_nd_max
235from tensorflow.python.ops.gen_array_ops import tensor_scatter_min as tensor_scatter_nd_min
236from tensorflow.python.ops.gen_array_ops import tensor_scatter_sub as tensor_scatter_nd_sub
237from tensorflow.python.ops.gen_array_ops import tile
238from tensorflow.python.ops.gen_array_ops import unravel_index
239from tensorflow.python.ops.gen_control_flow_ops import no_op
240from tensorflow.python.ops.gen_data_flow_ops import dynamic_partition
241from tensorflow.python.ops.gen_data_flow_ops import dynamic_stitch
242from tensorflow.python.ops.gen_linalg_ops import matrix_square_root
243from tensorflow.python.ops.gen_logging_ops import timestamp
244from tensorflow.python.ops.gen_math_ops import acosh
245from tensorflow.python.ops.gen_math_ops import asin
246from tensorflow.python.ops.gen_math_ops import asinh
247from tensorflow.python.ops.gen_math_ops import atan
248from tensorflow.python.ops.gen_math_ops import atan2
249from tensorflow.python.ops.gen_math_ops import atanh
250from tensorflow.python.ops.gen_math_ops import cos
251from tensorflow.python.ops.gen_math_ops import cosh
252from tensorflow.python.ops.gen_math_ops import greater
253from tensorflow.python.ops.gen_math_ops import greater_equal
254from tensorflow.python.ops.gen_math_ops import less
255from tensorflow.python.ops.gen_math_ops import less_equal
256from tensorflow.python.ops.gen_math_ops import logical_and
257from tensorflow.python.ops.gen_math_ops import logical_not
258from tensorflow.python.ops.gen_math_ops import logical_or
259from tensorflow.python.ops.gen_math_ops import maximum
260from tensorflow.python.ops.gen_math_ops import minimum
261from tensorflow.python.ops.gen_math_ops import neg as negative
262from tensorflow.python.ops.gen_math_ops import real_div as realdiv
263from tensorflow.python.ops.gen_math_ops import sin
264from tensorflow.python.ops.gen_math_ops import sinh
265from tensorflow.python.ops.gen_math_ops import square
266from tensorflow.python.ops.gen_math_ops import tan
267from tensorflow.python.ops.gen_math_ops import tanh
268from tensorflow.python.ops.gen_math_ops import truncate_div as truncatediv
269from tensorflow.python.ops.gen_math_ops import truncate_mod as truncatemod
270from tensorflow.python.ops.gen_nn_ops import approx_top_k
271from tensorflow.python.ops.gen_nn_ops import conv
272from tensorflow.python.ops.gen_nn_ops import conv2d_backprop_filter_v2
273from tensorflow.python.ops.gen_nn_ops import conv2d_backprop_input_v2
274from tensorflow.python.ops.gen_ragged_array_ops import ragged_fill_empty_rows
275from tensorflow.python.ops.gen_ragged_array_ops import ragged_fill_empty_rows_grad
276from tensorflow.python.ops.gen_random_index_shuffle_ops import random_index_shuffle
277from tensorflow.python.ops.gen_string_ops import as_string
278from tensorflow.python.ops.gradients_impl import HessiansV2 as hessians
279from tensorflow.python.ops.gradients_impl import gradients_v2 as gradients
280from tensorflow.python.ops.gradients_util import AggregationMethod
281from tensorflow.python.ops.histogram_ops import histogram_fixed_width
282from tensorflow.python.ops.histogram_ops import histogram_fixed_width_bins
283from tensorflow.python.ops.init_ops_v2 import Constant as constant_initializer
284from tensorflow.python.ops.init_ops_v2 import Ones as ones_initializer
285from tensorflow.python.ops.init_ops_v2 import RandomNormal as random_normal_initializer
286from tensorflow.python.ops.init_ops_v2 import RandomUniform as random_uniform_initializer
287from tensorflow.python.ops.init_ops_v2 import Zeros as zeros_initializer
288from tensorflow.python.ops.linalg_ops import eig
289from tensorflow.python.ops.linalg_ops import eigvals
290from tensorflow.python.ops.linalg_ops import eye
291from tensorflow.python.ops.linalg_ops import norm_v2 as norm
292from tensorflow.python.ops.logging_ops import print_v2 as print
293from tensorflow.python.ops.manip_ops import roll
294from tensorflow.python.ops.map_fn import map_fn_v2 as map_fn
295from tensorflow.python.ops.math_ops import abs
296from tensorflow.python.ops.math_ops import acos
297from tensorflow.python.ops.math_ops import add
298from tensorflow.python.ops.math_ops import add_n
299from tensorflow.python.ops.math_ops import argmax_v2 as argmax
300from tensorflow.python.ops.math_ops import argmin_v2 as argmin
301from tensorflow.python.ops.math_ops import cast
302from tensorflow.python.ops.math_ops import complex
303from tensorflow.python.ops.math_ops import cumsum
304from tensorflow.python.ops.math_ops import divide
305from tensorflow.python.ops.math_ops import equal
306from tensorflow.python.ops.math_ops import exp
307from tensorflow.python.ops.math_ops import floor
308from tensorflow.python.ops.math_ops import linspace_nd as linspace
309from tensorflow.python.ops.math_ops import matmul
310from tensorflow.python.ops.math_ops import multiply
311from tensorflow.python.ops.math_ops import not_equal
312from tensorflow.python.ops.math_ops import pow
313from tensorflow.python.ops.math_ops import range
314from tensorflow.python.ops.math_ops import reduce_all
315from tensorflow.python.ops.math_ops import reduce_any
316from tensorflow.python.ops.math_ops import reduce_logsumexp
317from tensorflow.python.ops.math_ops import reduce_max
318from tensorflow.python.ops.math_ops import reduce_mean
319from tensorflow.python.ops.math_ops import reduce_min
320from tensorflow.python.ops.math_ops import reduce_prod
321from tensorflow.python.ops.math_ops import reduce_sum
322from tensorflow.python.ops.math_ops import round
323from tensorflow.python.ops.math_ops import saturate_cast
324from tensorflow.python.ops.math_ops import scalar_mul_v2 as scalar_mul
325from tensorflow.python.ops.math_ops import sigmoid
326from tensorflow.python.ops.math_ops import sign
327from tensorflow.python.ops.math_ops import sqrt
328from tensorflow.python.ops.math_ops import subtract
329from tensorflow.python.ops.math_ops import tensordot
330from tensorflow.python.ops.math_ops import truediv
331from tensorflow.python.ops.parallel_for.control_flow_ops import vectorized_map
332from tensorflow.python.ops.ragged.ragged_tensor import RaggedTensor
333from tensorflow.python.ops.ragged.ragged_tensor import RaggedTensorSpec
334from tensorflow.python.ops.script_ops import eager_py_func as py_function
335from tensorflow.python.ops.script_ops import numpy_function
336from tensorflow.python.ops.sort_ops import argsort
337from tensorflow.python.ops.sort_ops import sort
338from tensorflow.python.ops.special_math_ops import einsum
339from tensorflow.python.ops.tensor_array_ops import TensorArray
340from tensorflow.python.ops.tensor_array_ops import TensorArraySpec
341from tensorflow.python.ops.unconnected_gradients import UnconnectedGradients
342from tensorflow.python.ops.variable_scope import variable_creator_scope
343from tensorflow.python.ops.variables import Variable
344from tensorflow.python.ops.variables import VariableAggregationV2 as VariableAggregation
345from tensorflow.python.ops.variables import VariableSynchronization
346from tensorflow.python.ops.while_loop import while_loop_v2 as while_loop
347from tensorflow.python.platform.tf_logging import get_logger
349# WRAPPER_PLACEHOLDER
351# Make sure directory containing top level submodules is in
352# the __path__ so that "from tensorflow.foo import bar" works.
353# We're using bitwise, but there's nothing special about that.
354_API_MODULE = _sys.modules[__name__].bitwise
355_tf_api_dir = _os.path.dirname(_os.path.dirname(_API_MODULE.__file__))
356_current_module = _sys.modules[__name__]
358if not hasattr(_current_module, "__path__"):
359 __path__ = [_tf_api_dir]
360elif _tf_api_dir not in __path__:
361 __path__.append(_tf_api_dir)
363# Hook external TensorFlow modules.
364# Import compat before trying to import summary from tensorboard, so that
365# reexport_tf_summary can get compat from sys.modules. Only needed if using
366# lazy loading.
367_current_module.compat.v2 # pylint: disable=pointless-statement
368try:
369 from tensorboard.summary._tf import summary
370 _current_module.__path__ = (
371 [_module_util.get_parent_dir(summary)] + _current_module.__path__)
372 setattr(_current_module, "summary", summary)
373except ImportError:
374 _logging.warning(
375 "Limited tf.summary API due to missing TensorBoard installation.")
377# Load tensorflow-io-gcs-filesystem if enabled
378# pylint: disable=g-import-not-at-top
379if (_os.getenv("TF_USE_MODULAR_FILESYSTEM", "0") == "true" or
380 _os.getenv("TF_USE_MODULAR_FILESYSTEM", "0") == "1"):
381 import tensorflow_io_gcs_filesystem as _tensorflow_io_gcs_filesystem
382# pylint: enable=g-import-not-at-top
384# Lazy-load estimator.
385_estimator_module = "tensorflow_estimator.python.estimator.api._v2.estimator"
386estimator = _LazyLoader("estimator", globals(), _estimator_module)
387_module_dir = _module_util.get_parent_dir_for_name(_estimator_module)
388if _module_dir:
389 _current_module.__path__ = [_module_dir] + _current_module.__path__
390setattr(_current_module, "estimator", estimator)
392_keras_module = "keras.api._v2.keras"
393_keras = _LazyLoader("keras", globals(), _keras_module)
394_module_dir = _module_util.get_parent_dir_for_name(_keras_module)
395if _module_dir:
396 _current_module.__path__ = [_module_dir] + _current_module.__path__
397setattr(_current_module, "keras", _keras)
400# Enable TF2 behaviors
401from tensorflow.python.compat import v2_compat as _compat # pylint: disable=g-import-not-at-top
402_compat.enable_v2_behavior()
403_major_api_version = 2
406# Load all plugin libraries from site-packages/tensorflow-plugins if we are
407# running under pip.
408# TODO(gunan): Find a better location for this code snippet.
409from tensorflow.python.framework import load_library as _ll
410from tensorflow.python.lib.io import file_io as _fi
412# Get sitepackages directories for the python installation.
413_site_packages_dirs = []
414if _site.ENABLE_USER_SITE and _site.USER_SITE is not None:
415 _site_packages_dirs += [_site.USER_SITE]
416_site_packages_dirs += [p for p in _sys.path if "site-packages" in p]
417if "getsitepackages" in dir(_site):
418 _site_packages_dirs += _site.getsitepackages()
420if "sysconfig" in dir(_distutils):
421 _site_packages_dirs += [_distutils.sysconfig.get_python_lib()]
423_site_packages_dirs = list(set(_site_packages_dirs))
425# Find the location of this exact file.
426_current_file_location = _inspect.getfile(_inspect.currentframe())
428def _running_from_pip_package():
429 return any(
430 _current_file_location.startswith(dir_) for dir_ in _site_packages_dirs)
432if _running_from_pip_package():
433 # TODO(gunan): Add sanity checks to loaded modules here.
435 # Load first party dynamic kernels.
436 _tf_dir = _os.path.dirname(_current_file_location)
437 _kernel_dir = _os.path.join(_tf_dir, "core", "kernels")
438 if _os.path.exists(_kernel_dir):
439 _ll.load_library(_kernel_dir)
441 # Load third party dynamic kernels.
442 for _s in _site_packages_dirs:
443 _plugin_dir = _os.path.join(_s, "tensorflow-plugins")
444 if _os.path.exists(_plugin_dir):
445 _ll.load_library(_plugin_dir)
446 # Load Pluggable Device Library
447 _ll.load_pluggable_device_library(_plugin_dir)
449if _os.getenv("TF_PLUGGABLE_DEVICE_LIBRARY_PATH", ""):
450 _ll.load_pluggable_device_library(
451 _os.getenv("TF_PLUGGABLE_DEVICE_LIBRARY_PATH")
452 )
454# Add module aliases
455if hasattr(_current_module, "keras"):
456 # It is possible that keras is a lazily loaded module, which might break when
457 # actually trying to import it. Have a Try-Catch to make sure it doesn't break
458 # when it doing some very initial loading, like tf.compat.v2, etc.
459 try:
460 _keras_package = "keras.api._v2.keras."
461 _losses = _LazyLoader("losses", globals(), _keras_package + "losses")
462 _metrics = _LazyLoader("metrics", globals(), _keras_package + "metrics")
463 _optimizers = _LazyLoader(
464 "optimizers", globals(), _keras_package + "optimizers")
465 _initializers = _LazyLoader(
466 "initializers", globals(), _keras_package + "initializers")
467 setattr(_current_module, "losses", _losses)
468 setattr(_current_module, "metrics", _metrics)
469 setattr(_current_module, "optimizers", _optimizers)
470 setattr(_current_module, "initializers", _initializers)
471 except ImportError:
472 pass
474 # Do an eager load for Keras' code so that any function/method that needs to
475 # happen at load time will trigger, eg registration of optimizers in the
476 # SavedModel registry.
477 # See b/196254385 for more details.
478 try:
479 importlib.import_module("keras.optimizers")
480 except (ImportError, AttributeError):
481 pass
482 try:
483 importlib.import_module("keras.src.optimizers")
484 except (ImportError, AttributeError):
485 pass
486del importlib
488# Explicitly import lazy-loaded modules to support autocompletion.
489# pylint: disable=g-import-not-at-top
490if _typing.TYPE_CHECKING:
491 from tensorflow_estimator.python.estimator.api._v2 import estimator as estimator
492 from keras.api._v2 import keras
493 from keras.api._v2.keras import losses
494 from keras.api._v2.keras import metrics
495 from keras.api._v2.keras import optimizers
496 from keras.api._v2.keras import initializers
497# pylint: enable=g-import-not-at-top
499# pylint: enable=undefined-variable
501# Delete modules that should be hidden from dir().
502# Don't fail if these modules are not available.
503# For e.g. this file will be originally placed under tensorflow/_api/v1 which
504# does not have "python", "core" directories. Then, it will be copied
505# to tensorflow/ which does have these two directories.
506# pylint: disable=undefined-variable
507try:
508 del python
509except NameError:
510 pass
511try:
512 del core
513except NameError:
514 pass
515try:
516 del compiler
517except NameError:
518 pass
521_names_with_underscore = ['__compiler_version__', '__cxx11_abi_flag__', '__cxx_version__', '__git_version__', '__internal__', '__monolithic_build__', '__operators__', '__version__']
522__all__ = [_s for _s in dir() if not _s.startswith('_')]
523__all__.extend([_s for _s in _names_with_underscore])