mindspore.export
- mindspore.export(net, *inputs, file_name, file_format='AIR', **kwargs)[source]
Export the MindSpore network into an offline model in the specified format.
Note
When exporting AIR, ONNX format, the size of a single tensor can not exceed 2GB.
When file_name does not have a suffix, the system will automatically add one according to the file_format.
- Parameters
net (Cell) – MindSpore network.
inputs (Union[Tensor, Dataset, List, Tuple, Number, Bool]) – It represents the inputs of the net, if the network has multiple inputs, set them together. While its type is Dataset, it represents the preprocess behavior of the net, data preprocess operations will be serialized. In second situation, you should adjust batch size of dataset script manually which will impact on the batch size of ‘net’ input. Only supports parse “image” column from dataset currently.
file_name (str) – File name of the model to be exported.
file_format (str) –
MindSpore currently supports ‘AIR’, ‘ONNX’ and ‘MINDIR’ format for exported model. Default: ‘AIR’.
AIR: Ascend Intermediate Representation. An intermediate representation format of Ascend model.
ONNX: Open Neural Network eXchange. An open format built to represent machine learning models.
MINDIR: MindSpore Native Intermediate Representation for Anf. An intermediate representation format for MindSpore models.
kwargs (dict) –
Configuration options dictionary.
quant_mode (str): If the network is a quantization aware training network, the quant_mode should be set to “QUANT”, else the quant_mode should be set to “NONQUANT”.
mean (float): The mean of input data after preprocessing, used for quantizing the first layer of network. Default: 127.5.
std_dev (float): The variance of input data after preprocessing, used for quantizing the first layer of the network. Default: 127.5.
enc_key (byte): Byte type key used for encryption. The valid length is 16, 24, or 32.
enc_mode (Union[str, function]): Specifies the encryption mode, to take effect when enc_key is set. For ‘AIR’ and ‘ONNX’ models, only Customized encryption is supported. For ‘MINDIR’, all options are supported. Option: ‘AES-GCM’, ‘AES-CBC’ or Customized encryption by user. Default: ‘AES-GCM’.
Examples
>>> import mindspore as ms >>> import numpy as np >>> from mindspore import Tensor >>> >>> net = LeNet() >>> input_tensor = Tensor(np.ones([1, 1, 32, 32]).astype(np.float32)) >>> ms.export(net, input_tensor, file_name='lenet', file_format='MINDIR')