您的位置:首页 > 新闻 > 资讯 > 中国互联网协会是什么单位_杭州网络设计行业公司_发广告推广平台_百度推广怎么样

中国互联网协会是什么单位_杭州网络设计行业公司_发广告推广平台_百度推广怎么样

2025/9/19 7:08:07 来源:https://blog.csdn.net/m0_67647321/article/details/143127914  浏览:    关键词:中国互联网协会是什么单位_杭州网络设计行业公司_发广告推广平台_百度推广怎么样
中国互联网协会是什么单位_杭州网络设计行业公司_发广告推广平台_百度推广怎么样

 秋招面试专栏推荐 :深度学习算法工程师面试问题总结【百面算法工程师】——点击即可跳转


💡💡💡本专栏所有程序均经过测试,可成功执行💡💡💡


本文给大家带来的教程是将YOLO11的backbone替换为CSWin Transformer结构来提取特征。文章在介绍主要的原理后,将手把手教学如何进行模块的代码添加和修改,并将修改后的完整代码放在文章的最后,方便大家一键运行,小白也可轻松上手实践。以帮助您更好地学习深度学习目标检测YOLO系列的挑战。 

专栏地址:YOLO11入门 + 改进涨点——点击即可跳转 欢迎订阅

目录

1.论文

2. CSWin Transformer代码实现

2.1 将CSWin Transformer添加到YOLO11中

2.2 更改init.py文件

2.3 添加yaml文件

2.4 在task.py中进行注册

2.5 执行程序

3.修改后的网络结构图

4. 完整代码分享

5. GFLOPs

6. 进阶

7.总结


1.论文

论文地址:Swin-Transformer点击即可跳转

官方代码:Swin-Transformer官方代码仓库点击即可跳转

2. CSWin Transformer代码实现

2.1 将CSWin Transformer添加到YOLO11中

关键步骤一:将下面代码粘贴到在/ultralytics/ultralytics/nn/modules/block.py中

