mindspore.dataset.DSCallback

class mindspore.dataset.DSCallback(step_size=1)[source]

Abstract base class used to build a dataset callback class.

Parameters

step_size (int, optional) – The number of steps between the step_begin and step_end are called (Default=1).

Examples

>>> from mindspore.dataset import DSCallback
>>> from mindspore.dataset.transforms import c_transforms
>>>
>>> class PrintInfo(DSCallback):
...     def ds_epoch_end(self, ds_run_context):
...         print(ds_run_context.cur_epoch_num)
...         print(ds_run_context.cur_step_num)
>>>
>>> dataset = ds.MnistDataset(mnist_dataset_dir, num_samples=100)
>>> op = c_transforms.OneHot(10)
>>> dataset = dataset.map(operations=op, callbacks=PrintInfo())
ds_begin(ds_run_context)[source]

Called before the data pipeline is started.

Parameters

ds_run_context (RunContext) – Include some information of the pipeline.

ds_epoch_begin(ds_run_context)[source]

Called before a new epoch is started.

Parameters

ds_run_context (RunContext) – Include some information of the pipeline.

ds_epoch_end(ds_run_context)[source]

Called after an epoch is finished.

Parameters

ds_run_context (RunContext) – Include some information of the pipeline.

ds_step_begin(ds_run_context)[source]

Called before each step start.

Parameters

ds_run_context (RunContext) – Include some information of the pipeline.

ds_step_end(ds_run_context)[source]

Called after each step finished.

Parameters

ds_run_context (RunContext) – Include some information of the pipeline.