Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
 
"""
Draw a pipeline
===============
 
There is no other way to look into one model stored
in ONNX format than looking into its node with
*onnx*. This example demonstrates
how to draw a model and to retrieve it in *json*
format.
 
Retrieve a model in JSON format
+++++++++++++++++++++++++++++++
 
That's the most simple way.
"""
 
from onnxruntime.datasets import get_example
 
example1 = get_example("mul_1.onnx")
 
import onnx  # noqa: E402
 
model = onnx.load(example1)  # model is a ModelProto protobuf message
 
print(model)
 
 
#################################
# Draw a model with ONNX
# ++++++++++++++++++++++
# We use `net_drawer.py <https://github.com/onnx/onnx/blob/main/onnx/tools/net_drawer.py>`_
# included in *onnx* package.
# We use *onnx* to load the model
# in a different way than before.
 
 
from onnx import ModelProto  # noqa: E402
 
model = ModelProto()
with open(example1, "rb") as fid:
    content = fid.read()
    model.ParseFromString(content)
 
###################################
# We convert it into a graph.
from onnx.tools.net_drawer import GetOpNodeProducer, GetPydotGraph  # noqa: E402
 
pydot_graph = GetPydotGraph(
    model.graph, name=model.graph.name, rankdir="LR", node_producer=GetOpNodeProducer("docstring")
)
pydot_graph.write_dot("graph.dot")
 
#######################################
# Then into an image
import os  # noqa: E402
 
os.system("dot -O -Tpng graph.dot")
 
################################
# Which we display...
import matplotlib.pyplot as plt  # noqa: E402
 
image = plt.imread("graph.dot.png")
plt.imshow(image)