# ------------------------------------------
# CSWin Transformer
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# written By Xiaoyi Dong
# ------------------------------------------import torch
import torch.nn as nn
import torch.nn.functional as F
from functools import partialfrom timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD
from timm.models.helpers import load_pretrained
from timm.models.layers import DropPath, to_2tuple, trunc_normal_
from timm.models.registry import register_model
from einops.layers.torch import Rearrange
import torch.utils.checkpoint as checkpoint
import numpy as np
import time__all__ = ['CSWin_tiny', 'CSWin_small', 'CSWin_base', 'CSWin_large']class Mlp(nn.Module):def __init__(self, in_features, hidden_features=None, out_features=None, act_layer=nn.GELU, drop=0.):super().__init__()out_features = out_features or in_featureshidden_features = hidden_features or in_featuresself.fc1 = nn.Linear(in_features, hidden_features)self.act = act_layer()self.fc2 = nn.Linear(hidden_features, out_features)self.drop = nn.Dropout(drop)def forward(self, x):x = self.fc1(x)x = self.act(x)x = self.drop(x)x = self.fc2(x)x = self.drop(x)return xclass LePEAttention(nn.Module):def __init__(self, dim, resolution, idx, split_size=7, dim_out=None, num_heads=8, attn_drop=0., proj_drop=0., qk_scale=None):super().__init__()self.dim = dimself.dim_out = dim_out or dimself.resolution = resolutionself.split_size = split_sizeself.num_heads = num_headshead_dim = dim // num_heads# NOTE scale factor was wrong in my original version, can set manually to be compat with prev weightsself.scale = qk_scale or head_dim ** -0.5if idx == -1:H_sp, W_sp = self.resolution, self.resolutionelif idx == 0:H_sp, W_sp = self.resolution, self.split_sizeelif idx == 1:W_sp, H_sp = self.resolution, self.split_sizeelse:print ("ERROR MODE", idx)exit(0)self.H_sp = H_spself.W_sp = W_spstride = 1self.get_v = nn.Conv2d(dim, dim, kernel_size=3, stride=1, padding=1,groups=dim)self.attn_drop = nn.Dropout(attn_drop)def im2cswin(self, x):B, N, C = x.shapeH = W = int(np.sqrt(N))x = x.transpose(-2,-1).contiguous().view(B, C, H, W)x = img2windows(x, self.H_sp, self.W_sp)x = x.reshape(-1, self.H_sp* self.W_sp, self.num_heads, C // self.num_heads).permute(0, 2, 1, 3).contiguous()return xdef get_lepe(self, x, func):B, N, C = x.shapeH = W = int(np.sqrt(N))x = x.transpose(-2,-1).contiguous().view(B, C, H, W)H_sp, W_sp = self.H_sp, self.W_spx = x.view(B, C, H // H_sp, H_sp, W // W_sp, W_sp)x = x.permute(0, 2, 4, 1, 3, 5).contiguous().reshape(-1, C, H_sp, W_sp) ### B', C, H', W'lepe = func(x) ### B', C, H', W'lepe = lepe.reshape(-1, self.num_heads, C // self.num_heads, H_sp * W_sp).permute(0, 1, 3, 2).contiguous()x = x.reshape(-1, self.num_heads, C // self.num_heads, self.H_sp* self.W_sp).permute(0, 1, 3, 2).contiguous()return x, lepedef forward(self, qkv):"""x: B L C"""q,k,v = qkv[0], qkv[1], qkv[2]### Img2WindowH = W = self.resolutionB, L, C = q.shapeassert L == H * W, "flatten img_tokens has wrong size"q = self.im2cswin(q)k = self.im2cswin(k)v, lepe = self.get_lepe(v, self.get_v)q = q * self.scaleattn = (q @ k.transpose(-2, -1))  # B head N C @ B head C N --> B head N Nattn = nn.functional.softmax(attn, dim=-1, dtype=attn.dtype)attn = self.attn_drop(attn)x = (attn @ v) + lepex = x.transpose(1, 2).reshape(-1, self.H_sp* self.W_sp, C)  # B head N N @ B head N C### Window2Imgx = windows2img(x, self.H_sp, self.W_sp, H, W).view(B, -1, C)  # B H' W' Creturn xclass CSWinBlock(nn.Module):def __init__(self, dim, reso, num_heads,split_size=7, mlp_ratio=4., qkv_bias=False, qk_scale=None,drop=0., attn_drop=0., drop_path=0.,act_layer=nn.GELU, norm_layer=nn.LayerNorm,last_stage=False):super().__init__()self.dim = dimself.num_heads = num_headsself.patches_resolution = resoself.split_size = split_sizeself.mlp_ratio = mlp_ratioself.qkv = nn.Linear(dim, dim * 3, bias=qkv_bias)self.norm1 = norm_layer(dim)if self.patches_resolution == split_size:last_stage = Trueif last_stage:self.branch_num = 1else:self.branch_num = 2self.proj = nn.Linear(dim, dim)self.proj_drop = nn.Dropout(drop)if last_stage:self.attns = nn.ModuleList([LePEAttention(dim, resolution=self.patches_resolution, idx = -1,split_size=split_size, num_heads=num_heads, dim_out=dim,qk_scale=qk_scale, attn_drop=attn_drop, proj_drop=drop)for i in range(self.branch_num)])else:self.attns = nn.ModuleList([LePEAttention(dim//2, resolution=self.patches_resolution, idx = i,split_size=split_size, num_heads=num_heads//2, dim_out=dim//2,qk_scale=qk_scale, attn_drop=attn_drop, proj_drop=drop)for i in range(self.branch_num)])mlp_hidden_dim = int(dim * mlp_ratio)self.drop_path = DropPath(drop_path) if drop_path > 0. else nn.Identity()self.mlp = Mlp(in_features=dim, hidden_features=mlp_hidden_dim, out_features=dim, act_layer=act_layer, drop=drop)self.norm2 = norm_layer(dim)def forward(self, x):"""x: B, H*W, C"""H = W = self.patches_resolutionB, L, C = x.shapeassert L == H * W, "flatten img_tokens has wrong size"img = self.norm1(x)qkv = self.qkv(img).reshape(B, -1, 3, C).permute(2, 0, 1, 3)if self.branch_num == 2:x1 = self.attns[0](qkv[:,:,:,:C//2])x2 = self.attns[1](qkv[:,:,:,C//2:])attened_x = torch.cat([x1,x2], dim=2)else:attened_x = self.attns[0](qkv)attened_x = self.proj(attened_x)x = x + self.drop_path(attened_x)x = x + self.drop_path(self.mlp(self.norm2(x)))return xdef img2windows(img, H_sp, W_sp):"""img: B C H W"""B, C, H, W = img.shapeimg_reshape = img.view(B, C, H // H_sp, H_sp, W // W_sp, W_sp)img_perm = img_reshape.permute(0, 2, 4, 3, 5, 1).contiguous().reshape(-1, H_sp* W_sp, C)return img_permdef windows2img(img_splits_hw, H_sp, W_sp, H, W):"""img_splits_hw: B' H W C"""B = int(img_splits_hw.shape[0] / (H * W / H_sp / W_sp))img = img_splits_hw.view(B, H // H_sp, W // W_sp, H_sp, W_sp, -1)img = img.permute(0, 1, 3, 2, 4, 5).contiguous().view(B, H, W, -1)return imgclass Merge_Block(nn.Module):def __init__(self, dim, dim_out, norm_layer=nn.LayerNorm):super().__init__()self.conv = nn.Conv2d(dim, dim_out, 3, 2, 1)self.norm = norm_layer(dim_out)def forward(self, x):B, new_HW, C = x.shapeH = W = int(np.sqrt(new_HW))x = x.transpose(-2, -1).contiguous().view(B, C, H, W)x = self.conv(x)B, C = x.shape[:2]x = x.view(B, C, -1).transpose(-2, -1).contiguous()x = self.norm(x)return xclass CSWinTransformer(nn.Module):""" Vision Transformer with support for patch or hybrid CNN input stage"""def __init__(self, img_size=640, patch_size=16, in_chans=3, num_classes=1000, embed_dim=96, depth=[2,2,6,2], split_size = [3,5,7],num_heads=12, mlp_ratio=4., qkv_bias=True, qk_scale=None, drop_rate=0., attn_drop_rate=0.,drop_path_rate=0., hybrid_backbone=None, norm_layer=nn.LayerNorm, use_chk=False):super().__init__()self.use_chk = use_chkself.num_classes = num_classesself.num_features = self.embed_dim = embed_dim  # num_features for consistency with other modelsheads=num_headsself.stage1_conv_embed = nn.Sequential(nn.Conv2d(in_chans, embed_dim, 7, 4, 2),Rearrange('b c h w -> b (h w) c', h = img_size//4, w = img_size//4),nn.LayerNorm(embed_dim))curr_dim = embed_dimdpr = [x.item() for x in torch.linspace(0, drop_path_rate, np.sum(depth))]  # stochastic depth decay ruleself.stage1 = nn.ModuleList([CSWinBlock(dim=curr_dim, num_heads=heads[0], reso=img_size//4, mlp_ratio=mlp_ratio,qkv_bias=qkv_bias, qk_scale=qk_scale, split_size=split_size[0],drop=drop_rate, attn_drop=attn_drop_rate,drop_path=dpr[i], norm_layer=norm_layer)for i in range(depth[0])])self.merge1 = Merge_Block(curr_dim, curr_dim*2)curr_dim = curr_dim*2self.stage2 = nn.ModuleList([CSWinBlock(dim=curr_dim, num_heads=heads[1], reso=img_size//8, mlp_ratio=mlp_ratio,qkv_bias=qkv_bias, qk_scale=qk_scale, split_size=split_size[1],drop=drop_rate, attn_drop=attn_drop_rate,drop_path=dpr[np.sum(depth[:1])+i], norm_layer=norm_layer)for i in range(depth[1])])self.merge2 = Merge_Block(curr_dim, curr_dim*2)curr_dim = curr_dim*2temp_stage3 = []temp_stage3.extend([CSWinBlock(dim=curr_dim, num_heads=heads[2], reso=img_size//16, mlp_ratio=mlp_ratio,qkv_bias=qkv_bias, qk_scale=qk_scale, split_size=split_size[2],drop=drop_rate, attn_drop=attn_drop_rate,drop_path=dpr[np.sum(depth[:2])+i], norm_layer=norm_layer)for i in range(depth[2])])self.stage3 = nn.ModuleList(temp_stage3)self.merge3 = Merge_Block(curr_dim, curr_dim*2)curr_dim = curr_dim*2self.stage4 = nn.ModuleList([CSWinBlock(dim=curr_dim, num_heads=heads[3], reso=img_size//32, mlp_ratio=mlp_ratio,qkv_bias=qkv_bias, qk_scale=qk_scale, split_size=split_size[-1],drop=drop_rate, attn_drop=attn_drop_rate,drop_path=dpr[np.sum(depth[:-1])+i], norm_layer=norm_layer, last_stage=True)for i in range(depth[-1])])self.apply(self._init_weights)self.channel = [i.size(1) for i in self.forward(torch.randn(1, 3, 640, 640))]def _init_weights(self, m):if isinstance(m, nn.Linear):trunc_normal_(m.weight, std=.02)if isinstance(m, nn.Linear) and m.bias is not None:nn.init.constant_(m.bias, 0)elif isinstance(m, (nn.LayerNorm, nn.BatchNorm2d)):nn.init.constant_(m.bias, 0)nn.init.constant_(m.weight, 1.0)def forward_features(self, x):input_size = x.size(2)scale = [4, 8, 16, 32]features = [None, None, None, None]B = x.shape[0]x = self.stage1_conv_embed(x)for blk in self.stage1:if self.use_chk:x = checkpoint.checkpoint(blk, x)else:x = blk(x)if input_size // int(x.size(1) ** 0.5) in scale:features[scale.index(input_size // int(x.size(1) ** 0.5))] = x.reshape((x.size(0), int(x.size(1) ** 0.5), int(x.size(1) ** 0.5), x.size(2))).permute(0, 3, 1, 2)for pre, blocks in zip([self.merge1, self.merge2, self.merge3], [self.stage2, self.stage3, self.stage4]):x = pre(x)for blk in blocks:if self.use_chk:x = checkpoint.checkpoint(blk, x)else:x = blk(x)if input_size // int(x.size(1) ** 0.5) in scale:features[scale.index(input_size // int(x.size(1) ** 0.5))] = x.reshape((x.size(0), int(x.size(1) ** 0.5), int(x.size(1) ** 0.5), x.size(2))).permute(0, 3, 1, 2)return featuresdef forward(self, x):x = self.forward_features(x)return xdef _conv_filter(state_dict, patch_size=16):""" convert patch embedding weight from manual patchify + linear proj to conv"""out_dict = {}for k, v in state_dict.items():if 'patch_embed.proj.weight' in k:v = v.reshape((v.shape[0], 3, patch_size, patch_size))out_dict[k] = vreturn out_dictdef update_weight(model_dict, weight_dict):idx, temp_dict = 0, {}for k, v in weight_dict.items():# k = k[9:]if k in model_dict.keys() and np.shape(model_dict[k]) == np.shape(v):temp_dict[k] = vidx += 1model_dict.update(temp_dict)print(f'loading weights... {idx}/{len(model_dict)} items')return model_dictdef CSWin_tiny(pretrained=False, **kwargs):model = CSWinTransformer(patch_size=4, embed_dim=64, depth=[1,2,21,1],split_size=[1,2,8,8], num_heads=[2,4,8,16], mlp_ratio=4., **kwargs)if pretrained:model.load_state_dict(update_weight(model.state_dict(), torch.load(pretrained)['state_dict_ema']))return modeldef CSWin_small(pretrained=False, **kwargs):model = CSWinTransformer(patch_size=4, embed_dim=64, depth=[2,4,32,2],split_size=[1,2,8,8], num_heads=[2,4,8,16], mlp_ratio=4., **kwargs)if pretrained:model.load_state_dict(update_weight(model.state_dict(), torch.load(pretrained)['state_dict_ema']))return modeldef CSWin_base(pretrained=False, **kwargs):model = CSWinTransformer(patch_size=4, embed_dim=96, depth=[2,4,32,2],split_size=[1,2,8,8], num_heads=[4,8,16,32], mlp_ratio=4., **kwargs)if pretrained:model.load_state_dict(update_weight(model.state_dict(), torch.load(pretrained)['state_dict_ema']))return modeldef CSWin_large(pretrained=False, **kwargs):model = CSWinTransformer(patch_size=4, embed_dim=144, depth=[2,4,32,2],split_size=[1,2,8,8], num_heads=[6,12,24,24], mlp_ratio=4., **kwargs)if pretrained:model.load_state_dict(update_weight(model.state_dict(), torch.load(pretrained)['state_dict_ema']))return model

