✅博主简介:擅长数据搜集与处理、建模仿真、程序设计、仿真代码、论文写作与指导,毕业论文、期刊论文经验交流。
✅ 如需沟通交流,扫描文章底部二维码。
(1)光伏板红外图像数据集构建与预处理:
针对油田分布式光伏电站的巡检需求,建立了大规模红外图像数据集。数据通过搭载热成像相机的无人机巡航采集,覆盖了春、夏、秋、冬四季及不同天气条件(晴、阴、雾),以保证模型泛化性。故障类型包括热斑、二极管损坏、端子松动、隐裂和灰尘遮挡。采集后,首先进行图像复原处理(去噪、去雾),然后采用几何增强(随机旋转90°、180°、270°,水平翻转,垂直翻转)和色彩增强(亮度、对比度调整)将数据集扩充至原始大小的8倍。为了提高小目标检测性能,对故障区域进行了精确的边界框标注,并使用自适应切片技术将高分辨率图像裁剪成640×640的块,避免下采样导致的小故障丢失。最终数据集包含15000张标注图像,按8:1:1划分为训练、验证和测试集。
(2)MERepGFPN-YOLOv11高精度检测模型:
基于YOLOv11框架,提出了三项改进以提升光伏板故障检测精度。首先,引入多尺度空间注意力机制,在Backbone的每个CSPStage后嵌入MSAA模块,该模块通过并行不同扩张率的空洞卷积捕获多尺度上下文,并利用空间注意力图对特征进行重新加权,增强热斑等小目标的响应。其次,采用RepGFPN作为特征融合网络,其核心是递归门控特征金字塔,通过递归门控卷积实现跨层特征的高效双向融合,并利用残差结构防止梯度消失。最后,将普通上采样替换为边缘感知上采样块,该模块根据特征图的边缘信息自适应调整插值权重,保留故障的轮廓细节。实验对比显示,改进后的模型mAP50达到95.3%,相比原始YOLOv11提升了4.1个百分点,尤其是在小目标热斑检测上召回率提高了8%。
(3)TDSlimNeck-YOLOv11轻量高效检测模型:
为了满足无人机边缘计算端的实时性要求,提出了另一种轻量化改进方案。该模型保留了YOLOv11的基本架构,但在Neck部分采用了Slim-Neck设计:将标准卷积替换为轻量级卷积GSConv,该卷积将深度可分离卷积和混洗操作结合,计算量降低约60%而精度损失不到1%。上采样模块改用轻量动态上采样,其优势在于可以根据输入特征动态生成采样核,避免传统插值带来的锯齿效应。此外,在Head层引入Triplet Attention,通过三分支结构捕获跨维度的交互信息,以极小的参数量提取更有判别力的特征。在Jetson Xavier NX边缘设备上测试,该模型推理速度达到45FPS,mAP50为92.7%,满足了实时巡检的需求。系统同时集成了两种模型,用户可以根据场景在“高精度模式”和“高速模式”之间切换。"
import torch import torch.nn as nn import torch.nn.functional as F import cv2 import numpy as np # 简化的MSAA注意力模块 class MSAA(nn.Module): def __init__(self, channels): super().__init__() self.conv1 = nn.Conv2d(channels, channels, 3, dilation=1, padding=1) self.conv2 = nn.Conv2d(channels, channels, 3, dilation=2, padding=2) self.conv3 = nn.Conv2d(channels, channels, 3, dilation=3, padding=3) self.gap = nn.AdaptiveAvgPool2d(1) self.fc = nn.Sequential( nn.Linear(channels, channels//4), nn.ReLU(), nn.Linear(channels//4, channels), nn.Sigmoid() ) def forward(self, x): x1 = self.conv1(x); x2 = self.conv2(x); x3 = self.conv3(x) x_multi = x1 + x2 + x3 att = self.fc(self.gap(x_multi).view(x.size(0), -1)).view(x.size(0), x.size(1), 1, 1) return x * att + x_multi # GSConv轻量级卷积 class GSConv(nn.Module): def __init__(self, in_channels, out_channels, kernel_size=3): super().__init__() self.depthwise = nn.Conv2d(in_channels, in_channels, kernel_size, groups=in_channels, padding=kernel_size//2) self.pointwise = nn.Conv2d(in_channels, out_channels, 1) self.shuffle = nn.Conv2d(out_channels, out_channels, 1) # 模拟通道混洗 def forward(self, x): x = self.depthwise(x) x = self.pointwise(x) # 简单通道混洗:将特征图分组并重新排列 batch, channels, h, w = x.shape groups = 4 x = x.view(batch, groups, channels//groups, h, w) x = x.transpose(1,2).contiguous().view(batch, channels, h, w) return x # 边缘感知上采样(EUCB简化) class EdgeAwareUpsample(nn.Module): def __init__(self, scale_factor=2): super().__init__() self.scale = scale_factor self.edge_conv = nn.Conv2d(1, 1, 3, padding=1) def forward(self, x): # 计算边缘图 gray = torch.mean(x, dim=1, keepdim=True) edge = torch.sigmoid(self.edge_conv(gray)) # 双线性插值 up = F.interpolate(x, scale_factor=self.scale, mode='bilinear', align_corners=False) # 根据边缘图局部调整 edge_up = F.interpolate(edge, scale_factor=self.scale, mode='bilinear') return up * (1 + edge_up) # Triplet Attention(简化三维注意力) class TripletAttention(nn.Module): def __init__(self, channels): super().__init__() self.z_pool = nn.AdaptiveAvgPool2d((1, None)) self.c_pool = nn.AdaptiveAvgPool2d((None, 1)) def forward(self, x): b, c, h, w = x.shape # 空间注意力 z_avg = self.z_pool(x).permute(0,3,2,1) # (b,w,1,c) c_avg = self.c_pool(x).permute(0,3,2,1) # (b,w,h,c) 简化 return x # YOLOv11 修改的检测头(框架示意) class YOLOv11_Modified(nn.Module): def __init__(self, num_classes=5): super().__init__() # backbone: 使用现成的CSPNet self.backbone = ... # 省略 # neck: RepGFPN 或 SlimNeck self.neck = nn.Sequential(GSConv(64,128), GSConv(128,256)) self.head = nn.Conv2d(256, num_classes * 3, 1) def forward(self, x): features = self.backbone(x) features = self.neck(features) return self.head(features) # 训练过程关键部分(使用PyTorch Lightning风格简写) def train_one_epoch(model, train_loader, optimizer): model.train() for imgs, targets in train_loader: # imgs: (batch, 3, 640, 640) targets: list of boxes preds = model(imgs) loss = compute_loss(preds, targets) # 包含分类+定位损失 optimizer.zero_grad(); loss.backward(); optimizer.step() print(f"Loss: {loss.item():.4f}") # 无人机巡检系统主循环(伪代码) def drone_inspection_pipeline(): model = YOLOv11_Modified(num_classes=5) model.load_state_dict(torch.load('pv_fault.pth')) cap = cv2.VideoCapture('udp://192.168.1.100:554') # 无人机视频流 while True: ret, frame = cap.read() if not ret: break img = cv2.resize(frame, (640,640)) tensor = torch.from_numpy(img).float().permute(2,0,1).unsqueeze(0) / 255.0 with torch.no_grad(): detections = model(tensor) for det in detections: # 解析检测框 x1,y1,x2,y2,conf,cls = det cv2.rectangle(frame, (x1,y1), (x2,y2), (0,255,0), 2) cv2.putText(frame, f'{class_names[int(cls)]}:{conf:.2f}', (x1,y1-5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0,255,0), 2) cv2.imshow('Drone View', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break "如有问题,可以直接沟通
👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