mindspore.TimeMonitor

class mindspore.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

>>> import mindspore as ms
>>> from mindspore import nn
>>>
>>> net = LeNet5()
>>> loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True, reduction='mean')
>>> optim = nn.Momentum(net.trainable_params(), 0.01, 0.9)
>>> model = ms.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.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.RunContext.