2.2 更改init.py文件

关键步骤二:修改modules文件夹下的__init__.py文件,先导入函数

然后在下面的__all__中声明函数

2.3 添加yaml文件

关键步骤三:在/ultralytics/ultralytics/cfg/models/11下面新建文件yolo11_GCNet.yaml文件,粘贴下面的内容

  • 目标检测
# Ultralytics YOLO 🚀, AGPL-3.0 license
# YOLO11 object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect# Parameters
nc: 80 # number of classes
scales: # model compound scaling constants, i.e. 'model=yolo11n.yaml' will call yolo11.yaml with scale 'n'# [depth, width, max_channels]n: [0.50, 0.25, 1024] # summary: 319 layers, 2624080 parameters, 2624064 gradients, 6.6 GFLOPss: [0.50, 0.50, 1024] # summary: 319 layers, 9458752 parameters, 9458736 gradients, 21.7 GFLOPsm: [0.50, 1.00, 512] # summary: 409 layers, 20114688 parameters, 20114672 gradients, 68.5 GFLOPsl: [1.00, 1.00, 512] # summary: 631 layers, 25372160 parameters, 25372144 gradients, 87.6 GFLOPsx: [1.00, 1.50, 512] # summary: 631 layers, 56966176 parameters, 56966160 gradients, 196.0 GFLOPs# YOLO11n backbone
backbone:# [from, repeats, module, args]- [-1, 1, CSWin_tiny, []]  # 4- [-1, 1, SPPF, [1024, 5]]  # 5# YOLO11n head
head:- [-1, 1, nn.Upsample, [None, 2, "nearest"]]- [[-1, 3], 1, Concat, [1]] # cat backbone P4- [-1, 2, C3k2, [512, False]] # 13- [-1, 1, nn.Upsample, [None, 2, "nearest"]]- [[-1, 2], 1, Concat, [1]] # cat backbone P3- [-1, 2, C3k2, [256, False]] # 16 (P3/8-small)- [-1, 1, Conv, [256, 3, 2]]- [[-1, 8], 1, Concat, [1]] # cat head P4- [-1, 2, C3k2, [512, False]] # 19 (P4/16-medium)- [-1, 1, Conv, [512, 3, 2]]- [[-1, 5], 1, Concat, [1]] # cat head P5- [-1, 2, C3k2, [1024, True]] # 22 (P5/32-large)- [[11, 14, 17], 1, Detect, [nc]] # Detect(P3, P4, P5)
  • 语义分割
