From bc23af20d6340fa69f112e605e49ff33f4b8c956 Mon Sep 17 00:00:00 2001 From: ougongchang Date: Tue, 1 Dec 2020 20:27:47 +0800 Subject: [PATCH] fix the docstring of SummaryCollector and SummaryRecord --- .../train/callback/_summary_collector.py | 10 ++++--- mindspore/train/summary/summary_record.py | 27 ++++++++++--------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/mindspore/train/callback/_summary_collector.py b/mindspore/train/callback/_summary_collector.py index 9d13c3adbc..93c79bef73 100644 --- a/mindspore/train/callback/_summary_collector.py +++ b/mindspore/train/callback/_summary_collector.py @@ -135,13 +135,17 @@ class SummaryCollector(Callback): Examples: >>> # Simple usage: + >>> from mindspore.train import Model >>> 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 >>> specified={'collect_metric': False, 'histogram_regular': '^conv1.*'} >>> 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, >>> # others are not collected @@ -151,7 +155,7 @@ class SummaryCollector(Callback): >>> keep_default_action=False, >>> 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 = { diff --git a/mindspore/train/summary/summary_record.py b/mindspore/train/summary/summary_record.py index d84df9f5e1..f7db1d857f 100644 --- a/mindspore/train/summary/summary_record.py +++ b/mindspore/train/summary/summary_record.py @@ -89,14 +89,15 @@ class SummaryRecord: Examples: >>> # use in with statement to auto close + >>> from mindspore.train.summary import SummaryRecord >>> with SummaryRecord(log_dir="./summary_dir") as summary_record: - >>> pass + ... pass >>> >>> # use in try .. finally .. to ensure closing >>> 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): @@ -162,7 +163,7 @@ class SummaryRecord: Examples: >>> 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' if mode not in mode_spec: @@ -199,7 +200,7 @@ class SummaryRecord: Examples: >>> 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 not name or not isinstance(name, str): @@ -239,7 +240,9 @@ class SummaryRecord: Examples: >>> 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) if self._closed: @@ -303,7 +306,7 @@ class SummaryRecord: Examples: >>> 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 @@ -315,7 +318,7 @@ class SummaryRecord: Examples: >>> with SummaryRecord(log_dir="./summary_dir", file_prefix="xxx_", file_suffix="_yyy") as summary_record: - >>> summary_record.flush() + ... summary_record.flush() """ if self._closed: logger.error("The record writer is closed and can not flush.") @@ -328,9 +331,9 @@ class SummaryRecord: Examples: >>> 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: # event writer flush and close