修改
在YOLOv11中ultralytics->nn->tasks.py文件,导入CBAM模块,在
from ultralytics.nn.modules import # 添加CBAM模块



添加
在
def parse_model(d, ch, verbose=True): # 中添加CBAM模块

添加 elif m is CBAM:
if m in {BottleneckCSP, C1, C2, C2f, C2fAttn, C3, C3TR, C3Ghost, C3x, RepC3}:
args.insert(2, n) # number of repeats
n = 1
elif m is AIFI:
args = [ch[f], *args]
elif m in {HGStem, HGBlock}:
c1, cm, c2 = ch[f], args[0], args[1]
args = [c1, cm, c2, *args[2:]]
if m is HGBlock:
args.insert(4, n) # number of repeats
n = 1
elif m is ResNetLayer:
c2 = args[1] if args[3] else args[1] * 4
elif m is nn.BatchNorm2d:
args = [ch[f]]
elif m is Concat:
c2 = sum(ch[x] for x in f)
elif m in {Detect, WorldDetect, Segment, Pose, OBB, ImagePoolingAttn}:
args.append([ch[x] for x in f])
if m is Segment:
args[2] = make_divisible(min(args[2], max_channels) * width, 8)
elif m is RTDETRDecoder: # special case, channels arg must be passed in index 1
args.insert(1, [ch[x] for x in f])
elif m is CBLinear:
c2 = args[0]
c1 = ch[f]
args = [c1, c2, *args[1:]]
elif m is CBFuse:
c2 = ch[f[-1]]
elif m is CBAM:
c1, c2 = ch[f], args[0]
if c2 != nc:
c2 = make_divisible(min(c2, max_channels)*width, 8)
args = [c1, *args[1:]]
else:
c2 = ch[f]
elif m is CBAM:
c1, c2 = ch[f], args[0]
if c2 != nc:
c2 = make_divisible(min(c2, max_channels)*width, 8)
args = [c1, *args[1:]]
查看conv.py模块是否存在“CBAM”


查看__init__.py文件中CBAM模块


修改配置文件,复制一份yolov11-obb.yaml文件,命名位yolov11_CBAM.yaml文件

新建文件查看模块是否添加成功

添加成功
注:yolov11和yolov8一样,CBAM模块不易添加过多,过多模块容易引起模型过拟合,适得其反,一般情况n/s尺度的模型只在head中间层添加一个CBAM模块,m/l/x模块可以酌情添加2-3个CBAM模块,分别在backbone尾和head中间层添加,添加完成后一定记得修改head层中引用的层数
5941

被折叠的 条评论
为什么被折叠?



