Ah, I see the issue. Mermaid doesn't support connecting directly to subgraph labels in this way. Let me provide a correct version that achieves the visual effect you want by using invisible nodes to represent the stage boundaries:
graph TD;
%% === 1. DEFINE ALL NODES ===
classDef stage fill:#f8f9fa,stroke:#333,stroke-width:2px,stroke-dasharray: 3;
classDef io fill:#e6f3ff,stroke:#333,stroke-width:2px;
classDef invisible fill:none,stroke:none;
Input["Input Tensor <br/> (Batch, Seq_Len, 17, 3)"];
Output(("Output Logit <br/> (Batch, 1)"));
%% Invisible nodes to represent stage boundaries
Stage1[ ]:::invisible;
Stage2[ ]:::invisible;
Stage3[ ]:::invisible;
%% === 2. GROUP NODES INTO STAGES ===
subgraph " "
S1_A["Flatten Keypoints <br/> (Batch, Seq_Len, 51)"];
S1_B["Linear Embedding <br/> (51 -> d_model)"];
S1_A --> S1_B;
end
subgraph " "
S2_A["Add Positional Encoding"];
S2_B["N x Transformer Encoder Layers <br/> (Multi-Head Self-Attention)"];
S2_C["Mean Pooling over Sequence <br/> (Temporal Aggregation)"];
S2_A --> S2_B --> S2_C;
end
subgraph " "
S3_A["MLP Classifier <br/> (Linear -> ReLU -> Linear)"];
end
%% === 3. DEFINE STAGE-TO-STAGE CONNECTIONS ===
Input --> Stage1;
Stage1 --> Stage2;
Stage2 --> Stage3;
Stage3 --> Output;
%% === 4. APPLY STYLES ===
class Input,Output io;
class S1_A,S1_B,S2_A,S2_B,S2_C,S3_A stage;
class Stage1,Stage2,Stage3 invisible;
Alternative approach that might work better (using subgraph IDs):
graph TD;
%% === 1. DEFINE ALL NODES ===
classDef stage fill:#f8f9fa,stroke:#333,stroke-width:2px,stroke-dasharray: 3;
classDef io fill:#e6f3ff,stroke:#333,stroke-width:2px;
Input["Input Tensor <br/> (Batch, Seq_Len, 17, 3)"];
Output(("Output Logit <br/> (Batch, 1)"));
%% === 2. GROUP NODES INTO STAGES ===
subgraph id1["Stage 1: Input Processing"]
S1_A["Flatten Keypoints <br/> (Batch, Seq_Len, 51)"];
S1_B["Linear Embedding <br/> (51 -> d_model)"];
S1_A --> S1_B;
end
subgraph id2["Stage 2: Temporal Feature Extraction"]
S2_A["Add Positional Encoding"];
S2_B["N x Transformer Encoder Layers <br/> (Multi-Head Self-Attention)"];
S2_C["Mean Pooling over Sequence <br/> (Temporal Aggregation)"];
S2_A --> S2_B --> S2_C;
end
subgraph id3["Stage 3: Classification Head"]
S3_A["MLP Classifier <br/> (Linear -> ReLU -> Linear)"];
end
%% === 3. DEFINE STAGE-TO-STAGE CONNECTIONS ===
Input --> id1;
id1 --> id2;
id2 --> id3;
id3 --> Output;
%% === 4. APPLY STYLES ===
class Input,Output io;
class S1_A,S1_B,S2_A,S2_B,S2_C,S3_A stage;
The second version should work correctly in most Mermaid implementations, as it uses the subgraph IDs (id1, id2, id3) as connection points. This creates the visual effect of arrows connecting to the stage boundaries rather than the internal nodes.