Draw Neural Network Architecture Diagram Online
Article directory
- Foreword
- Dot drawing neural network diagram
- Simple neural network
- Big neural network (pseudo)
- Python cartoon neural network diagram
- Big neural network
Foreword
I accept been doing neural networks for so long, and I occasionally want to describe an architectural diagram of my own model, but I take no mode to start, because the network is generally more complicated. If I manually use the paintings painted past Visio, information technology is more troublesome, and I am lazy, I searched online. Wait at Graphviz
The drawing tool, when you lot learned it, began to use it to draw the model structure.
For an introduction to Graphviz, check out my first ii blog posts:
- Graphviz drawing tutorial
- Graphviz Drawing Tutorial (Python)
Dot drawing neural network diagram
Elementary neural network
digraph G { rankdir=LR; splines=line; nodesep= .1 ; node [label= "" ] ; subgraph cluster_0 { color=white; node [style=solid,color=light-green,shape=circle] ; i; label = "Input Layer" ; } subgraph cluster_1 { color=white; node [style=solid,color=blue, shape=circle] ; h11, h12, h13, h14; characterization = "Subconscious Layer 1" ; } subgraph cluster_2 { colour=white; node [style=solid,colour=bluish, shape=circle] ; h21, h22; characterization = "Hidden Layer 2" ; } subgraph cluster_3 { color=white; node [style=solid,color=red, shape=circle] ; o; characterization= "Output Layer" ; } i -> h11 i -> h12 i -> h13 i -> h14 h11 -> h21 h11 -> h22 h12 -> h21 h12 -> h22 h13 -> h21 h13 -> h22 h14 -> h21 h14 -> h22 h21 -> o h22 -> o }
Here nosotros define a mapG
, and iv subgraphscluster_0
、cluster_1
、cluster_2
、cluster_ iii
And define a node grade for each submapnode
And their corresponding properties, considering the neural network is fully continued, we need to connect each node (very cumbersome).
salvage it equallydemo.dot
File, by command:
dot -Tpng demo.dot -o demo.png
converts it to a png image equally follows:
Ok, so I drew a simple neural network model diagram, merely what if you see more than nodes?
You might say, I am not stupid, are you writing them on the dot script one by one? I can supersede it with an ellipsis! Ok, then try the ellipses instead of the "pseudo-large neural network" look.
Big neural network (pseudo)
digraph Thousand { rankdir=LR; splines=line; nodesep= .ane ; node [label= "" ] ; compound=true subgraph cluster_0 { color=white; node [style=solid,color=green,shape=circumvolve] ; i; label = "Input Layer" ; } subgraph cluster_1 { colour=white; node [mode=solid,color=blue, shape=circumvolve] ; h11, h12, h13, h14; label = "Hidden Layer one (iv nodes)" ; } subgraph cluster_2 { color=white; { node [style=solid,color=blue,shape=circumvolve] ; h21;h22; } node [style=solid,shape=point] ; p1; p2; p3; { node [way=solid,colour=bluish,shape=circle] ; h23;h24; } label = "Hidden Layer 2 (100 nodes)" ; } subgraph cluster_3 { color=white; node [style=solid,color=red, shape=circle] ; o; characterization= "Output Layer" ; } i -> h11 i -> h12 i -> h13 i -> h14 h11 -> h21 h11 -> h22 h12 -> h21 h12 -> h22 h13 -> h21 h13 -> h22 h14 -> h21 h14 -> h22 h11 -> h23 h11 -> h24 h12 -> h23 h12 -> h24 h13 -> h23 h13 -> h24 h14 -> h23 h14 -> h24 h21 -> o h22 -> o h23 -> o h24 -> o }
Here I added a few shapes tobetoken
The node makes the entire network await similar an abbreviated version of a large network. Note that the club of drawing is fatigued in the order defined past the nodes, so iii small black dots are defined in the middle.
Python drawing neural network diagram
Large neural network
Although you can "fake opportunistically" to depict a pseudo-large neural network construction diagram according to the above method, when you want to actually describe a large neural network and observe its connexion details? This time y'all take to take advantage of the power of Python.
The lawmaking is as follows, and the relevant explanation has been written in the lawmaking comment:
from graphviz import Digraph def Neural_Network_Graph (input_layer, hidden_layers, output_layer, filename= "demo" ) : 1000 = Digraph( 'm' , filename=filename) # Define a directed graph due north = 0 # The number of all nodes, employ it as the name of the node (code) g.graph_attr.update(splines= "false" , nodesep= '0.eight' , ranksep= 'two' , rankdir= "LR" ) # Prepare the properties of the post-obit figure: Line type, node interval, interval of each level # Input Layer with yard.subgraph(name= 'cluster_input' ) every bit c: the_label = 'Input Layer' c.attr(color= 'white' ) for i in range (input_layer) : north += 1 c.node( str (north) ) c.attr(label=the_label, rank= 'same' ) c.node_attr.update(color= "#2ecc71" , style= "filled" , fontcolor= "#2ecc71" , shape= "circumvolve" ) last_layer_nodes = input_layer # Number of nodes in the last layer nodes_up = input_layer #summary point number # Hidden Layers hidden_layers_nr = len (hidden_layers) # hibernate layer number for i in range (hidden_layers_nr) : with m.subgraph(name= "cluster_" + str (i + 1 ) ) as c: c.attr(color= 'white' ) c.attr(rank= 'same' ) the_label = "Subconscious Layer" + str (i+ ane ) c.attr(characterization=the_label) for j in range (hidden_layers[i] ) : n += 1 c.node( str (n) , shape= "circumvolve" , manner= "filled" , colour= "#3498db" , fontcolor= "#3498db" ) for h in range (nodes_up - last_layer_nodes + one , nodes_up + 1 ) : chiliad.edge( str (h) , str (n) ) # Define the connectedness line from the previous layer to the next layer last_layer_nodes = hidden_layers[i] nodes_up += hidden_layers[i] # Output Layer with g.subgraph(proper name= 'cluster_output' ) as c: c.attr(color= 'white' ) c.attr(rank= 'same' ) for i in range ( one , output_layer + one ) : northward += 1 c.node( str (n) , shape= "circumvolve" , mode= "filled" , color= "#e74c3c" , fontcolor= "#e74c3c" ) for h in range (nodes_up - last_layer_nodes + 1 , nodes_up + 1 ) : g.edge( str (h) , str (northward) ) c.attr(characterization= 'Output Layer' ) c.node_attr.update(color= "#2ecc71" , style= "filled" , fontcolor= "#2ecc71" , shape= "circle" ) g.attr(arrowShape= "none" ) g.edge_attr.update(arrowhead= "none" , colour= "#707070" ) g.return(filename, format = "png" )
I wrote aNeural_Network_Graph
Office, receive input as:
-
input_layer
: Number of input layer neurons -
hidden_layers
: list type, number of hidden layers and number of neurons -
output_layer
: Number of neurons in the output layer
is chosen by defining 3 parametersNeural_Network_Graph
function:
# ------------------------------------------- input_layer = five # Input layer of neurons hidden_layers = [ 10 , 6 ] # Hide layers and quantities output_layer = one # Output layer neurons number # ----------------------------------------------- Neural_Network_Graph(input_layer, hidden_layers, output_layer)
It's easy to get apng
Format of the neural network diagram:
Source: https://programmersought.com/article/12981121025/
0 Response to "Draw Neural Network Architecture Diagram Online"
Post a Comment