forked from mindspore-Ecosystem/mindspore
!9317 fix the docstring of SummaryCollector and SummaryRecord
From: @ouwenchang Reviewed-by: @lilongfei15,@jonyguo Signed-off-by: @jonyguo
This commit is contained in:
commit
7c38b072d4
|
@ -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 = {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue