# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== """The execution context for ClusterCoordinator.""" import contextlib import threading from tensorflow.python.util.lazy_loader import LazyLoader # There is a circular dependency between this and the `cluster_coordinator` # module. So we load it lazily to work around this. cluster_coordinator = LazyLoader( "cluster_coordinator", globals(), "tensorflow.python.distribute.coordinator.cluster_coordinator") _dispatch_context = threading.local() def get_current_dispatch_context(): try: return _dispatch_context.current except AttributeError: return None @contextlib.contextmanager def with_dispatch_context(worker_obj): previous_context = getattr(_dispatch_context, "current", None)
import six from tensorflow.python.framework import composite_tensor from tensorflow.python.framework import dtypes from tensorflow.python.framework import tensor_shape from tensorflow.python.platform import tf_logging as logging from tensorflow.python.util import _pywrap_utils from tensorflow.python.util import compat from tensorflow.python.util import nest from tensorflow.python.util import tf_decorator from tensorflow.python.util.lazy_loader import LazyLoader from tensorflow.python.util.tf_export import tf_export # Use LazyLoader to avoid circular dependencies. tensor_spec = LazyLoader( "tensor_spec", globals(), "tensorflow.python.framework.tensor_spec") ops = LazyLoader( "ops", globals(), "tensorflow.python.framework.ops") @tf_export("TypeSpec", v1=["TypeSpec", "data.experimental.Structure"]) @six.add_metaclass(abc.ABCMeta) class TypeSpec(object): """Specifies a TensorFlow value type. A `tf.TypeSpec` provides metadata describing an object accepted or returned by TensorFlow APIs. Concrete subclasses, such as `tf.TensorSpec` and `tf.RaggedTensorSpec`, are used to describe different value types.
from __future__ import print_function import numpy as np from tensorflow.lite.python.convert_phase import Component from tensorflow.lite.python.convert_phase import convert_phase from tensorflow.lite.python.convert_phase import SubComponent from tensorflow.lite.python.interpreter import Interpreter from tensorflow.python.framework import dtypes from tensorflow.python.util.lazy_loader import LazyLoader # Lazy load since some of the performance benchmark skylark rules # break dependencies. Must use double quotes to match code internal rewrite # rule. _calibration_wrapper = LazyLoader( "_calibration_wrapper", globals(), "tensorflow.lite.python.optimize." "_pywrap_tensorflow_lite_calibration_wrapper") def add_intermediate_tensors(model_content): """Adds intermediate tensors to fused op if needed.""" return _calibration_wrapper.AddIntermediateTensors(model_content) class Calibrator(object): """Calibrates a floating point model and then quantizes it. This is an internal class, not a public interface. """ def __init__(self, model_content,
from __future__ import absolute_import from __future__ import division from __future__ import print_function from tensorflow.python.eager import def_function from tensorflow.python.eager import function as defun from tensorflow.python.keras.saving.saved_model import constants from tensorflow.python.training.tracking import base as trackable from tensorflow.python.training.tracking.tracking import AutoTrackable from tensorflow.python.util.lazy_loader import LazyLoader # TODO(b/134426265): Switch back to single-quotes to match the rest of the file # once the issue with copybara is fixed. # pylint:disable=g-inconsistent-quotes base_layer = LazyLoader( "base_layer", globals(), "tensorflow.python.keras.engine.base_layer") training_lib = LazyLoader( "training_lib", globals(), "tensorflow.python.keras.engine.training") # pylint:enable=g-inconsistent-quotes class SerializedAttributes(object): """Class that tracks and validates all serialization attributes. Keras models contain many Python-defined components. For example, the trainable_variable property lists the model's trainable variables by recursively retrieving the trainable variables from each of the child layers. Another example is model.call, a python function that calls child layers and adds ops to the backend graph.
keras = _LazyLoader("keras", globals(), _keras_module) _module_dir = _module_util.get_parent_dir_for_name(_keras_module) if _module_dir: _current_module.__path__ = [_module_dir] + _current_module.__path__ setattr(_current_module, "keras", keras) from tensorflow.python.util.lazy_loader import LazyLoader # pylint: disable=g-import-not-at-top _CONTRIB_WARNING = """ The TensorFlow contrib module will not be included in TensorFlow 2.0. For more information, please see: * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md * https://github.com/tensorflow/addons * https://github.com/tensorflow/io (for I/O related ops) If you depend on functionality not listed there, please file an issue. """ contrib = LazyLoader('contrib', globals(), 'tensorflow.contrib', _CONTRIB_WARNING) del LazyLoader # The templated code that replaces the placeholder above sometimes # sets the __all__ variable. If it does, we have to be sure to add # "contrib". if '__all__' in vars(): vars()['__all__'].append('contrib') from tensorflow.python.platform import flags # pylint: disable=g-import-not-at-top # The 'app' module will be imported as part of the placeholder section above. _current_module.app.flags = flags # pylint: disable=undefined-variable setattr(_current_module, "flags", flags) _major_api_version = 1 # Add module aliases from Keras to TF.
from tensorflow.contrib import rnn from tensorflow.contrib import saved_model from tensorflow.contrib import seq2seq from tensorflow.contrib import signal from tensorflow.contrib import slim from tensorflow.contrib import solvers from tensorflow.contrib import sparsemax from tensorflow.contrib import staging from tensorflow.contrib import stat_summarizer from tensorflow.contrib import stateless from tensorflow.contrib import tensor_forest from tensorflow.contrib import tensorboard from tensorflow.contrib import testing from tensorflow.contrib import tfprof from tensorflow.contrib import timeseries from tensorflow.contrib import tpu from tensorflow.contrib import training from tensorflow.contrib import util from tensorflow.contrib.ndlstm import python as ndlstm from tensorflow.contrib.remote_fused_graph import pylib as remote_fused_graph from tensorflow.contrib.specs import python as specs from tensorflow.python.util.lazy_loader import LazyLoader ffmpeg = LazyLoader("ffmpeg", globals(), "tensorflow.contrib.ffmpeg") del LazyLoader del absolute_import del division del print_function
from __future__ import print_function from tensorflow.python.framework import dtypes from tensorflow.python.framework import ops from tensorflow.python.framework import tensor_shape from tensorflow.python.ops import array_ops from tensorflow.python.ops import gen_list_ops # go/tf-wildcard-import # pylint: disable=wildcard-import from tensorflow.python.ops.gen_list_ops import * # pylint: enable=wildcard-import from tensorflow.python.util.lazy_loader import LazyLoader # list_ops -> control_flow_ops -> tensor_array_ops -> list_ops control_flow_ops = LazyLoader( "control_flow_ops", globals(), "tensorflow.python.ops.control_flow_ops") ops.NotDifferentiable("TensorListConcatLists") ops.NotDifferentiable("TensorListElementShape") ops.NotDifferentiable("TensorListLength") ops.NotDifferentiable("TensorListPushBackBatch") def empty_tensor_list(element_shape, element_dtype, max_num_elements=None, name=None): if max_num_elements is None: max_num_elements = -1
from tensorflow.python.framework import tensor_shape from tensorflow.python.ops import array_ops from tensorflow.python.ops import resource_variable_ops from tensorflow.python.ops import variable_scope as vs from tensorflow.python.platform import tf_logging as logging from tensorflow.python.training import server_lib from tensorflow.python.training.tracking import base as trackable from tensorflow.python.util import nest from tensorflow.python.util import tf_inspect from tensorflow.python.util.lazy_loader import LazyLoader from tensorflow.python.util.tf_export import tf_export ALLOWED_TASK_TYPES = ("chief", "worker", "ps") cluster_coordinator = LazyLoader( "cluster_coordinator", globals(), "tensorflow.python.distribute.coordinator.cluster_coordinator" ) load_context = LazyLoader( "load_context", globals(), "tensorflow.python.keras.saving.saved_model.load_context" ) @tf_export( "distribute.experimental.ParameterServerStrategy", "distribute.ParameterServerStrategy", v1=[]) class ParameterServerStrategyV2(distribute_lib.Strategy): """An multi-worker tf.distribute strategy with parameter servers.
from tensorflow.python.saved_model import utils_impl as saved_model_utils from tensorflow.python.training import saver as saver_lib from tensorflow.python.training.tracking import graph_view from tensorflow.python.util import compat from tensorflow.python.util import deprecation from tensorflow.python.util import nest from tensorflow.python.util.lazy_loader import LazyLoader from tensorflow.python.util.tf_export import keras_export # To avoid circular dependencies between keras/engine and keras/saving, # code in keras/saving must delay imports. # TODO(b/134426265): Switch back to single-quotes to match the rest of the file # once the issue with copybara is fixed. # pylint:disable=g-inconsistent-quotes metrics_lib = LazyLoader("metrics_lib", globals(), "tensorflow.python.keras.metrics") models_lib = LazyLoader("models_lib", globals(), "tensorflow.python.keras.models") sequential = LazyLoader( "sequential", globals(), "tensorflow.python.keras.engine.sequential") # pylint:enable=g-inconsistent-quotes @deprecation.deprecated( date=None, instructions=('Please use `model.save(..., save_format="tf")` or ' '`tf.keras.models.save_model(..., save_format="tf")`.')) @keras_export('keras.experimental.export_saved_model') def export_saved_model(model, saved_model_path,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== """Python wrapper for convert models from dense to sparse format.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function from tensorflow.python.util.lazy_loader import LazyLoader # Lazy load since some of the performance benchmark skylark rules # break dependencies. Must use double quotes to match code internal rewrite # rule. _sparsification_wrapper = LazyLoader( "_sparsification_wrapper", globals(), "tensorflow.lite.python.optimize." "tensorflow_lite_wrap_sparsification_wrapper") class Sparsifier(object): """Convert a model from dense to sparse format. This is an internal class, not a public interface. """ def __init__(self, model_content): """Constructor. Args: model_content: Content of a TF-Lite Flatbuffer file. Raises:
from tensorflow.python.framework import dtypes from tensorflow.python.framework import tensor_conversion_registry from tensorflow.python.framework import tensor_shape from tensorflow.python.framework import type_spec from tensorflow.python.types import internal from tensorflow.python.util.compat import collections_abc from tensorflow.python.util.lazy_loader import LazyLoader from tensorflow.python.util.tf_export import tf_export # Use LazyLoader to avoid circular dependencies. # # Note: these can all be changed to regular imports once all code has been # updated to refer the symbols defined in this module directly, rather than # using the backwards-compatible aliases in ops.py. (E.g., # "indexed_slices.IndexedSlices" rather than "ops.IndexedSlices".) math_ops = LazyLoader("math_ops", globals(), "tensorflow.python.ops.math_ops") ops = LazyLoader("ops", globals(), "tensorflow.python.framework.ops") tensor_spec = LazyLoader("tensor_spec", globals(), "tensorflow.python.framework.tensor_spec") tensor_util = LazyLoader("tensor_util", globals(), "tensorflow.python.framework.tensor_util") class IndexedSlicesCompositeTensorGradient( composite_tensor_gradient.CompositeTensorGradient): """CompositeTensorGradient for IndexedSlices.""" def get_gradient_components(self, value): return value.values def replace_gradient_components(self, value, component_grads): return IndexedSlices(component_grads, value.indices, value.dense_shape)
from tensorflow.python.keras.saving.saved_model.serialized_attributes import CommonEndpoints from tensorflow.python.keras.utils.generic_utils import deserialize_keras_object from tensorflow.python.saved_model import load as tf_load from tensorflow.python.training.tracking import base as trackable from tensorflow.python.training.tracking.tracking import delete_tracking from tensorflow.python.util import compat from tensorflow.python.util import nest from tensorflow.python.util.lazy_loader import LazyLoader # To avoid circular dependencies between keras/engine and keras/saving, # code in keras/saving must delay imports. # TODO(b/134426265): Switch back to single-quotes to match the rest of the file # once the issue with copybara is fixed. # pylint:disable=g-inconsistent-quotes models_lib = LazyLoader("models_lib", globals(), "tensorflow.python.keras.models") base_layer = LazyLoader("base_layer", globals(), "tensorflow.python.keras.engine.base_layer") network_lib = LazyLoader("network_lib", globals(), "tensorflow.python.keras.engine.network") training_lib = LazyLoader("training_lib", globals(), "tensorflow.python.keras.engine.training") # pylint:enable=g-inconsistent-quotes PUBLIC_ATTRIBUTES = CommonEndpoints.all_functions.union( CommonEndpoints.all_checkpointable_objects) PUBLIC_ATTRIBUTES.add(constants.KERAS_ATTR) def load(path, compile=True): # pylint: disable=redefined-builtin """Loads Keras objects from a SavedModel.
"""Gradient tape utilites.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import contextlib from tensorflow.python import pywrap_tensorflow from tensorflow.python.util.lazy_loader import LazyLoader # There is a circular dependency between this, ops.py, and # distribution_strategy_context. # TODO(b/117329403): Remove this circular dependency. distribution_strategy_context = LazyLoader( "distribute_lib", globals(), "tensorflow.python.training." "distribution_strategy_context") class Tape(object): """Represents a gradient propagation trace.""" def __init__(self, tape): self._tape = tape def watched_variables(self): return pywrap_tensorflow.TFE_Py_TapeWatchedVariables(self._tape) def push_new_tape(persistent=False, watch_accessed_variables=True): """Pushes a new tape onto the tape stack.""" tape = pywrap_tensorflow.TFE_Py_TapeSetNew(persistent,
from tensorflow.python.saved_model import nested_structure_coder from tensorflow.python.saved_model import revived_types from tensorflow.python.training.tracking import base as trackable from tensorflow.python.training.tracking.tracking import delete_tracking from tensorflow.python.util import compat from tensorflow.python.util import nest from tensorflow.python.util import object_identity from tensorflow.python.util.lazy_loader import LazyLoader # To avoid circular dependencies between keras/engine and keras/saving, # code in keras/saving must delay imports. # TODO(b/134426265): Switch back to single-quotes to match the rest of the file # once the issue with copybara is fixed. # pylint:disable=g-inconsistent-quotes models_lib = LazyLoader("models_lib", globals(), "tensorflow.python.keras.models") base_layer = LazyLoader("base_layer", globals(), "tensorflow.python.keras.engine.base_layer") layers_module = LazyLoader("layers_module", globals(), "tensorflow.python.keras.layers") input_layer = LazyLoader("input_layer", globals(), "tensorflow.python.keras.engine.input_layer") functional_lib = LazyLoader("functional_lib", globals(), "tensorflow.python.keras.engine.functional") training_lib = LazyLoader("training_lib", globals(), "tensorflow.python.keras.engine.training") training_lib_v1 = LazyLoader("training_lib_v1", globals(), "tensorflow.python.keras.engine.training_v1") metrics = LazyLoader("metrics", globals(), "tensorflow.python.keras.metrics") recurrent = LazyLoader("recurrent", globals(), "tensorflow.python.keras.layers.recurrent")
"""Python TF-Lite interpreter.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import sys import numpy as np from tensorflow.python.util.lazy_loader import LazyLoader from tensorflow.python.util.tf_export import tf_export as _tf_export # Lazy load since some of the performance benchmark skylark rules # break dependencies. Must use double quotes to match code internal rewrite # rule. # pylint: disable=g-inconsistent-quotes _interpreter_wrapper = LazyLoader( "_interpreter_wrapper", globals(), "tensorflow.contrib.lite.python.interpreter_wrapper." "tensorflow_wrap_interpreter_wrapper") # pylint: enable=g-inconsistent-quotes del LazyLoader @_tf_export('lite.Interpreter') class Interpreter(object): """Interpreter inferace for TF-Lite Models.""" def __init__(self, model_path=None, model_content=None): """Constructor. Args: model_path: Path to TF-Lite Flatbuffer file. model_content: Content of model.
# ============================================================================== """FeatureColumn serialization, deserialization logic.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import six from tensorflow.python.feature_column import feature_column_v2 as fc_lib from tensorflow.python.feature_column import sequence_feature_column as sfc_lib from tensorflow.python.ops import init_ops from tensorflow.python.util.lazy_loader import LazyLoader # Prevent circular dependencies with Keras serialization. generic_utils = LazyLoader('generic_utils', globals(), 'tensorflow.python.keras.utils.generic_utils') _FEATURE_COLUMNS = [ fc_lib.BucketizedColumn, fc_lib.CrossedColumn, fc_lib.EmbeddingColumn, fc_lib.HashedCategoricalColumn, fc_lib.IdentityCategoricalColumn, fc_lib.IndicatorColumn, fc_lib.NumericColumn, fc_lib.SequenceCategoricalColumn, fc_lib.SequenceDenseColumn, fc_lib.SharedEmbeddingColumn, fc_lib.VocabularyFileCategoricalColumn, fc_lib.VocabularyListCategoricalColumn, fc_lib.WeightedCategoricalColumn, init_ops.TruncatedNormal, sfc_lib.SequenceNumericColumn ] def serialize_feature_column(fc): """Serializes a FeatureColumn or a raw string key.
import sys import numpy as np # pylint: disable=g-import-not-at-top if not __file__.endswith('tflite_runtime/interpreter.py'): # This file is part of tensorflow package. from tensorflow.python.util.lazy_loader import LazyLoader from tensorflow.python.util.tf_export import tf_export as _tf_export # Lazy load since some of the performance benchmark skylark rules # break dependencies. Must use double quotes to match code internal rewrite # rule. # pylint: disable=g-inconsistent-quotes _interpreter_wrapper = LazyLoader( "_interpreter_wrapper", globals(), "tensorflow.lite.python.interpreter_wrapper." '_pywrap_tensorflow_interpreter_wrapper') # pylint: enable=g-inconsistent-quotes del LazyLoader else: # This file is part of tflite_runtime package. from tflite_runtime import interpreter_wrapper as _interpreter_wrapper def _tf_export(*x, **kwargs): del x, kwargs return lambda x: x class Delegate(object): """Python wrapper class to manage TfLiteDelegate objects.
from __future__ import print_function import itertools import types from tensorflow.python.eager import context from tensorflow.python.keras import backend as K from tensorflow.python.keras.engine import base_layer_utils from tensorflow.python.keras.utils import tf_utils from tensorflow.python.training.tracking import layer_utils as trackable_layer_utils from tensorflow.python.util import tf_decorator from tensorflow.python.util import tf_inspect from tensorflow.python.util.lazy_loader import LazyLoader # pylint:disable=g-inconsistent-quotes training_lib = LazyLoader("training_lib", globals(), "tensorflow.python.keras.engine.training") # pylint:enable=g-inconsistent-quotes def use_wrapped_call(layer, call_fn, default_training_value=None, return_method=False): """Creates fn that adds the losses returned by call_fn & returns the outputs. Args: layer: A Keras layer object call_fn: tf.function that takes layer inputs (and possibly a training arg), and returns a tuple of (outputs, list of losses). default_training_value: Default value of the training kwarg. If `None`, the default is `K.learning_phase()`.
import os as _os import subprocess as _subprocess import tempfile as _tempfile from tensorflow.contrib.lite.python import lite_constants from tensorflow.contrib.lite.toco import model_flags_pb2 as _model_flags_pb2 from tensorflow.contrib.lite.toco import toco_flags_pb2 as _toco_flags_pb2 from tensorflow.python.framework import dtypes as _dtypes from tensorflow.python.platform import resource_loader as _resource_loader from tensorflow.python.util.lazy_loader import LazyLoader # Lazy load since some of the performance benchmark skylark rules # break dependencies. _toco_python = LazyLoader( "tensorflow_wrap_toco", globals(), "tensorflow.contrib.lite.toco.python." "tensorflow_wrap_toco") del LazyLoader # Find the toco_from_protos binary using the resource loader if using from # bazel, otherwise we are in a pip where console_scripts already has # the toco_from_protos tool. if lite_constants.EXPERIMENTAL_USE_TOCO_API_DIRECTLY: _toco_from_proto_bin = "" else: _toco_from_proto_bin = _resource_loader.get_path_to_datafile( "../toco/python/toco_from_protos") if _toco_from_proto_bin and not _os.path.exists(_toco_from_proto_bin): _toco_from_proto_bin = "toco_from_protos"
"""Gradient tape utilites.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import contextlib from tensorflow.python import pywrap_tensorflow from tensorflow.python.util.lazy_loader import LazyLoader # There is a circular dependency between this, ops.py, and # distribution_strategy_context. # TODO(b/117329403): Remove this circular dependency. distribution_strategy_context = LazyLoader( "distribution_strategy_context", globals(), "tensorflow.python.distribute." "distribution_strategy_context") class Tape(object): """Represents a gradient propagation trace.""" def __init__(self, tape): self._tape = tape def watched_variables(self): return pywrap_tensorflow.TFE_Py_TapeWatchedVariables(self._tape) def push_new_tape(persistent=False, watch_accessed_variables=True): """Pushes a new tape onto the tape stack."""
# See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== """Utility to get tf.distribute.Strategy related contexts.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function from tensorflow.python.framework import ops from tensorflow.python.util.lazy_loader import LazyLoader from tensorflow.python.util.tf_export import tf_export # There is a circular dependency between this and `distribute` module. So we # load it lazily to workaround this. distribute_lib = LazyLoader("distribute_lib", globals(), "tensorflow.python.distribute.distribute_lib") # ------------------------------------------------------------------------------ # Internal API for setting the current thread mode as being either in a # replica or cross-replica context for a particular tf.distribute.Strategy. class _ThreadMode(object): def __init__(self, dist, cross, replica): self.strategy = dist self.cross_replica_context = cross self.replica_context = replica class _CrossReplicaThreadMode(_ThreadMode): def __init__(self, strategy):
import numpy as np import tensorflow as tf from conf import conf from models.tensorflow.common import TfModel from utils import get_all_2_element_combinations tfk = tf.keras K = tfk.backend import models.tensorflow.mykeras.layers as mylayers from tensorflow.python.util.lazy_loader import LazyLoader pfor_ops = LazyLoader("pfor_ops", globals(), "tensorflow.python.ops.parallel_for.control_flow_ops") class MonotonicConstraint(tfk.constraints.Constraint): def __init__(self, mon_size_in, non_mon_size_in, mon_size_out, non_mon_size_out, blocks): self._mon_size_in = mon_size_in self._non_mon_size_in = non_mon_size_in self._mon_size_out = mon_size_out self._non_mon_size_out = non_mon_size_out self._blocks = blocks def __call__(self, w): w_shape = w.shape block_in_size = self._mon_size_in + self._non_mon_size_in block_out_size = self._mon_size_out + self._non_mon_size_out
from tensorflow.python.ops import gen_array_ops from tensorflow.python.ops import gen_math_ops from tensorflow.python.ops import math_ops from tensorflow.python.ops import resource_variable_ops from tensorflow.python.ops.unconnected_gradients import UnconnectedGradients from tensorflow.python.platform import tf_logging as logging from tensorflow.python.util import nest from tensorflow.python.util import tf_contextlib from tensorflow.python.util import tf_inspect from tensorflow.python.util.lazy_loader import LazyLoader from tensorflow.python.util.tf_export import tf_export # Note that we need to lazy load the following two modules to avoid creating # circular dependencies. # TODO(b/119775953): fix the circular dependencies. pfor_ops = LazyLoader("pfor_ops", globals(), "tensorflow.python.ops.parallel_for.control_flow_ops") function = LazyLoader("function", globals(), "tensorflow.python.eager.function") _op_attr_type_cache = {} def op_attr_type(op_type, attr_name): try: return _op_attr_type_cache[(op_type, attr_name)] except KeyError: context.ensure_initialized() h = context.context()._handle # pylint: disable=protected-access attr_type = pywrap_tensorflow.TFE_OpNameGetAttrType( h, op_type, attr_name)
from tensorflow.python.ops import array_ops from tensorflow.python.ops import control_flow_ops from tensorflow.python.ops import gen_string_ops from tensorflow.python.ops import string_ops from tensorflow.python.ops.ragged import ragged_array_ops from tensorflow.python.ops.ragged import ragged_functional_ops from tensorflow.python.ops.ragged import ragged_math_ops from tensorflow.python.ops.ragged import ragged_tensor from tensorflow.python.util import compat as util_compat from tensorflow.python.util import deprecation from tensorflow.python.util import dispatch from tensorflow.python.util.lazy_loader import LazyLoader from tensorflow.python.util.tf_export import tf_export map_fn_lib = LazyLoader("map_fn_lib", globals(), "tensorflow.python.ops.map_fn") @tf_export("strings.bytes_split") @dispatch.add_dispatch_support def string_bytes_split(input, name=None): # pylint: disable=redefined-builtin """Split string elements of `input` into bytes. Examples: >>> tf.strings.bytes_split('hello').numpy() array([b'h', b'e', b'l', b'l', b'o'], dtype=object) >>> tf.strings.bytes_split(['hello', '123']) <tf.RaggedTensor [[b'h', b'e', b'l', b'l', b'o'], [b'1', b'2', b'3']]> Note that this op splits strings into bytes, not unicode characters. To
from tensorflow.python.keras.saving.saved_model import utils from tensorflow.python.platform import tf_logging as logging from tensorflow.python.training.tracking import base as trackable from tensorflow.python.training.tracking import data_structures from tensorflow.python.util import nest from tensorflow.python.util import tf_decorator from tensorflow.python.util import tf_inspect from tensorflow.python.util.lazy_loader import LazyLoader # To avoid circular dependencies between keras/engine and keras/saving, # code in keras/saving must delay imports. # TODO(b/134426265): Switch back to single-quotes to match the rest of the file # once the issue with copybara is fixed. # pylint:disable=g-inconsistent-quotes base_layer = LazyLoader("base_layer", globals(), "tensorflow.python.keras.engine.base_layer") input_layer = LazyLoader("input_layer", globals(), "tensorflow.python.keras.engine.input_layer") training_lib = LazyLoader("training_lib", globals(), "tensorflow.python.keras.engine.training") sequential_lib = LazyLoader("sequential_lib", globals(), "tensorflow.python.keras.engine.sequential") # pylint:enable=g-inconsistent-quotes def should_skip_serialization(layer): """Skip serializing extra objects and functions if layer inputs aren't set.""" if isinstance(layer, training_lib.Model): try: # pylint:disable=pointless-statement layer.inputs
from tensorflow.python.saved_model import nested_structure_coder from tensorflow.python.saved_model import revived_types from tensorflow.python.training.tracking import base as trackable from tensorflow.python.training.tracking.tracking import delete_tracking from tensorflow.python.util import compat from tensorflow.python.util import nest from tensorflow.python.util import object_identity from tensorflow.python.util.lazy_loader import LazyLoader # To avoid circular dependencies between keras/engine and keras/saving, # code in keras/saving must delay imports. # TODO(b/134426265): Switch back to single-quotes to match the rest of the file # once the issue with copybara is fixed. # pylint:disable=g-inconsistent-quotes models_lib = LazyLoader("models_lib", globals(), "tensorflow.python.keras.models") base_layer = LazyLoader("base_layer", globals(), "tensorflow.python.keras.engine.base_layer") layers_module = LazyLoader("layers_module", globals(), "tensorflow.python.keras.layers") input_layer = LazyLoader("input_layer", globals(), "tensorflow.python.keras.engine.input_layer") network_lib = LazyLoader("network_lib", globals(), "tensorflow.python.keras.engine.network") training_lib = LazyLoader("training_lib", globals(), "tensorflow.python.keras.engine.training") training_lib_v1 = LazyLoader("training_lib_v1", globals(), "tensorflow.python.keras.engine.training_v1") metrics = LazyLoader("metrics", globals(), "tensorflow.python.keras.metrics") # pylint:enable=g-inconsistent-quotes
from tensorflow.python.framework.auto_control_deps import AutomaticControlDependencies from tensorflow.python.ops import array_ops from tensorflow.python.ops import custom_gradient from tensorflow.python.ops import resource_variable_ops from tensorflow.python.ops import tensor_array_ops from tensorflow.python.ops import variable_scope from tensorflow.python.util import compat from tensorflow.python.util import memory from tensorflow.python.util import nest from tensorflow.python.util import tf_contextlib from tensorflow.python.util import tf_decorator from tensorflow.python.util.lazy_loader import LazyLoader # This is to avoid a circular dependency: # function -> func_graph function = LazyLoader("function", globals(), "tensorflow.python.eager.function") def_function = LazyLoader("def_function", globals(), "tensorflow.python.eager.def_function") WHITELIST_COLLECTIONS = [ ops.GraphKeys.GLOBAL_VARIABLES, ops.GraphKeys.LOCAL_VARIABLES, ops.GraphKeys.TRAINABLE_VARIABLES, variable_scope._VARSTORE_KEY, # pylint: disable=protected-access variable_scope._VARSCOPESTORE_KEY # pylint: disable=protected-access ] class UnknownArgument(object): """Signifies an argument which is not currently handled.""" pass
# See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== # Bring in all of the public TensorFlow interface into this # module. from __future__ import absolute_import from __future__ import division from __future__ import print_function # pylint: disable=g-bad-import-order from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import from tensorflow.python.util.lazy_loader import LazyLoader contrib = LazyLoader('contrib', globals(), 'tensorflow.contrib') del LazyLoader from tensorflow.python.platform import flags # pylint: disable=g-import-not-at-top app.flags = flags # pylint: disable=undefined-variable del absolute_import del division del print_function # These symbols appear because we import the python package which # in turn imports from tensorflow.core and tensorflow.python. They # must come from this module. So python adds these symbols for the # resolution to succeed. # pylint: disable=undefined-variable del python
from tensorflow.python.saved_model import builder from tensorflow.python.saved_model import load from tensorflow.python.saved_model import loader from tensorflow.python.saved_model import loader_impl from tensorflow.python.saved_model import save from tensorflow.python.saved_model import signature_constants from tensorflow.python.saved_model import signature_def_utils from tensorflow.python.saved_model import tag_constants from tensorflow.python.saved_model import utils from tensorflow.python.tools import saved_model_utils from tensorflow.python.training.tracking import tracking from tensorflow.python.util.lazy_loader import LazyLoader _SAVED_MODEL_SIGNATURE_KEY = "mypredict" gen_trt_ops = LazyLoader("gen_trt_ops", globals(), "tensorflow.compiler.tf2tensorrt.ops.gen_trt_ops") class TrtConvertTest(test_util.TensorFlowTestCase, parameterized.TestCase): """Class to test Tensorflow-TensorRT integration python API.""" # Use a small max_workspace_size for tests so they don't consume too much GPU # memory. _TRT_MAX_WORKSPACE_SIZE_BYTES = 2 << 20 def mkdtemp(self): return tempfile.mkdtemp(dir=self.get_temp_dir()) def testTRTEngineInstanceAvailable(self): # test if we can access the TRTEngineInstance protobuf assert hasattr(TRTEngineInstance(), "serialized_engine")
import re from tensorflow.python.framework import constant_op from tensorflow.python.framework import dtypes from tensorflow.python.framework import ops from tensorflow.python.framework import tensor_shape from tensorflow.python.ops import array_ops from tensorflow.python.ops import math_ops from tensorflow.python.ops import sparse_ops from tensorflow.python.platform import tf_logging from tensorflow.python.util.lazy_loader import LazyLoader from tensorflow.python.util.tf_export import tf_export # Avoid circular dependencies with RaggedTensor. # TODO(b/141170488) Refactor ragged modules so this is unnecessary. ragged_tensor = LazyLoader("ragged_tensor", globals(), "tensorflow.python.ops.ragged.ragged_tensor") ragged_math_ops = LazyLoader("ragged_math_ops", globals(), "tensorflow.python.ops.ragged.ragged_math_ops") # TODO(b/122887740) Refactor code: # * Move input verification to feature configuration objects (e.g., # VarLenFeature should check that dtype is a valid dtype). # * Add an _add_feature() method to each feature configuration object # (rather than using a dispatch table in _ParseOpParams._add_feature). # * Update _construct_tensors_for_composite_features() to call a method # on the feature object (rather than using dispatch). @tf_export("io.VarLenFeature", v1=["VarLenFeature", "io.VarLenFeature"]) class VarLenFeature(collections.namedtuple("VarLenFeature", ["dtype"])): """Configuration for parsing a variable-length input feature.