Returns a context manager that enables summary writing.
For convenience, if step is not None, this function also sets a default
value for the step parameter used in summary-writing functions elsewhere
in the API so that it need not be explicitly passed in every such
invocation. The value can be a constant or a variable.
For example, step can be used as:
withwriter_a.as_default(step=10):tf.summary.scalar(tag,value)# Logged to writer_a with step 10withwriter_b.as_default(step=20):tf.summary.scalar(tag,value)# Logged to writer_b with step 20tf.summary.scalar(tag,value)# Logged to writer_a with step 10
Args
step
An int64-castable default step value, or None. When not None,
the current step is captured, replaced by a given one, and the original
one is restored when the context manager exits. When None, the current
step is not modified (and not restored when the context manager exits).
Enables this summary writer for the current thread.
For convenience, if step is not None, this function also sets a default
value for the step parameter used in summary-writing functions elsewhere
in the API so that it need not be explicitly passed in every such
invocation. The value can be a constant or a variable.
Args
step
An int64-castable default step value, or None. When not None,
the current step is modified to the given value. When None, the
current step is not modified.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.summary.SummaryWriter\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/summary_ops_v2.py#L239-L307) |\n\nInterface representing a stateful summary writer object.\n\nMethods\n-------\n\n### `as_default`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/summary_ops_v2.py#L263-L295) \n\n as_default(\n step=None\n )\n\nReturns a context manager that enables summary writing.\n\nFor convenience, if `step` is not None, this function also sets a default\nvalue for the `step` parameter used in summary-writing functions elsewhere\nin the API so that it need not be explicitly passed in every such\ninvocation. The value can be a constant or a variable.\n| **Note:** when setting `step` in a @tf.function, the step value will be captured at the time the function is traced, so changes to the step outside the function will not be reflected inside the function unless using a [`tf.Variable`](../../tf/Variable) step.\n\nFor example, `step` can be used as: \n\n with writer_a.as_default(step=10):\n tf.summary.scalar(tag, value) # Logged to writer_a with step 10\n with writer_b.as_default(step=20):\n tf.summary.scalar(tag, value) # Logged to writer_b with step 20\n tf.summary.scalar(tag, value) # Logged to writer_a with step 10\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `step` | An `int64`-castable default step value, or `None`. When not `None`, the current step is captured, replaced by a given one, and the original one is restored when the context manager exits. When `None`, the current step is not modified (and not restored when the context manager exits). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| The context manager. ||\n\n\u003cbr /\u003e\n\n### `close`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/summary_ops_v2.py#L305-L307) \n\n close()\n\nFlushes and closes the summary writer.\n\n### `flush`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/summary_ops_v2.py#L301-L303) \n\n flush()\n\nFlushes any buffered data.\n\n### `init`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/summary_ops_v2.py#L297-L299) \n\n init()\n\nInitializes the summary writer.\n\n### `set_as_default`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/summary_ops_v2.py#L243-L261) \n\n set_as_default(\n step=None\n )\n\nEnables this summary writer for the current thread.\n\nFor convenience, if `step` is not None, this function also sets a default\nvalue for the `step` parameter used in summary-writing functions elsewhere\nin the API so that it need not be explicitly passed in every such\ninvocation. The value can be a constant or a variable.\n| **Note:** when setting `step` in a @tf.function, the step value will be captured at the time the function is traced, so changes to the step outside the function will not be reflected inside the function unless using a [`tf.Variable`](../../tf/Variable) step.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `step` | An `int64`-castable default step value, or `None`. When not `None`, the current step is modified to the given value. When `None`, the current step is not modified. |\n\n\u003cbr /\u003e"]]