MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / to_graph_v1

Function to_graph_v1

tensorflow/python/autograph/impl/api.py:622–690  ·  view source on GitHub ↗

Converts a Python entity into a TensorFlow graph. Also see: `tf.autograph.to_code`, `tf.function`. Unlike `tf.function`, `to_graph` is a low-level transpiler that converts Python code to TensorFlow graph code. It does not implement any caching, variable management or create any actual ops,

(entity,
                recursive=True,
                arg_values=None,
                arg_types=None,
                experimental_optional_features=None)

Source from the content-addressed store, hash-verified

620
621@tf_export(v1=['autograph.to_graph'])
622def to_graph_v1(entity,
623 recursive=True,
624 arg_values=None,
625 arg_types=None,
626 experimental_optional_features=None):
627 """Converts a Python entity into a TensorFlow graph.
628
629 Also see: `tf.autograph.to_code`, `tf.function`.
630
631 Unlike `tf.function`, `to_graph` is a low-level transpiler that converts
632 Python code to TensorFlow graph code. It does not implement any caching,
633 variable management or create any actual ops, and is best used where greater
634 control over the generated TensorFlow graph is desired. Another difference
635 from `tf.function` is that `to_graph` will not wrap the graph into a
636 TensorFlow function or a Python callable. Internally, `tf.function` uses
637 `to_graph`.
638
639 _Example Usage_
640
641 ```python
642 def foo(x):
643 if x > 0:
644 y = x * x
645 else:
646 y = -x
647 return y
648
649 converted_foo = to_graph(foo)
650
651 x = tf.constant(1)
652 y = converted_foo(x) # converted_foo is a TensorFlow Op-like.
653 assert is_tensor(y)
654 ```
655
656 Supported Python entities include:
657 * functions
658 * classes
659 * object methods
660
661 Functions are converted into new functions with converted code.
662
663 Classes are converted by generating a new class whose methods use converted
664 code.
665
666 Methods are converted into unbound function that have an additional first
667 argument called `self`.
668
669 Args:
670 entity: Python callable or class to convert.
671 recursive: Whether to recursively convert any functions that the converted
672 function may call.
673 arg_values: Deprecated.
674 arg_types: Deprecated.
675 experimental_optional_features: `None`, a tuple of, or a single
676 `tf.autograph.experimental.Feature` value. Controls the use of optional
677 features in the conversion process.
678
679 Returns:

Callers

nothing calls this directly

Calls 1

to_graphFunction · 0.85

Tested by

no test coverage detected