-
Notifications
You must be signed in to change notification settings - Fork 0
/
CNN_draw.tex
146 lines (106 loc) · 4.26 KB
/
CNN_draw.tex
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
\documentclass{article}
\usepackage{tikz}
\usepackage{verbatim}
\documentclass{article2}
\begin{comment}
:Title: Neural network
:Tags: Foreach
The ``\foreach`` command is very useful for quickly creating structured graphics
like this neural network diagram.
\end{comment}
\begin{document}
\pagestyle{empty}
\def\layersep{2.5cm}
%\begin{tikzpicture}[shorten >=1pt,->,draw=black!50, node distance=\layersep]
% \tikzstyle{every pin edge}=[<-,shorten <=1pt]
% \tikzstyle{neuron}=[circle,fill=black!25,minimum size=17pt,inner sep=0pt]
% \tikzstyle{input neuron}=[neuron, fill=green!50];
% \tikzstyle{output neuron}=[neuron, fill=red!50];
% \tikzstyle{hidden neuron}=[neuron, fill=orange!50];
% \tikzstyle{annot} = [text width=4em, text centered]
%
% % Draw the input layer nodes
% \foreach \name / \y in {1,...,4}
% % This is the same as writing \foreach \name / \y in {1/1,2/2,3/3,4/4}
% \node[input neuron, pin=left:Input \-\y] (I-\name) at (0,-\y) {};
%
% % Draw the hidden layer nodes
% \foreach \name / \y in {1,...,5}
% \path[yshift=0.5cm]
% node[hidden neuron] (H-\name) at (\layersep,-\y cm) {};
%
% % Draw the output layer node
% \node[output neuron,pin={[pin edge={->}]right:Output}, right of=H-3] (O) {};
%
% % Connect every node in the input layer with every node in the
% % hidden layer.
% \foreach \source in {1,...,4}
% \foreach \dest in {1,...,5}
% \path (I-\source) edge (H-\dest);
%
% % Connect every node in the hidden layer with the output layer
% \foreach \source in {1,...,5}
% \path (H-\source) edge (O);
%
% % Annotate the layers
% \node[annot,above of=H-1, node distance=1cm] (hl) {Hidden layer};
% \node[annot,left of=hl] {Input layer};
% \node[annot,right of=hl] {Output layer};
%\end{tikzpicture}
% End of code
\begin{comment}
:Title: Convolutional Neural network
:Tags: Foreach
The ``\foreach`` command is very useful for quickly creating structured graphics
like this neural network diagram.
\end{comment}
\begin{document}
\pagestyle{empty}
\def\layersep{2.5cm}
\begin{tikzpicture}[shorten >=1pt,->,draw=black!50, node distance=\layersep]
\tikzstyle{every pin edge}=[<-,shorten <=1pt]
\tikzstyle{neuron}=[circle,fill=black!25,minimum size=17pt,inner sep=0pt]
\tikzstyle{input neuron}=[neuron, fill=green!50];
\tikzstyle{output neuron}=[neuron, fill=red!50];
\tikzstyle{hidden neuron}=[neuron, fill=blue!50];
\tikzstyle{hidden neuron2}=[neuron, fill=black!50];
\tikzstyle{hidden neuron3}=[neuron, fill=orange!50];
\tikzstyle{annot} = [text width=4em, text centered]
% Draw the input layer nodes
\foreach \name / \y in {1,...,4}
% This is the same as writing \foreach \name / \y in {1/1,2/2,3/3,4/4}
\node[input neuron, pin=left:Input \-\y] (I-\name) at (0,-\y) {};
% Draw the hidden layer nodes
\foreach \name / \y in {1,...,5}
\path[yshift=0.5cm]
node[hidden neuron] (H-\name) at (\layersep,-\y cm) {};
\foreach \name / \y in {1,...,5}
\path[yshift=0.5cm]
node[hidden neuron2] (J-\name) at (5,-\y) {};
\foreach \name / \y in {1,...,5}
\path[yshift=0.5cm]
node[hidden neuron3] (K-\name) at (7.5,-\y) {};
% Draw the output layer node
\node[output neuron,pin={[pin edge={->}]right:Output}, right of=K-3] (O) {};
% Connect every node in the input layer with every node in the
% hidden layer.
\foreach \source in {1,...,4}
\foreach \dest in {1,...,5}
\path (I-\source) edge (H-\dest);
\foreach \source in {1,...,5}
\foreach \dest in {1,...,5}
\path (H-\source) edge (J-\dest);
\foreach \source in {1,...,5}
\foreach \dest in {1,...,5}
\path (J-\source) edge (K-\dest);
% Connect every node in the hidden layer with the output layer
\foreach \source in {1,...,5}
\path (K-\source) edge (O);
% Annotate the layers
\node[annot,above of=H-1, node distance=1cm] (hl) {Convolutional layer};
\node[annot,left of=hl] {Input layer};Convolutional
\node[annot,right of=hl] {Pooling layer};
\node[annot,above of=K-1, node distance=1cm] (kl) { Fully connected layer};
\node[annot,right of=kl] {Output layer};
\end{tikzpicture}
\end{document}