mindspore.nn.GraphCell
- class mindspore.nn.GraphCell(graph, params_init=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.
- Raises
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> import mindspore as ms >>> import mindspore.nn as nn >>> from mindspore import Tensor >>> >>> 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.]]]]