# Ultralytics YOLO 🚀, AGPL-3.0 license
# YOLO11 object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect# Parameters
nc: 80 # number of classes
scales: # model compound scaling constants, i.e. 'model=yolo11n.yaml' will call yolo11.yaml with scale 'n'# [depth, width, max_channels]n: [0.50, 0.25, 1024] # summary: 319 layers, 2624080 parameters, 2624064 gradients, 6.6 GFLOPss: [0.50, 0.50, 1024] # summary: 319 layers, 9458752 parameters, 9458736 gradients, 21.7 GFLOPsm: [0.50, 1.00, 512] # summary: 409 layers, 20114688 parameters, 20114672 gradients, 68.5 GFLOPsl: [1.00, 1.00, 512] # summary: 631 layers, 25372160 parameters, 25372144 gradients, 87.6 GFLOPsx: [1.00, 1.50, 512] # summary: 631 layers, 56966176 parameters, 56966160 gradients, 196.0 GFLOPs# YOLO11n backbone
backbone:# [from, repeats, module, args]- [-1, 1, CSWin_tiny, []]  # 4- [-1, 1, SPPF, [1024, 5]]  # 5# YOLO11n head
head:- [-1, 1, nn.Upsample, [None, 2, "nearest"]]- [[-1, 3], 1, Concat, [1]] # cat backbone P4- [-1, 2, C3k2, [512, False]] # 13- [-1, 1, nn.Upsample, [None, 2, "nearest"]]- [[-1, 2], 1, Concat, [1]] # cat backbone P3- [-1, 2, C3k2, [256, False]] # 16 (P3/8-small)- [-1, 1, Conv, [256, 3, 2]]- [[-1, 8], 1, Concat, [1]] # cat head P4- [-1, 2, C3k2, [512, False]] # 19 (P4/16-medium)- [-1, 1, Conv, [512, 3, 2]]- [[-1, 5], 1, Concat, [1]] # cat head P5- [-1, 2, C3k2, [1024, True]] # 22 (P5/32-large)- [[11, 14, 17], 1, Segment, [nc, 32, 256]] # Segment(P3, P4, P5)
  • 旋转目标检测
