先构建一个普通的网络:
import mindspore
from mindspore import nn, ops
class Network(nn.Cell):
def __init__(self):
super().__init__()
self.flatten = nn.Flatten()
self.dense_relu_sequential = nn.SequentialCell(
nn.Dense(28*28, 512),
nn.ReLU(),
nn.Dense(512, 512),
nn.ReLU(),
nn.Dense(512, 10)
)
def construct(self, x):
x = self.flatten(x)
logits = self.dense_relu_sequential(x)
return logits
model = Network()
print(model)
打印结果为:
Network<
(flatten): Flatten<>
(dense_relu_sequential): SequentialCell<
(0): Dense<input_channels=784, output_channels=512, has_bias=True>
(1): ReLU<>
(2): Dense<input_channels=512, output_channels=512, has_bias=True>
(3): ReLU<>
(4): Dense<input_channels=512, output_channels=10, has_bias=True>
>
>
加载网络后
添加代码:
ms.context.set_context(save_graphs=True,save_graphs_path="./saved_graphs/",save_graph_dot=True)
ms.export(net,input_tensor,file_name="obf_net",file_format="MINDIR")
把这个名字特殊的dot文件导出为pdf
!dot -Tpdf saved_graphs/ModelDigraph_0062.dot -o my_net.pdf
这样就可以看到可视化后的网络结构了。