Python tensorflow.compat() Examples

The following are 3 code examples of tensorflow.compat(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tensorflow , or try the search function .
Example #1
Source File: tf_summary_test.py    From tensorboard with Apache License 2.0 6 votes vote down vote up
def test_tf_summary_export(self):
        # Ensure that TF wasn't already imported, since we want this test to cover
        # the entire flow of "import tensorflow; use tf.summary" and if TF was in
        # fact already imported that reduces the comprehensiveness of the test.
        # This means this test has to be kept in its own file and that no other
        # test methods in this file should import tensorflow.
        self.assertEqual("notfound", sys.modules.get("tensorflow", "notfound"))
        import tensorflow as tf

        if not tf.__version__.startswith("2."):
            if hasattr(tf, "compat") and hasattr(tf.compat, "v2"):
                tf = tf.compat.v2
            else:
                self.skipTest("TF v2 summary API not available")
        # Check that tf.summary contains both TB-provided and TF-provided symbols.
        expected_symbols = frozenset(
            ["scalar", "image", "audio", "histogram", "text"]
            + ["write", "create_file_writer", "SummaryWriter"]
        )
        self.assertLessEqual(expected_symbols, frozenset(dir(tf.summary)))
        # Ensure we can dereference symbols as well.
        print(tf.summary.scalar)
        print(tf.summary.write) 
Example #2
Source File: __init__.py    From batchflow with Apache License 2.0 5 votes vote down vote up
def __init__(self):
        modules = []
        if hasattr(tf_.compat, 'v1'):
            modules.append(tf_.compat.v1)

        self.modules = modules 
Example #3
Source File: formatter.py    From law with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def import_tf(cls):
        import tensorflow as tf

        # keep a reference to the v1 API as long as v2 provides compatibility
        tf1 = None
        tf_version = tf.__version__.split(".", 2)
        if tf_version[0] == "1":
            tf1 = tf
        elif getattr(tf, "compat", None) is not None and getattr(tf.compat, "v1", None) is not None:
            tf1 = tf.compat.v1

        return tf, tf1, tf_version