mindspore.nn.GraphCell
- class mindspore.nn.GraphCell(graph, params_init=None, obf_random_seed=None)[source]
Base class for running the graph loaded from a MindIR.
This feature is still under development. Currently GraphCell do not support modifying the structure of the diagram, and can only use data that shape and type are the same as the input when exporting the MindIR.
- Parameters
graph (FuncGraph) – A compiled graph loaded from MindIR.
params_init (dict) – Parameters need to be inited in the graph. The key is the parameter name whose type is str, and the value is a Tensor or Parameter. If the parameter exists in the graph according to the name, update it’s value. If the parameter does not exist, ignore it. Default:
None
.obf_random_seed (Union[int, None]) – The random seed used for dynamic obfuscation. “dynamic obfuscation” is used for model protection, which can refer to
mindspore.obfuscate_model()
. If the input graph is a func_graph loaded from a mindir file obfuscated with obf_random_seed , then obf_random_seed should be provided. obf_random_seed should be in (0, 9223372036854775807]. default:None
.
- Raises
- Supported Platforms:
Ascend
GPU
CPU
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(np.ones([1, 1, 3, 3]).astype(np.float32)) >>> ms.export(net, input, file_name="net", file_format="MINDIR") >>> graph = ms.load("net.mindir") >>> net = nn.GraphCell(graph) >>> output = net(input) >>> print(output) [[[[4. 6. 4.] [6. 9. 6.] [4. 6. 4.]]]]