mindspore.load

mindspore.load(file_name, **kwargs)[source]

Load MindIR.

The returned object can be executed by a GraphCell, see class mindspore.nn.GraphCell for more details.

Parameters
  • file_name (str) – MindIR file name.

  • kwargs (dict) –

    Configuration options dictionary.

    • dec_key (bytes): Byte-type key used for decryption. The valid length is 16, 24, or 32.

    • dec_mode (Union[str, function]): Specifies the decryption mode, to take effect when dec_key is set.

      • Option: 'AES-GCM', 'AES-CBC', 'SM4-CBC' or customized decryption. Default: 'AES-GCM'.

      • For details of using the customized decryption, please check the tutorial.

    • obf_func (function): A python function used for loading obfuscated MindIR model, which can refer to obfuscate_model().

Returns

GraphCell, a compiled graph that can executed by GraphCell.

Raises
  • ValueError – MindIR file does not exist or file_name is not a string.

  • RuntimeError – Failed to parse MindIR file.

Examples

>>> import numpy as np
>>> import mindspore as ms
>>> import mindspore.nn as nn
>>> from mindspore import Tensor
>>> from mindspore import context
>>> context.set_context(mode=context.GRAPH_MODE)
>>>
>>> net = nn.Conv2d(1, 1, kernel_size=3, weight_init="ones")
>>> input_tensor = Tensor(np.ones([1, 1, 3, 3]).astype(np.float32))
>>> ms.export(net, input_tensor, file_name="net", file_format="MINDIR")
>>> graph = ms.load("net.mindir")
>>> net = nn.GraphCell(graph)
>>> output = net(input_tensor)
>>> print(output)
[[[[4. 6. 4.]
   [6. 9. 6.]
   [4. 6. 4.]]]]
Tutorial Examples: