Bootstrap

可视化展示深度学习模型中模块的详细流程图:结合GraphvizOnline

一、在GPT中输入指令

根据以下Python模块代码,自动生成对应的Graphviz流程图代码,并保持图表简洁清晰,仅展示主流程:
<模块代码>

1. 以YOLOv9中ADown下采样为例:

根据以下Python模块代码,自动生成对应的Graphviz流程图代码,并保持图表简洁清晰,仅展示主流程:
class ADown(nn.Module):
    def __init__(self, c1, c2):  # ch_in, ch_out, shortcut, kernels, groups, expand
        super().__init__()
        self.c = c2 // 2
        self.cv1 = Conv(c1 // 2, self.c, 3, 2, 1)
        self.cv2 = Conv(c1 // 2, self.c, 1, 1, 0)
    def forward(self, x):
        x = torch.nn.functional.avg_pool2d(x, 2, 1, 0, False, True)
        x1,x2 = x.chunk(2, 1)
        x1 = self.cv1(x1)
        x2 = torch.nn.functional.max_pool2d(x2, 3, 2, 1)
        x2 = self.cv2(x2)
        return torch.cat((x1, x2), 1)

2. 系统生成的输出示例:
 

digraph ADown {
    rankdir=TB;
    node [fontname="Arial", shape=box, style=rounded];

    input [label="Input", shape=oval, width=1.2];
    avg_pool [label="AvgPool2D\n(k=2, s=1, p=0)", fontsize=10];
    chunk [label="Chunk (dim=1)", fontsize=10];
    x1_cv1 [label="Conv\n(k=3, s=2, p=1)", fontsize=10];
    x2_max_pool [label="MaxPool2D\n(k=3, s=2, p=1)", fontsize=10];
    x2_cv2 [label="Conv\n(k=1, s=1, p=0)", fontsize=10];
    concat [label="Concat\n(dim=1)", shape=diamond, fontsize=10];
    output [label="Output", shape=oval, width=1.2];

    input -> avg_pool;
    avg_pool -> chunk;
    chunk -> x1_cv1 [label="x1"];
    chunk -> x2_max_pool [label="x2"];
    x1_cv1 -> concat;
    x2_max_pool -> x2_cv2;
    x2_cv2 -> concat;
    concat -> output;
}

二:复制dot代码到GraphvizOnline


GraphvizOnline链接:Graphviz Online

1. GraphvizOnline页面展示

2. 将dot代码复制到GraphvizOnline左面代码框中

3. 右面流程图框自动生成

三、流程图中添加流程说明

1. 以YOLOv9中ADown下采样为例:

根据以下Python模块代码,自动生成对应的Graphviz流程图代码,流程图中添加详细的流程说明,并保持图表简洁清晰:
class ADown(nn.Module):
    def __init__(self, c1, c2):
        super().__init__()
        self.c = c2 // 2
        self.cv1 = Conv(c1 // 2, self.c, 3, 2, 1)
        self.cv2 = Conv(c1 // 2, self.c, 1, 1, 0)

    def forward(self, x):
        x = torch.nn.functional.avg_pool2d(x, 2, 1, 0, False, True)
        x1, x2 = x.chunk(2, 1)
        x1 = self.cv1(x1)
        x2 = torch.nn.functional.max_pool2d(x2, 3, 2, 1)
        x2 = self.cv2(x2)
        return torch.cat((x1, x2), 1)

系统生成的输出示例:

digraph ADown {
    rankdir=LR;
    node [shape=box, fontname="Arial"];

    subgraph cluster_legend {
        label="流程说明";
        fontsize=12;
        style=dotted;
        legend1 [label="1. 输入数据通过平均池化处理 (AvgPool2D)。", shape=note];
        legend2 [label="2. 输入数据分割成两部分 (x1 和 x2)。", shape=note];
        legend3 [label="3. x1 通过一个 3x3 的卷积操作 (Conv)。", shape=note];
        legend4 [label="4. x2 首先经过最大池化 (MaxPool2D),然后通过 1x1 的卷积操作 (Conv)。", shape=note];
        legend5 [label="5. 两个分支的结果在通道维度上进行拼接,得到输出。", shape=note];
    }

    input [label="Input", shape=oval];
    avg_pool [label="AvgPool2D (k=2, s=1, p=0)"];
    chunk [label="Chunk (2, dim=1)"];
    x1_cv1 [label="Conv (k=3, s=2, p=1)"];
    x2_max_pool [label="MaxPool2D (k=3, s=2, p=1)"];
    x2_cv2 [label="Conv (k=1, s=1, p=0)"];
    concat [label="Concat (dim=1)", shape=diamond];
    output [label="Output", shape=oval];

    input -> avg_pool;
    avg_pool -> chunk;
    chunk -> x1_cv1 [label="x1"];
    chunk -> x2_max_pool [label="x2"];
    x1_cv1 -> concat;
    x2_max_pool -> x2_cv2;
    x2_cv2 -> concat;
    concat -> output;
}

2. 将dot代码复制到GraphvizOnline左面代码框中

3.生成流程图

;