Writes a TensorFlow graph to the summary interface. The graph summary is, strictly speaking, not a summary. Conditions like `tf.summary.should_record_summaries` do not apply. Only a single graph can be associated with a particular run. If multiple graphs are written, then only the last one
(param, step=None, name=None)
| 838 | |
| 839 | |
| 840 | def graph(param, step=None, name=None): |
| 841 | """Writes a TensorFlow graph to the summary interface. |
| 842 | |
| 843 | The graph summary is, strictly speaking, not a summary. Conditions |
| 844 | like `tf.summary.should_record_summaries` do not apply. Only |
| 845 | a single graph can be associated with a particular run. If multiple |
| 846 | graphs are written, then only the last one will be considered by |
| 847 | TensorBoard. |
| 848 | |
| 849 | When not using eager execution mode, the user should consider passing |
| 850 | the `graph` parameter to `tf.compat.v1.summary.initialize` instead of |
| 851 | calling this function. Otherwise special care needs to be taken when |
| 852 | using the graph to record the graph. |
| 853 | |
| 854 | Args: |
| 855 | param: A `tf.Tensor` containing a serialized graph proto. When |
| 856 | eager execution is enabled, this function will automatically |
| 857 | coerce `tf.Graph`, `tf.compat.v1.GraphDef`, and string types. |
| 858 | step: The global step variable. This doesn't have useful semantics |
| 859 | for graph summaries, but is used anyway, due to the structure of |
| 860 | event log files. This defaults to the global step. |
| 861 | name: A name for the operation (optional). |
| 862 | |
| 863 | Returns: |
| 864 | The created `tf.Operation` or a `tf.no_op` if summary writing has |
| 865 | not been enabled for this context. |
| 866 | |
| 867 | Raises: |
| 868 | TypeError: If `param` isn't already a `tf.Tensor` in graph mode. |
| 869 | """ |
| 870 | if not context.executing_eagerly() and not isinstance(param, ops.Tensor): |
| 871 | raise TypeError("graph() needs a tf.Tensor (e.g. tf.placeholder) in graph " |
| 872 | "mode, but was: %s" % type(param)) |
| 873 | writer = context.context().summary_writer |
| 874 | if writer is None: |
| 875 | return control_flow_ops.no_op() |
| 876 | with ops.device("cpu:0"): |
| 877 | if isinstance(param, (ops.Graph, graph_pb2.GraphDef)): |
| 878 | tensor = ops.convert_to_tensor(_serialize_graph(param), dtypes.string) |
| 879 | else: |
| 880 | tensor = array_ops.identity(param) |
| 881 | return gen_summary_ops.write_graph_summary( |
| 882 | writer._resource, _choose_step(step), tensor, name=name) # pylint: disable=protected-access |
| 883 | |
| 884 | |
| 885 | _graph = graph # for functions with a graph parameter |