# Ultralytics YOLO 🚀, AGPL-3.0 license
# YOLO11 object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect# Parameters
nc: 80 # number of classes
scales: # model compound scaling constants, i.e. 'model=yolo11n.yaml' will call yolo11.yaml with scale 'n'# [depth, width, max_channels]n: [0.50, 0.25, 1024] # summary: 319 layers, 2624080 parameters, 2624064 gradients, 6.6 GFLOPss: [0.50, 0.50, 1024] # summary: 319 layers, 9458752 parameters, 9458736 gradients, 21.7 GFLOPsm: [0.50, 1.00, 512] # summary: 409 layers, 20114688 parameters, 20114672 gradients, 68.5 GFLOPsl: [1.00, 1.00, 512] # summary: 631 layers, 25372160 parameters, 25372144 gradients, 87.6 GFLOPsx: [1.00, 1.50, 512] # summary: 631 layers, 56966176 parameters, 56966160 gradients, 196.0 GFLOPs# YOLO11n backbone
backbone:# [from, repeats, module, args]- [-1, 1, CSWin_tiny, []]  # 4- [-1, 1, SPPF, [1024, 5]]  # 5# YOLO11n head
head:- [-1, 1, nn.Upsample, [None, 2, "nearest"]]- [[-1, 3], 1, Concat, [1]] # cat backbone P4- [-1, 2, C3k2, [512, False]] # 13- [-1, 1, nn.Upsample, [None, 2, "nearest"]]- [[-1, 2], 1, Concat, [1]] # cat backbone P3- [-1, 2, C3k2, [256, False]] # 16 (P3/8-small)- [-1, 1, Conv, [256, 3, 2]]- [[-1, 8], 1, Concat, [1]] # cat head P4- [-1, 2, C3k2, [512, False]] # 19 (P4/16-medium)- [-1, 1, Conv, [512, 3, 2]]- [[-1, 5], 1, Concat, [1]] # cat head P5- [-1, 2, C3k2, [1024, True]] # 22 (P5/32-large)- [[11, 14, 17], 1, OBB, [nc, 1]] # OBB(P3, P4, P5)

