-
Notifications
You must be signed in to change notification settings - Fork 3
/
_draw_network_1cam.py
179 lines (155 loc) · 10.2 KB
/
_draw_network_1cam.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import sys
import os
from plot_nn.pycore.blocks import *
from plot_nn.pycore.tikzeng import *
import subprocess
shift = 2
# defined your arch
arch = [
to_head('..'),
to_cor(),
to_begin(),
# 8 Convolutions of Centre Camera Stream & Input image
to_input(name="input img 1", pathfile='./imgs/CentralRGB_00142.png', width=300, height=10, scale=3, offset="-5", to="(0,0,-30)", caption="Centre Camera Image 200X88"),
to_Conv(name="conv 1", width_label="32", height_label="42", depth_label="98", offset="(0,0,-30)", to="(0,0,0)",
width=2, height=42, depth=98, caption=r"""5$\times$5,2"""),
to_Conv(name="conv 2", width_label="32", height_label="40", depth_label="96", offset="(3,0,-30)", to="(0,0,0)",
width=2, height=40, depth=96, caption=r"""3$\times$3,1"""),
to_Conv(name="conv 3", width_label="64", height_label="19", depth_label="47", offset="(7,0,-30)", to="(0,0,0)",
width=4, height=19, depth=47, caption=r"""3$\times$3,2"""),
to_Conv(name="conv 4", width_label="64", height_label="17", depth_label="45", offset="(10,0,-30)", to="(0,0,0)",
width=4, height=17, depth=45, caption=r"""3$\times$3,1"""),
to_Conv(name="conv 5", width_label="128", height_label="8", depth_label="22", offset="(14,0,-30)", to="(0,0,0)",
width=8, height=8, depth=22, caption=r"""3$\times$3,2"""),
to_Conv(name="conv 6", width_label="128", height_label="6", depth_label="20", offset="(17,0,-30)", to="(0,0,0)",
width=8, height=6, depth=20, caption=r"""3$\times$3,1"""),
to_Conv(name="conv 7", width_label="256", height_label="4", depth_label="18", offset="(20,0,-30)", to="(0,0,0)",
width=16, height=4, depth=18, caption=r"""3$\times$3,1"""),
to_Conv(name="conv 8", width_label="256", height_label="2", depth_label="16", offset="(25,0,-30)", to="(0,0,0)",
width=16, height=2, depth=16, caption=r"""3$\times$3,1"""),
# 8 Convolutions of PGM Stream & Input image
to_input(name="input img 2", pathfile='./imgs/Lidar32_00142.png', width=300, height=5, scale=10, offset="-5", to="(0,0,0)", caption="LiDAR PGV 90X32"),
to_Conv(name="conv 9", width_label="32", height_label="14", depth_label="43", offset="(0,0,0)", to="(0,0,0)",
width=2, height=14, depth=43, caption=r"""5$\times$5,2"""),
to_Conv(name="conv 10", width_label="32", height_label="12", depth_label="41", offset="(5,0,0)", to="(0,0,0)",
width=2, height=12, depth=41, caption=r"""3$\times$3,1"""),
to_Conv(name="conv 11", width_label="64", height_label="5", depth_label="20", offset="(10,0,0)", to="(0,0,0)",
width=4, height=5, depth=20, caption=r"""3$\times$3,2"""),
to_Conv(name="conv 12", width_label="64", height_label="3", depth_label="18", offset="(15,0,0)", to="(0,0,0)",
width=4, height=3, depth=18, caption=r"""3$\times$3,1"""),
# Images connections to conv layers
r"""\draw [connection] (input img 1.center) -- node {\midarrow} (conv 1-west);""",
r"""\draw [connection] (conv 1-east) -- node {\midarrow} (conv 2-west);""",
r"""\draw [connection] (conv 2-east) -- node {\midarrow} (conv 3-west);""",
r"""\draw [connection] (conv 3-east) -- node {\midarrow} (conv 4-west);""",
r"""\draw [connection] (conv 4-east) -- node {\midarrow} (conv 5-west);""",
r"""\draw [connection] (conv 5-east) -- node {\midarrow} (conv 6-west);""",
r"""\draw [connection] (conv 6-east) -- node {\midarrow} (conv 7-west);""",
r"""\draw [connection] (conv 7-east) -- node {\midarrow} (conv 8-west);""",
r"""\draw [connection] (input img 2.center) -- node {\midarrow} (conv 9-west);""",
r"""\draw [connection] (conv 9-east) -- node {\midarrow} (conv 10-west);""",
r"""\draw [connection] (conv 10-east) -- node {\midarrow} (conv 11-west);""",
r"""\draw [connection] (conv 11-east) -- node {\midarrow} (conv 12-west);""",
# First Concatenation node and connections to it
r"""\node[shade, shading=ball, circle, ball color={rgb:magenta,5;black,7}, minimum size=1cm] (Concat 1) at (""" + str(23+2*1.6+shift) + """, 0, 0) {};""",
r"""\node[color=white] at (""" + str(23+2*1.6+shift) + r""",0,0){\huge \bf +};""",
r"""\draw [connection] (conv 12-east) -- node {\midarrow} (Concat 1);""",
r"""\draw [connection] (conv 8-east) -- node {\midarrow} ([xshift="""+str(shift)+"""cm]conv 8-east);""",
r"""\draw [connection] ([xshift="""+str(shift)+"""cm]conv 8-east) -- node {\midarrow} (Concat 1);""",
# Fully connected layers
to_FC(name="FC 1", width_label="512", offset="(35,0,0)", to="(0,0,0)",
width=3, height=50, depth=3, caption="FC 1"),
to_FC(name="FC 2", width_label="512", offset="(37,0,0)", to="(0,0,0)",
width=3, height=50, depth=3, caption="FC 2"),
r"""\draw [connection] (Concat 1) -- node {\midarrow} (FC 1-west);""",
to_connection("FC 1", "FC 2"),
# Measurement input (speed)
r"""\node[draw, canvas is yz plane at x=-5, rotate=-90, anchor=center] (measurements word) at (0,0,25) {\scalebox{2}{\fontsize{70}{70}\sffamily\bfseries Measurements}};""",
to_FC(name="FC 3", width_label="128", offset="(20,0,25)", to="(0,0,0)",
width=3, height=20, depth=3, caption="FC 3"),
to_FC(name="FC 4", width_label="128", offset="(25,0,25)", to="(0,0,0)",
width=3, height=20, depth=3, caption="FC 4"),
to_connection("FC 3", "FC 4"),
r"""\draw [connection] (measurements word.center) -- node {\midarrow} (FC 3-west);""",
# Fully connected layer before control
to_FC(name="FC 5", width_label="512", offset="(41.5,0,0)", to="(0,-5,0)",
width=3, height=50, depth=3, caption="FC 5"),
# Second Concatenation node
r"""\node[shade, shading=ball, circle, ball color={rgb:magenta,5;black,7}, minimum size=1cm] (Concat 2) at (40, -5, 0) {};""",
r"""\node[color=white] at (40,-5,0){\huge \bf +};""",
r"""\draw [connection] (Concat 2) -- node {\midarrow} (FC 5-west);""",
r"""\draw [connection] (FC 2-east) -- node {\midarrow} (Concat 2);""",
r"""\draw [connection] (FC 4-east) -- node {\midarrow} ([xshift="""+str(shift+20)+"""cm]FC 4-east);""",
r"""\draw [connection] ([xshift="""+str(shift+20)+"""cm]FC 4-east) -- node {\midarrow} (Concat 2);""",
# Control node
r"""\node[shade, shading=ball, circle, ball color={rgb:blue,2;green,1;black,0.3}, minimum size=3cm] (Control node) at (45, -5, 0) {};""",
r"""\node[color=white] at (45,-5,0){\Huge \bf C};""",
r"""\draw [connection] (FC 5-east) -- node {\midarrow} (Control node);""",
# Speed Branch
to_FC(name="FC 18", width_label="256", offset="(49,0,0)", to="(0,17,0)",
width=3, height=25, depth=3, caption="FC 18"),
to_FC(name="FC 19", width_label="256", offset="(52,0,0)", to="(0,17,0)",
width=3, height=25, depth=3, caption="FC 19"),
to_FC(name="FC 20", width_label="1", offset="(55,0,0)", to="(0,17,0)",
width=3, height=2, depth=3, caption="FC 20"),
to_connection("FC 2", "FC 18"),
to_connection("FC 18", "FC 19"),
to_connection("FC 19", "FC 20"),
r"""\node[shift={(56,0,0)}, anchor=west] at (0,17,0){\huge \bf Speed};""",
# Branch 1
to_FC(name="FC 6", width_label="256", offset="(49,0,0)", to="(0,7,0)",
width=3, height=25, depth=3, caption="FC 6"),
to_FC(name="FC 7", width_label="256", offset="(52,0,0)", to="(0,7,0)",
width=3, height=25, depth=3, caption="FC 7"),
to_FC(name="FC 8", width_label="3", offset="(55,0,0)", to="(0,7,0)",
width=3, height=5, depth=3, caption="FC 8"),
r"""\draw [connection] (Control node) -- node {\midarrow} (FC 6-west);""",
to_connection("FC 6", "FC 7"),
to_connection("FC 7", "FC 8"),
r"""\node[shift={(56,0,0)}, anchor=west] at (0,7,0){\huge \bf Follow-lane Commands};""",
# Branch 2
to_FC(name="FC 9", width_label="256", offset="(49,0,0)", to="(0,0,0)",
width=3, height=25, depth=3, caption="FC 9"),
to_FC(name="FC 10", width_label="256", offset="(52,0,0)", to="(0,0,0)",
width=3, height=25, depth=3, caption="FC 10"),
to_FC(name="FC 11", width_label="3", offset="(55,0,0)", to="(0,0,0)",
width=3, height=5, depth=3, caption="FC 11"),
r"""\draw [connection] (Control node) -- node {\midarrow} (FC 9-west);""",
to_connection("FC 9", "FC 10"),
to_connection("FC 10", "FC 11"),
r"""\node[shift={(56,0,0)}, anchor=west] at (0,0,0){\huge \bf Go Right Commands};""",
# Branch 3
to_FC(name="FC 12", width_label="256", offset="(49,0,0)", to="(0,-7,0)",
width=3, height=25, depth=3, caption="FC 12"),
to_FC(name="FC 13", width_label="256", offset="(52,0,0)", to="(0,-7,0)",
width=3, height=25, depth=3, caption="FC 13"),
to_FC(name="FC 14", width_label="3", offset="(55,0,0)", to="(0,-7,0)",
width=3, height=5, depth=3, caption="FC 14"),
r"""\draw [connection] (Control node) -- node {\midarrow} (FC 12-west);""",
to_connection("FC 12", "FC 13"),
to_connection("FC 13", "FC 14"),
r"""\node[shift={(56,0,0)}, anchor=west] at (0,-7,0){\huge \bf Go Left Commands};""",
# Branch 4
to_FC(name="FC 15", width_label="256", offset="(49,0,0)", to="(0,-14,0)",
width=3, height=25, depth=3, caption="FC 15"),
to_FC(name="FC 16", width_label="256", offset="(52,0,0)", to="(0,-14,0)",
width=3, height=25, depth=3, caption="FC 16"),
to_FC(name="FC 17", width_label="3", offset="(55,0,0)", to="(0,-14,0)",
width=3, height=5, depth=3, caption="FC 17"),
r"""\draw [connection] (Control node) -- node {\midarrow} (FC 15-west);""", # dashed or connection
to_connection("FC 15", "FC 16"),
to_connection("FC 16", "FC 17"),
r"""\node[shift={(56,0,0)}, anchor=west] at (0,-14,0){\huge \bf Go Straight Commands};""",
# end
to_end()
]
if __name__ == '__main__':
to_generate(arch, 'temp.tex')
with open("temp.tex", "rt") as fin:
with open("network.tex", "wt") as fout:
for line in fin:
fout.write(line.replace('../layers/', './plot_nn/layers/'))
bashCommand = "pdflatex -output-directory " + os.getcwd() + " -interaction batchmode " + os.getcwd() + "/network.tex"
FNULL = open(os.devnull, 'w')
process = subprocess.Popen(bashCommand, shell=True, stdout=FNULL, stderr=subprocess.STDOUT)
# p.kill() #TODO process should be closed?