def enable_v2_behavior(): """Enables TensorFlow 2.x behaviors. This function can be called at the beginning of the program (before `Tensors`, `Graphs` or other structures have been created, and before devices have been initialized. It switches all global behaviors that are different between TensorFlow 1.x and 2.x to behave as intended for 2.x. This function is called in the main TensorFlow `__init__.py` file, user should not need to call it, except during complex migrations. """ # TF2 behavior is enabled if either 1) enable_v2_behavior() is called or # 2) the TF2_BEHAVIOR=1 environment variable is set. In the latter case, # the modules below independently check if tf2.enabled(). tf2.enable() ops.enable_eager_execution() tensor_shape.enable_v2_tensorshape() # Also switched by tf2 variable_scope.enable_resource_variables() ops.enable_tensor_equality() # Enables TensorArrayV2 and control flow V2. control_flow_v2_toggles.enable_control_flow_v2() # Make sure internal uses of tf.data symbols map to V2 versions. dataset_ops.Dataset = dataset_ops.DatasetV2 readers.FixedLengthRecordDataset = readers.FixedLengthRecordDatasetV2 readers.TFRecordDataset = readers.TFRecordDatasetV2 readers.TextLineDataset = readers.TextLineDatasetV2 counter.Counter = counter.CounterV2 interleave_ops.choose_from_datasets = interleave_ops.choose_from_datasets_v2 interleave_ops.sample_from_datasets = interleave_ops.sample_from_datasets_v2 random_ops.RandomDataset = random_ops.RandomDatasetV2 exp_readers.CsvDataset = exp_readers.CsvDatasetV2 exp_readers.SqlDataset = exp_readers.SqlDatasetV2 exp_readers.make_batched_features_dataset = ( exp_readers.make_batched_features_dataset_v2) exp_readers.make_csv_dataset = exp_readers.make_csv_dataset_v2
def test_initializer_v2_get(self): tf2_force_enabled = tf2._force_enable # pylint: disable=protected-access try: tf2.enable() rn = keras.initializers.get('random_normal') self.assertIn('init_ops_v2', rn.__class__.__module__) finally: tf2._force_enable = tf2_force_enabled # pylint: disable=protected-access
def test_initializer_v2_get(self): tf2_force_enabled = tf2._force_enable # pylint: disable=protected-access try: tf2.enable() rn = initializers.get('random_normal') self.assertIn('init_ops_v2', rn.__class__.__module__) finally: tf2._force_enable = tf2_force_enabled # pylint: disable=protected-access
def main(): """Runs all unit tests with select TF 2.0 features enabled. This function should only be used if TensorFlow code is being tested. Eventually, all TF 2.0 features will be enabled. """ tf2.enable() # Switches TensorArrayV2 and control flow V2 tf.enable_v2_tensorshape() tf.enable_resource_variables() # Required since we use defuns. tf.test.main()
def enable_v2_behavior(): """Enables TensorFlow 2.x behaviors. This function can be called at the beginning of the program (before `Tensors`, `Graphs` or other structures have been created, and before devices have been initialized. It switches all global behaviors that are different between TensorFlow 1.x and 2.x to behave as intended for 2.x. This function is called in the main TensorFlow `__init__.py` file, user should not need to call it, except during complex migrations. """ tf2.enable() # Switches TensorArrayV2 and control flow V2 ops.enable_eager_execution() tensor_shape.enable_v2_tensorshape() # Also switched by tf2 variable_scope.enable_resource_variables()
def enable_v2_behavior(): """Enables TensorFlow 2.x behaviors. This function can be called at the beginning of the program (before `Tensors`, `Graphs` or other structures have been created, and before devices have been initialized. It switches all global behaviors that are different between TensorFlow 1.x and 2.x to behave as intended for 2.x. This function is called in the main TensorFlow `__init__.py` file, user should not need to call it, except during complex migrations. """ tf2.enable() # Switches TensorArrayV2 and control flow V2 ops.enable_eager_execution() tensor_shape.enable_v2_tensorshape() # Also switched by tf2 variable_scope.enable_resource_variables()
def enable_v2_behavior(): """Enables TensorFlow 2.x behaviors. This function can be called at the beginning of the program (before `Tensors`, `Graphs` or other structures have been created, and before devices have been initialized. It switches all global behaviors that are different between TensorFlow 1.x and 2.x to behave as intended for 2.x. This function is called in the main TensorFlow `__init__.py` file, user should not need to call it, except during complex migrations. """ # TF2 behavior is enabled if either 1) enable_v2_behavior() is called or # 2) the TF2_BEHAVIOR=1 environment variable is set. In the latter case, # the modules below independently check if tf2.enabled(). tf2.enable() ops.enable_eager_execution() tensor_shape.enable_v2_tensorshape() # Also switched by tf2 variable_scope.enable_resource_variables() # Enables TensorArrayV2 and control flow V2. control_flow_v2_toggles.enable_control_flow_v2()
def setUp(self): super().setUp() tf2.enable()
import distutils as _distutils import inspect as _inspect import logging as _logging import os as _os import site as _site import six as _six import sys as _sys from tensorflow.python.tools import module_util as _module_util from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader # Make sure code inside the TensorFlow codebase can use tf2.enabled() at import. _os.environ['TF2_BEHAVIOR'] = '1' from tensorflow.python import tf2 as _tf2 _tf2.enable() # API IMPORTS PLACEHOLDER # WRAPPER_PLACEHOLDER # Make sure directory containing top level submodules is in # the __path__ so that "from tensorflow.foo import bar" works. # We're using bitwise, but there's nothing special about that. _API_MODULE = _sys.modules[__name__].bitwise _tf_api_dir = _os.path.dirname(_os.path.dirname(_API_MODULE.__file__)) _current_module = _sys.modules[__name__] if not hasattr(_current_module, '__path__'): __path__ = [_tf_api_dir] elif _tf_api_dir not in __path__: