Model Export

View Source On Gitee

MindSpore provides a unified intermediate representation (IR) for training and inference. You can use the export API to directly save a model as MindIR. (Currently, only graph mode is supported.)

import mindspore as ms
import numpy as np
from mindspore import Tensor

# Define the network structure of LeNet5. Refer to
# https://gitee.com/mindspore/docs/blob/r2.4.0/docs/mindspore/code/lenet.py
net = LeNet5()
input_tensor = Tensor(np.ones([1, 1, 32, 32]).astype(np.float32))
ms.export(net, input_tensor, file_name='lenet', file_format='MINDIR')

For details about the API, see mindspore.export.

The model export result is provided for MindSpore Lite. For details about how to use the result, see Lite Inference Overview.