温馨提示:本文只是对yolo11基础上添加模块,如果要对yolo11n/l/m/x进行添加则只需要指定对应的depth_multiple 和 width_multiple


# YOLO11n
depth_multiple: 0.50  # model depth multiple
width_multiple: 0.25  # layer channel multiple
max_channel:1024# YOLO11s
depth_multiple: 0.50  # model depth multiple
width_multiple: 0.50  # layer channel multiple
max_channel:1024# YOLO11m
depth_multiple: 0.50  # model depth multiple
width_multiple: 1.00  # layer channel multiple
max_channel:512# YOLO11l 
depth_multiple: 1.00  # model depth multiple
width_multiple: 1.00  # layer channel multiple
max_channel:512 # YOLO11x
depth_multiple: 1.00  # model depth multiple
width_multiple: 1.50 # layer channel multiple
max_channel:512

2.4 在task.py中进行注册

关键步骤四:在parse_model函数中进行注册,添加CSWin Transformer

先在task.py导入函数

然后在task.py文件下找到parse_model这个函数,如下图,添加CSWin Transformer

        elif m in {CSWin_tiny,CSWin_small,CSWin_large,}:m = m(*args)c2 = m.channel

2.5 执行程序

关键步骤五: 在ultralytics文件中新建train.py,将model的参数路径设置为yolo11_CSWin Transformer.yaml的路径即可

