class C3TR(C3):
# C3 module with TransformerBlock()
def __init__(self, c1, c2, n=1, shortcut=True, g=1, e=0.5):
super().__init__(c1, c2, n, shortcut, g, e)
c_ = int(c2 * e)
self.m = TransformerBlock(c_, c_, 4, n)
这是 C3 模块的 Transformer 变体,通过用 TransformerBlock 替换 Bottleneck,引入了自注意力机制,增强全局建模能力。
核心思想
输入 x
├──────────────┐
↓ ↓
┌──────┐ ┌──────┐
│ cv1 │ │ cv2 │
└──┬───┘ └──┬───┘
↓ ↓
┌────────────┐ │
│Transformer │ n层 │
│ Block ×n │ │
└────┬───────┘ │





