mindspore.train.ConvertNetUtils
- class mindspore.train.ConvertNetUtils[source]
Convert net to thor layer net, used to compute and store second-order information matrix.
Examples
>>> import mindspore as ms >>> convert_net_utils = ms.train.ConvertNetUtils()
- convert_to_thor_net(net)[source]
This interface is used to convert a network to thor layer network, in order to calculate and store the second-order information matrix.
Note
This interface is automatically called by the second-order optimizer thor.
- Parameters
net (Cell) – Network to be trained by the second-order optimizer thor.
- Supported Platforms:
Ascend
GPU
Examples
>>> import mindspore as ms >>> from mindspore import nn >>> from mindspore import Tensor >>> from mindspore.nn import thor >>> >>> # Define the network structure of LeNet5. Refer to >>> # https://gitee.com/mindspore/docs/blob/master/docs/mindspore/code/lenet.py >>> net = LeNet5() >>> temp = Tensor([4e-4, 1e-4, 1e-5, 1e-5], ms.float32) >>> opt = thor(net, learning_rate=temp, damping=temp, momentum=0.9, loss_scale=128, frequency=4) >>> loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True, reduction='mean') >>> loss_scale = ms.FixedLossScaleManager(128, drop_overflow_update=False) >>> model = ms.Model(net, loss_fn=loss, optimizer=opt, loss_scale_manager=loss_scale, metrics={'acc'}, ... amp_level="O2", keep_batchnorm_fp32=False) >>> model = ms.train.ConvertModelUtils.convert_to_thor_model(model=model, network=net, loss_fn=loss, ... optimizer=opt,loss_scale_manager=loss_scale, metrics={'acc'}, ... amp_level="O2", keep_batchnorm_fp32=False)