mindspore.nn.GraphCell

class mindspore.nn.GraphCell(graph)[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 (object) – A compiled graph loaded from MindIR.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> import mindspore.nn as nn
>>> from mindspore import Tensor, export, load
>>>
>>> net = nn.Conv2d(1, 1, kernel_size=3, weight_init="ones")
>>> input = Tensor(np.ones([1, 1, 3, 3]).astype(np.float32))
>>> export(net, input, file_name="net", file_format="MINDIR")
>>> graph = load("net.mindir")
>>> net = nn.GraphCell(graph)
>>> output = net(input)
>>> print(output)
[[[[4. 6. 4.]
   [6. 9. 6.]
   [4. 6. 4.]]]]