mindspore.train.TimeMonitor

class mindspore.train.TimeMonitor(data_size=None)[source]

Monitor the time in train or eval process.

Parameters

data_size (int) – How many steps are the intervals between print information each time. if the program get batch_num during training, data_size will be set to batch_num, otherwise data_size will be used. Default: None.

Raises

ValueError – If data_size is not positive int.

Examples

Note

Before running the following example, you need to customize the network LeNet5 and dataset preparation function create_dataset. Refer to Building a Network and Dataset .

>>> from mindspore import nn
>>> from mindspore.train import Model, TimeMonitor
>>>
>>> net = LeNet5()
>>> loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True, reduction='mean')
>>> optim = nn.Momentum(net.trainable_params(), 0.01, 0.9)
>>> model = Model(net, loss_fn=loss, optimizer=optim)
>>> data_path = './MNIST_Data'
>>> dataset = create_dataset(data_path)
>>> time_monitor = TimeMonitor()
>>> model.train(10, dataset, callbacks=time_monitor)
epoch_begin(run_context)[source]

Record time at the beginning of epoch.

Parameters

run_context (RunContext) – Context of the process running. For more details, please refer to mindspore.train.RunContext.

epoch_end(run_context)[source]

Print process cost time at the end of epoch.

Parameters

run_context (RunContext) – Context of the process running. For more details, please refer to mindspore.train.RunContext.