將 Python 實體轉換為 TensorFlow 圖。
用法
tf.compat.v1.autograph.to_graph(
entity, recursive=True, arg_values=None, arg_types=None,
experimental_optional_features=None
)
參數
-
entity
Python 可調用或要轉換的類。 -
recursive
是否遞歸轉換轉換後的函數可能調用的任何函數。 -
arg_values
已棄用。 -
arg_types
已棄用。 -
experimental_optional_features
None
,一個元組或單個tf.autograph.experimental.Feature
值。
返回
-
與
entity
相同,轉換後的 Python 函數或類。
拋出
-
ValueError
如果無法轉換實體。
另請參閱:tf.autograph.to_code
、tf.function
。
與 tf.function
不同,to_graph
是一個將 Python 代碼轉換為 TensorFlow 圖形代碼的低級轉譯器。它不實現任何緩存、變量管理或創建任何實際操作,最好用於需要對生成的 TensorFlow 圖進行更大控製的地方。與 tf.function
的另一個區別是 to_graph
不會將圖形包裝到 TensorFlow 函數或 Python 可調用文件中。在內部,tf.function
使用 to_graph
。
示例用法
def foo(x):
if x > 0:
y = x * x
else:
y = -x
return y
converted_foo = to_graph(foo)
x = tf.constant(1)
y = converted_foo(x) # converted_foo is a TensorFlow Op-like.
assert is_tensor(y)
支持的 Python 實體包括:
- functions
- classes
- 對象方法
使用轉換後的代碼將函數轉換為新函數。
通過生成其方法使用轉換代碼的新類來轉換類。
方法被轉換為具有額外的第一個參數 self
的未綁定函數。
相關用法
- Python tf.compat.v1.autograph.to_code用法及代碼示例
- Python tf.compat.v1.assert_none_equal用法及代碼示例
- Python tf.compat.v1.assign_add用法及代碼示例
- Python tf.compat.v1.assert_near用法及代碼示例
- Python tf.compat.v1.assert_negative用法及代碼示例
- Python tf.compat.v1.assert_less_equal用法及代碼示例
- Python tf.compat.v1.arg_max用法及代碼示例
- Python tf.compat.v1.arg_min用法及代碼示例
- Python tf.compat.v1.assign用法及代碼示例
- Python tf.compat.v1.assign_sub用法及代碼示例
- Python tf.compat.v1.argmin用法及代碼示例
- Python tf.compat.v1.assert_non_positive用法及代碼示例
- Python tf.compat.v1.argmax用法及代碼示例
- Python tf.compat.v1.assert_integer用法及代碼示例
- Python tf.compat.v1.assert_greater用法及代碼示例
- Python tf.compat.v1.assert_non_negative用法及代碼示例
- Python tf.compat.v1.assert_rank_at_least用法及代碼示例
- Python tf.compat.v1.assert_less用法及代碼示例
- Python tf.compat.v1.assert_rank_in用法及代碼示例
- Python tf.compat.v1.assert_greater_equal用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.autograph.to_graph。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。