mindspore.dataset.WaitedDSCallback

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

Abstract base class used to build a dataset callback class that is synchronized with the training callback.

This class can be used to execute a user defined logic right after the previous step or epoch. For example, one augmentation needs the loss from the previous trained epoch to update some of its parameters.

Parameters

step_size (int, optional) – The number of rows in each step. Usually the step size will be equal to the batch size (Default=1).

Examples

>>> from mindspore.dataset import WaitedDSCallback
>>>
>>> my_cb = WaitedDSCallback(32)
>>> # dataset is an instance of Dataset object
>>> dataset = dataset.map(operations=AugOp(), callbacks=my_cb)
>>> dataset = dataset.batch(32)
>>> # define the model
>>> model.train(epochs, data, callbacks=[my_cb])
begin(run_context)

Called once before the network executing.

Parameters

run_context (RunContext) – Include some information of the model.

create_runtime_obj()[source]

Creates a runtime (C++) object from the callback methods defined by the user. This method is internal.

Returns

_c_dataengine.PyDSCallback.

ds_begin(ds_run_context)

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]

Internal method, do not call/override. Defines ds_epoch_begin of DSCallback to wait for MS epoch_end callback.

Parameters

ds_run_context – Include some information of the pipeline.

ds_epoch_end(ds_run_context)

Called after an epoch is finished.

Parameters

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

ds_step_begin(ds_run_context)[source]

Internal method, do not call/override. Defines ds_step_begin of DSCallback to wait for MS step_end callback.

Parameters

ds_run_context – Include some information of the pipeline.

ds_step_end(ds_run_context)

Called after each step finished.

Parameters

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

end(run_context)[source]

Internal method, release the wait if training is ended.

Parameters

run_context – Include some information of the model.

epoch_begin(run_context)

Called before each epoch beginning.

Parameters

run_context (RunContext) – Include some information of the model.

epoch_end(run_context)[source]

Internal method, do not call/override. Defines epoch_end of Callback to release the wait in ds_epoch_begin.

Parameters

run_context – Include some information of the model.

step_begin(run_context)

Called before each step beginning.

Parameters

run_context (RunContext) – Include some information of the model.

step_end(run_context)[source]

Internal method, do not call/override. Defines step_end of Callback to release the wait in ds_step_begin.

Parameters

run_context – Include some information of the model.

sync_epoch_begin(train_run_context, ds_run_context)[source]

Called before a new dataset epoch is started and after the previous training epoch is ended.

Parameters
  • train_run_context – Include some information of the model with feedback from the previous epoch.

  • ds_run_context – Include some information of the dataset pipeline.

sync_step_begin(train_run_context, ds_run_context)[source]

Called before a new dataset step is started and after the previous training step is ended.

Parameters
  • train_run_context – Include some information of the model with feedback from the previous step.

  • ds_run_context – Include some information of the dataset pipeline.