from ultralytics import YOLO
import warnings
warnings.filterwarnings('ignore')
from pathlib import Pathif __name__ == '__main__':# 加载模型model = YOLO("ultralytics/cfg/11/yolo11.yaml")  # 你要选择的模型yaml文件地址# Use the modelresults = model.train(data=r"你的数据集的yaml文件地址",epochs=100, batch=16, imgsz=640, workers=4, name=Path(model.cfg).stem)  # 训练模型

   🚀运行程序,如果出现下面的内容则说明添加成功🚀  

                   from  n    params  module                                       arguments0                  -1  1  21806528  nsformer1                  -1  1    394240  ultralytics.nn.modules.block.SPPF            [512, 256, 5]2                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']3             [-1, 3]  1         0  ultralytics.nn.modules.conv.Concat           [1]4                  -1  1    127680  ultralytics.nn.modules.block.C3k2            [512, 128, 1, False]5                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']6             [-1, 2]  1         0  ultralytics.nn.modules.conv.Concat           [1]7                  -1  1     32096  ultralytics.nn.modules.block.C3k2            [256, 64, 1, False]8                  -1  1     36992  ultralytics.nn.modules.conv.Conv             [64, 64, 3, 2]9             [-1, 8]  1         0  ultralytics.nn.modules.conv.Concat           [1]10                  -1  1     86720  ultralytics.nn.modules.block.C3k2            [192, 128, 1, False]11                  -1  1    147712  ultralytics.nn.modules.conv.Conv             [128, 128, 3, 2]12             [-1, 5]  1         0  ultralytics.nn.modules.conv.Concat           [1]13                  -1  1    378880  ultralytics.nn.modules.block.C3k2            [384, 256, 1, True]14        [11, 14, 17]  1    464912  ultralytics.nn.modules.head.Detect           [80, [64, 128, 256]]
YOLO11_CSWinTransformer summary: 668 layers, 23,475,760 parameters, 23,475,744 gradients, 70.5 GFLOPs

3.修改后的网络结构图

4. 完整代码分享

这个后期补充吧~,先按照步骤来即可

5. GFLOPs

关于GFLOPs的计算方式可以查看百面算法工程师 | 卷积基础知识——Convolution

未改进的YOLO11n GFLOPs

改进后的GFLOPs

6. 进阶

可以与其他的注意力机制或者损失函数等结合,进一步提升检测效果

7.总结

通过以上的改进方法,我们成功提升了模型的表现。这只是一个开始,未来还有更多优化和技术深挖的空间。在这里,我想隆重向大家推荐我的专栏——<专栏地址:YOLO11入门 + 改进涨点——点击即可跳转 欢迎订阅>。这个专栏专注于前沿的深度学习技术,特别是目标检测领域的最新进展,不仅包含对YOLO11的深入解析和改进策略,还会定期更新来自各大顶会(如CVPR、NeurIPS等)的论文复现和实战分享。

为什么订阅我的专栏? ——专栏地址:YOLO11入门 + 改进涨点——点击即可跳转 欢迎订阅

  1. 前沿技术解读:专栏不仅限于YOLO系列的改进,还会涵盖各类主流与新兴网络的最新研究成果,帮助你紧跟技术潮流。

  2. 详尽的实践分享:所有内容实践性也极强。每次更新都会附带代码和具体的改进步骤,保证每位读者都能迅速上手。

  3. 问题互动与答疑:订阅我的专栏后,你将可以随时向我提问,获取及时的答疑

  4. 实时更新,紧跟行业动态:不定期发布来自全球顶会的最新研究方向和复现实验报告,让你时刻走在技术前沿。

专栏适合人群:

  • 对目标检测、YOLO系列网络有深厚兴趣的同学

  • 希望在用YOLO算法写论文的同学

  • 对YOLO算法感兴趣的同学等

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com