本文整理匯總了Python中tensorflow.compat方法的典型用法代碼示例。如果您正苦於以下問題:Python tensorflow.compat方法的具體用法?Python tensorflow.compat怎麽用?Python tensorflow.compat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tensorflow
的用法示例。
在下文中一共展示了tensorflow.compat方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_tf_summary_export
# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import compat [as 別名]
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)
示例2: __init__
# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import compat [as 別名]
def __init__(self):
modules = []
if hasattr(tf_.compat, 'v1'):
modules.append(tf_.compat.v1)
self.modules = modules
示例3: import_tf
# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import compat [as 別名]
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