如何用markdown中的mermaid快速画出不好看的神经网络
如何用markdown中的mermaid快速画出不好看的神经网络
用flowchart
或graph
😭
def gen_mm_nngraph(firstlayer_str,firstlayer_len,secondlayer_str,secondlayer_len,isformat=False):
for i in range(firstlayer_len):
for j in range(secondlayer_len):
print(";{}_{}--->{}_{}".format(firstlayer_str,i,secondlayer_str,j),end="")
if isformat:
print("") #打印换行
print("flowchart LR")
gen_mm_nngraph("a0",3,"a1",4)
gen_mm_nngraph("a1",4,"a2",4)
gen_mm_nngraph("a2",4,"a3",4)
gen_mm_nngraph("a3",4,"a4",1)
粘贴到markdown中的mermaid后如下所示:
```mermaid
[将上面代码生成的一堆字符串粘贴在这里]
```
下面的是flowchart
效果
flowchart LR
;a0_0--->a1_0;a0_0--->a1_1;a0_0--->a1_2;a0_0--->a1_3;a0_1--->a1_0;a0_1--->a1_1;a0_1--->a1_2;a0_1--->a1_3;a0_2--->a1_0;a0_2--->a1_1;a0_2--->a1_2;a0_2--->a1_3;a1_0--->a2_0;a1_0--->a2_1;a1_0--->a2_2;a1_0--->a2_3;a1_1--->a2_0;a1_1--->a2_1;a1_1--->a2_2;a1_1--->a2_3;a1_2--->a2_0;a1_2--->a2_1;a1_2--->a2_2;a1_2--->a2_3;a1_3--->a2_0;a1_3--->a2_1;a1_3--->a2_2;a1_3--->a2_3;a2_0--->a3_0;a2_0--->a3_1;a2_0--->a3_2;a2_0--->a3_3;a2_1--->a3_0;a2_1--->a3_1;a2_1--->a3_2;a2_1--->a3_3;a2_2--->a3_0;a2_2--->a3_1;a2_2--->a3_2;a2_2--->a3_3;a2_3--->a3_0;a2_3--->a3_1;a2_3--->a3_2;a2_3--->a3_3;a3_0--->a4_0;a3_1--->a4_0;a3_2--->a4_0;a3_3--->a4_0
下面的是graph
效果,把上面代码的flowchart
改为graph
即可
graph LR
;a0_0--->a1_0;a0_0--->a1_1;a0_0--->a1_2;a0_0--->a1_3;a0_1--->a1_0;a0_1--->a1_1;a0_1--->a1_2;a0_1--->a1_3;a0_2--->a1_0;a0_2--->a1_1;a0_2--->a1_2;a0_2--->a1_3;a1_0--->a2_0;a1_0--->a2_1;a1_0--->a2_2;a1_0--->a2_3;a1_1--->a2_0;a1_1--->a2_1;a1_1--->a2_2;a1_1--->a2_3;a1_2--->a2_0;a1_2--->a2_1;a1_2--->a2_2;a1_2--->a2_3;a1_3--->a2_0;a1_3--->a2_1;a1_3--->a2_2;a1_3--->a2_3;a2_0--->a3_0;a2_0--->a3_1;a2_0--->a3_2;a2_0--->a3_3;a2_1--->a3_0;a2_1--->a3_1;a2_1--->a3_2;a2_1--->a3_3;a2_2--->a3_0;a2_2--->a3_1;a2_2--->a3_2;a2_2--->a3_3;a2_3--->a3_0;a2_3--->a3_1;a2_3--->a3_2;a2_3--->a3_3;a3_0--->a4_0;a3_1--->a4_0;a3_2--->a4_0;a3_3--->a4_0
用stateDiagram-v2
🤦♂️🤦♀️
将上面的函数随便改改我们可以得到(主要是为了符合stateDiagram-v2
的连接方法):
def gen_mm_nnstateDiagram(firstlayer_str,firstlayer_len,secondlayer_str,secondlayer_len):
for i in range(firstlayer_len):
for j in range(secondlayer_len):
print("{}_{} --> {}_{}".format(firstlayer_str,i,secondlayer_str,j))
print("stateDiagram-v2")
gen_mm_nnstateDiagram("a0",3,"a1",4)
gen_mm_nnstateDiagram("a1",4,"a2",4)
gen_mm_nnstateDiagram("a2",4,"a3",4)
gen_mm_nnstateDiagram("a3",4,"a4",1)
stateDiagram-v2
a0_0 --> a1_0
a0_0 --> a1_1
a0_0 --> a1_2
a0_0 --> a1_3
a0_1 --> a1_0
a0_1 --> a1_1
a0_1 --> a1_2
a0_1 --> a1_3
a0_2 --> a1_0
a0_2 --> a1_1
a0_2 --> a1_2
a0_2 --> a1_3
a1_0 --> a2_0
a1_0 --> a2_1
a1_0 --> a2_2
a1_0 --> a2_3
a1_1 --> a2_0
a1_1 --> a2_1
a1_1 --> a2_2
a1_1 --> a2_3
a1_2 --> a2_0
a1_2 --> a2_1
a1_2 --> a2_2
a1_2 --> a2_3
a1_3 --> a2_0
a1_3 --> a2_1
a1_3 --> a2_2
a1_3 --> a2_3
a2_0 --> a3_0
a2_0 --> a3_1
a2_0 --> a3_2
a2_0 --> a3_3
a2_1 --> a3_0
a2_1 --> a3_1
a2_1 --> a3_2
a2_1 --> a3_3
a2_2 --> a3_0
a2_2 --> a3_1
a2_2 --> a3_2
a2_2 --> a3_3
a2_3 --> a3_0
a2_3 --> a3_1
a2_3 --> a3_2
a2_3 --> a3_3
a3_0 --> a4_0
a3_1 --> a4_0
a3_2 --> a4_0
a3_3 --> a4_0