Browse Source

!9317 fix the docstring of SummaryCollector and SummaryRecord

From: @ouwenchang
Reviewed-by: @lilongfei15,@jonyguo
Signed-off-by: @jonyguo
tags/v1.1.0
mindspore-ci-bot Gitee 5 years ago
parent
commit
7c38b072d4
2 changed files with 22 additions and 15 deletions
  1. +7
    -3
      mindspore/train/callback/_summary_collector.py
  2. +15
    -12
      mindspore/train/summary/summary_record.py

+ 7
- 3
mindspore/train/callback/_summary_collector.py View File

@@ -135,13 +135,17 @@ class SummaryCollector(Callback):


Examples: Examples:
>>> # Simple usage: >>> # Simple usage:
>>> from mindspore.train import Model
>>> summary_collector = SummaryCollector(summary_dir='./summary_dir') >>> summary_collector = SummaryCollector(summary_dir='./summary_dir')
>>> model.train(epoch, dataset, callbacks=summary_collector)
>>> dataset = get_dataset('/path/to/MNIST')
>>> network = LeNet5()
>>> model = Model(network)
>>> model.train(epoch=1, dataset=dataset, callbacks=summary_collector)
>>> >>>
>>> # Do not collect metric and collect the first layer parameter, others are collected by default >>> # Do not collect metric and collect the first layer parameter, others are collected by default
>>> specified={'collect_metric': False, 'histogram_regular': '^conv1.*'} >>> specified={'collect_metric': False, 'histogram_regular': '^conv1.*'}
>>> summary_collector = SummaryCollector(summary_dir='./summary_dir', collect_specified_data=specified) >>> summary_collector = SummaryCollector(summary_dir='./summary_dir', collect_specified_data=specified)
>>> model.train(epoch, dataset, callbacks=summary_collector)
>>> model.train(epoch=1, dataset=dataset, callbacks=summary_collector)
>>> >>>
>>> # Only collect metric, custom lineage data and record data that collected by the summary operator, >>> # Only collect metric, custom lineage data and record data that collected by the summary operator,
>>> # others are not collected >>> # others are not collected
@@ -151,7 +155,7 @@ class SummaryCollector(Callback):
>>> keep_default_action=False, >>> keep_default_action=False,
>>> custom_lineage_data={'version': 'resnet50_v1'} >>> custom_lineage_data={'version': 'resnet50_v1'}
>>> ) >>> )
>>> model.train(epoch, dataset, callbacks=summary_collector)
>>> model.train(epoch=1, dataset=dataset, callbacks=summary_collector)
""" """


_DEFAULT_SPECIFIED_DATA = { _DEFAULT_SPECIFIED_DATA = {


+ 15
- 12
mindspore/train/summary/summary_record.py View File

@@ -89,14 +89,15 @@ class SummaryRecord:


Examples: Examples:
>>> # use in with statement to auto close >>> # use in with statement to auto close
>>> from mindspore.train.summary import SummaryRecord
>>> with SummaryRecord(log_dir="./summary_dir") as summary_record: >>> with SummaryRecord(log_dir="./summary_dir") as summary_record:
>>> pass
... pass
>>> >>>
>>> # use in try .. finally .. to ensure closing >>> # use in try .. finally .. to ensure closing
>>> try: >>> try:
>>> summary_record = SummaryRecord(log_dir="./summary_dir")
>>> finally:
>>> summary_record.close()
... summary_record = SummaryRecord(log_dir="./summary_dir")
... finally:
... summary_record.close()
""" """


def __init__(self, log_dir, file_prefix="events", file_suffix="_MS", network=None, max_file_size=None): def __init__(self, log_dir, file_prefix="events", file_suffix="_MS", network=None, max_file_size=None):
@@ -162,7 +163,7 @@ class SummaryRecord:


Examples: Examples:
>>> with SummaryRecord(log_dir="./summary_dir", file_prefix="xxx_", file_suffix="_yyy") as summary_record: >>> with SummaryRecord(log_dir="./summary_dir", file_prefix="xxx_", file_suffix="_yyy") as summary_record:
>>> summary_record.set_mode('eval')
... summary_record.set_mode('eval')
""" """
mode_spec = 'train', 'eval' mode_spec = 'train', 'eval'
if mode not in mode_spec: if mode not in mode_spec:
@@ -199,7 +200,7 @@ class SummaryRecord:


Examples: Examples:
>>> with SummaryRecord(log_dir="./summary_dir", file_prefix="xxx_", file_suffix="_yyy") as summary_record: >>> with SummaryRecord(log_dir="./summary_dir", file_prefix="xxx_", file_suffix="_yyy") as summary_record:
>>> summary_record.add_value('scalar', 'loss', Tensor(0.1))
... summary_record.add_value('scalar', 'loss', Tensor(0.1))
""" """
if plugin in ('tensor', 'scalar', 'image', 'histogram'): if plugin in ('tensor', 'scalar', 'image', 'histogram'):
if not name or not isinstance(name, str): if not name or not isinstance(name, str):
@@ -239,7 +240,9 @@ class SummaryRecord:


Examples: Examples:
>>> with SummaryRecord(log_dir="./summary_dir", file_prefix="xxx_", file_suffix="_yyy") as summary_record: >>> with SummaryRecord(log_dir="./summary_dir", file_prefix="xxx_", file_suffix="_yyy") as summary_record:
>>> summary_record.record(step=2)
... summary_record.record(step=2)
...
True
""" """
logger.debug("SummaryRecord step is %r.", step) logger.debug("SummaryRecord step is %r.", step)
if self._closed: if self._closed:
@@ -303,7 +306,7 @@ class SummaryRecord:


Examples: Examples:
>>> with SummaryRecord(log_dir="./summary_dir", file_prefix="xxx_", file_suffix="_yyy") as summary_record: >>> with SummaryRecord(log_dir="./summary_dir", file_prefix="xxx_", file_suffix="_yyy") as summary_record:
>>> print(summary_record.log_dir)
... log_dir = summary_record.log_dir
""" """
return self.full_file_name return self.full_file_name


@@ -315,7 +318,7 @@ class SummaryRecord:


Examples: Examples:
>>> with SummaryRecord(log_dir="./summary_dir", file_prefix="xxx_", file_suffix="_yyy") as summary_record: >>> with SummaryRecord(log_dir="./summary_dir", file_prefix="xxx_", file_suffix="_yyy") as summary_record:
>>> summary_record.flush()
... summary_record.flush()
""" """
if self._closed: if self._closed:
logger.error("The record writer is closed and can not flush.") logger.error("The record writer is closed and can not flush.")
@@ -328,9 +331,9 @@ class SummaryRecord:


Examples: Examples:
>>> try: >>> try:
>>> summary_record = SummaryRecord(log_dir="./summary_dir")
>>> finally:
>>> summary_record.close()
... summary_record = SummaryRecord(log_dir="./summary_dir")
... finally:
... summary_record.close()
""" """
if not self._closed and self._event_writer: if not self._closed and self._event_writer:
# event writer flush and close # event writer flush and close


Loading…
Cancel
Save