mindspore.dataset.DSCallback

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

Abstract base class used to build dataset callback classes.

Users can obtain the dataset pipeline context through ds_run_context, including cur_epoch_num, cur_step_num_in_epoch and cur_step_num.

Parameters

step_size (int, optional) – The number of steps between adjacent ds_step_begin/ds_step_end calls. Default: 1, will be called at each step.

Examples

>>> from mindspore.dataset import DSCallback
>>> from mindspore.dataset.transforms import 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 = 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 data 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 data pipeline.

ds_epoch_end(ds_run_context)[source]

Called after an epoch is finished.

Parameters

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

ds_step_begin(ds_run_context)[source]

Called before a step start.

Parameters

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

ds_step_end(ds_run_context)[source]

Called after a step finished.

Parameters

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