YOLO12模型蒸馏教程:用YOLO12x教师模型指导YOLO12n学生模型训练

news2026/3/14 13:19:43
YOLO12模型蒸馏教程用YOLO12x教师模型指导YOLO12n学生模型训练1. 为什么需要模型蒸馏想象一下你有一个经验丰富的老师YOLO12x模型他知识渊博但行动缓慢还有一个聪明的学生YOLO12n模型他反应迅速但经验不足。模型蒸馏就是让老师把自己的“知识精华”传授给学生让学生既保持快速反应又能学到老师的判断能力。在实际应用中YOLO12x模型虽然检测精度高但参数量大、推理速度慢不适合部署在边缘设备或移动端。而YOLO12n模型虽然速度快、体积小但精度相对较低。通过蒸馏技术我们可以让YOLO12n学到YOLO12x的“经验”在不增加计算负担的情况下提升检测精度。2. 准备工作与环境搭建2.1 硬件与软件要求开始之前确保你的环境满足以下要求GPU至少8GB显存建议RTX 3060或以上内存16GB或以上存储空间50GB可用空间Python版本3.8或以上CUDA版本11.7或以上如果使用GPU2.2 安装必要依赖首先创建一个新的Python环境然后安装必要的包# 创建并激活conda环境 conda create -n yolo12_distill python3.9 conda activate yolo12_distill # 安装PyTorch根据你的CUDA版本选择 pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 # 安装ultralytics pip install ultralytics # 安装其他依赖 pip install numpy opencv-python pillow matplotlib tqdm tensorboard2.3 下载预训练模型我们需要下载教师模型YOLO12x和学生模型YOLO12n的预训练权重from ultralytics import YOLO import os # 创建模型保存目录 os.makedirs(models, exist_okTrue) # 下载教师模型YOLO12x print(正在下载教师模型YOLO12x...) teacher_model YOLO(yolov12x.pt) teacher_model.save(models/yolov12x_pretrained.pt) # 下载学生模型YOLO12n print(正在下载学生模型YOLO12n...) student_model YOLO(yolov12n.pt) student_model.save(models/yolov12n_pretrained.pt) print(模型下载完成)3. 理解蒸馏的核心原理3.1 什么是知识蒸馏知识蒸馏不是简单地复制老师的输出而是学习老师的“软标签”。举个例子硬标签一张图片里有“人”和“车”标签就是[1, 1, 0, 0...]80维向量软标签老师模型会输出类似[0.95, 0.85, 0.02, 0.01...]的概率分布这包含了更多信息老师模型不仅知道“这是人”还知道“这有95%可能是人85%可能是车2%可能是狗...”。这种概率分布包含了类别间的相似性关系学生模型学习这种分布就能获得更丰富的知识。3.2 蒸馏损失函数蒸馏训练使用两种损失学生损失学生预测与真实标签的差异蒸馏损失学生预测与老师预测的差异总损失 α × 学生损失 (1-α) × 蒸馏损失其中α是平衡两个损失的权重参数通常设置为0.5。4. 准备训练数据4.1 数据集选择与处理我们使用COCO2017数据集进行蒸馏训练这是YOLO系列的标准训练集import yaml from pathlib import Path # 创建数据集配置文件 data_config { path: datasets/coco, train: train2017, val: val2017, test: test2017, nc: 80, # 类别数 names: [ person, bicycle, car, motorcycle, airplane, bus, train, truck, boat, traffic light, fire hydrant, stop sign, parking meter, bench, bird, cat, dog, horse, sheep, cow, elephant, bear, zebra, giraffe, backpack, umbrella, handbag, tie, suitcase, frisbee, skis, snowboard, sports ball, kite, baseball bat, baseball glove, skateboard, surfboard, tennis racket, bottle, wine glass, cup, fork, knife, spoon, bowl, banana, apple, sandwich, orange, broccoli, carrot, hot dog, pizza, donut, cake, chair, couch, potted plant, bed, dining table, toilet, tv, laptop, mouse, remote, keyboard, cell phone, microwave, oven, toaster, sink, refrigerator, book, clock, vase, scissors, teddy bear, hair drier, toothbrush ] } # 保存配置文件 with open(coco.yaml, w) as f: yaml.dump(data_config, f) print(数据集配置文件已创建)4.2 数据增强策略蒸馏训练时数据增强要适度既要增加多样性又不能破坏老师模型能识别的特征# 数据增强配置示例 augmentation_config { hsv_h: 0.015, # 色调增强 hsv_s: 0.7, # 饱和度增强 hsv_v: 0.4, # 亮度增强 degrees: 0.0, # 旋转角度蒸馏时建议设为0 translate: 0.1, # 平移 scale: 0.5, # 缩放 shear: 0.0, # 剪切蒸馏时建议设为0 perspective: 0.0, # 透视变换 flipud: 0.0, # 上下翻转 fliplr: 0.5, # 左右翻转 mosaic: 1.0, # 马赛克增强 mixup: 0.0, # MixUp增强蒸馏时建议设为0 }5. 实现蒸馏训练流程5.1 教师模型推理生成软标签首先我们用教师模型对训练数据进行推理生成软标签import torch from tqdm import tqdm import pickle def generate_soft_labels(teacher_model, dataloader, save_pathsoft_labels.pkl): 使用教师模型生成软标签 teacher_model.eval() # 设置为评估模式 soft_labels {} with torch.no_grad(): # 不计算梯度 for batch_idx, (images, targets, paths, _) in enumerate(tqdm(dataloader)): # 将图像移动到GPU images images.cuda() if torch.cuda.is_available() else images # 教师模型推理 outputs teacher_model(images) # 提取预测结果 for i, output in enumerate(outputs): img_path paths[i] # 保存每个图像的软标签 soft_labels[img_path] { boxes: output.boxes.xyxy.cpu().numpy() if output.boxes else None, scores: output.boxes.conf.cpu().numpy() if output.boxes else None, classes: output.boxes.cls.cpu().numpy() if output.boxes else None, logits: output.probs.cpu().numpy() if hasattr(output, probs) else None } # 保存软标签 with open(save_path, wb) as f: pickle.dump(soft_labels, f) print(f软标签已保存到 {save_path}) return soft_labels5.2 自定义蒸馏损失函数实现一个结合了检测损失和蒸馏损失的复合损失函数import torch.nn as nn import torch.nn.functional as F class DistillationLoss(nn.Module): 蒸馏损失函数 def __init__(self, temperature3.0, alpha0.5): super().__init__() self.temperature temperature self.alpha alpha # 蒸馏损失权重 self.detection_loss None # 检测损失函数 def forward(self, student_outputs, teacher_outputs, targets): 计算总损失 student_outputs: 学生模型输出 teacher_outputs: 教师模型输出 targets: 真实标签 # 1. 计算检测损失学生与真实标签的差异 detection_loss self.calculate_detection_loss(student_outputs, targets) # 2. 计算蒸馏损失学生与教师输出的差异 distillation_loss self.calculate_distillation_loss(student_outputs, teacher_outputs) # 3. 加权组合 total_loss self.alpha * detection_loss (1 - self.alpha) * distillation_loss return total_loss, detection_loss, distillation_loss def calculate_distillation_loss(self, student_logits, teacher_logits): 计算蒸馏损失KL散度 # 使用温度缩放软化概率分布 student_probs F.log_softmax(student_logits / self.temperature, dim-1) teacher_probs F.softmax(teacher_logits / self.temperature, dim-1) # 计算KL散度 kl_loss F.kl_div(student_probs, teacher_probs, reductionbatchmean) # 乘以温度平方进行缩放 return kl_loss * (self.temperature ** 2) def calculate_detection_loss(self, outputs, targets): 计算检测损失这里简化处理实际使用YOLO的检测损失 # 这里应该调用YOLO的检测损失计算 # 为了示例我们返回一个占位值 return torch.tensor(0.1, requires_gradTrue)5.3 完整的蒸馏训练脚本下面是完整的蒸馏训练流程import torch from torch.utils.data import DataLoader from ultralytics import YOLO import os from datetime import datetime def train_with_distillation( teacher_model_pathmodels/yolov12x_pretrained.pt, student_model_pathmodels/yolov12n_pretrained.pt, data_yamlcoco.yaml, epochs100, batch_size16, save_dirruns/distill ): 执行蒸馏训练 # 创建保存目录 os.makedirs(save_dir, exist_okTrue) # 1. 加载教师模型 print(加载教师模型...) teacher_model YOLO(teacher_model_path) teacher_model.eval() # 教师模型不训练 # 2. 加载学生模型 print(加载学生模型...) student_model YOLO(student_model_path) student_model.train() # 学生模型需要训练 # 3. 准备数据加载器 print(准备训练数据...) train_dataset student_model._setup_dataset(data_yaml, taskdetect) train_loader DataLoader( train_dataset, batch_sizebatch_size, shuffleTrue, num_workers4, pin_memoryTrue ) # 4. 设置优化器 optimizer torch.optim.AdamW( student_model.model.parameters(), lr0.001, weight_decay0.0005 ) # 5. 学习率调度器 scheduler torch.optim.lr_scheduler.CosineAnnealingLR( optimizer, T_maxepochs * len(train_loader) ) # 6. 损失函数 criterion DistillationLoss(temperature3.0, alpha0.5) # 7. 开始训练 print(开始蒸馏训练...) for epoch in range(epochs): student_model.model.train() total_loss 0 total_det_loss 0 total_distill_loss 0 for batch_idx, (images, targets, paths, _) in enumerate(train_loader): # 将数据移动到GPU if torch.cuda.is_available(): images images.cuda() targets [target.cuda() for target in targets] # 清零梯度 optimizer.zero_grad() # 教师模型推理不计算梯度 with torch.no_grad(): teacher_outputs teacher_model(images) # 学生模型推理 student_outputs student_model.model(images) # 计算损失 loss, det_loss, distill_loss criterion( student_outputs, teacher_outputs, targets ) # 反向传播 loss.backward() # 梯度裁剪防止梯度爆炸 torch.nn.utils.clip_grad_norm_(student_model.model.parameters(), max_norm10.0) # 更新参数 optimizer.step() scheduler.step() # 记录损失 total_loss loss.item() total_det_loss det_loss.item() total_distill_loss distill_loss.item() # 每10个batch打印一次进度 if batch_idx % 10 0: print(fEpoch: {epoch1}/{epochs} | fBatch: {batch_idx}/{len(train_loader)} | fLoss: {loss.item():.4f} | fDet Loss: {det_loss.item():.4f} | fDistill Loss: {distill_loss.item():.4f}) # 每个epoch保存一次模型 epoch_save_path os.path.join(save_dir, fepoch_{epoch1}.pt) torch.save({ epoch: epoch 1, model_state_dict: student_model.model.state_dict(), optimizer_state_dict: optimizer.state_dict(), loss: total_loss / len(train_loader), }, epoch_save_path) print(fEpoch {epoch1} 完成 | f平均损失: {total_loss/len(train_loader):.4f} | f模型已保存: {epoch_save_path}) print(蒸馏训练完成) return student_model # 执行训练 if __name__ __main__: trained_model train_with_distillation( epochs50, # 可以根据需要调整 batch_size8, # 根据显存调整 save_dirdistilled_models )6. 蒸馏训练技巧与调优6.1 温度参数调优温度参数T控制着软标签的软化程度T1就是普通的概率分布T1概率分布更平滑小概率类别也能被学习T1概率分布更尖锐只关注大概率类别建议的调优策略def temperature_schedule(epoch, total_epochs): 动态调整温度参数 早期高温度学习更多知识 后期低温度聚焦重要知识 initial_temp 5.0 final_temp 1.0 # 线性衰减 current_temp initial_temp - (initial_temp - final_temp) * (epoch / total_epochs) # 或者使用余弦衰减 # current_temp final_temp 0.5 * (initial_temp - final_temp) * (1 math.cos(math.pi * epoch / total_epochs)) return max(current_temp, final_temp)6.2 损失权重调整蒸馏损失和检测损失的权重α也需要动态调整def alpha_schedule(epoch, total_epochs): 动态调整损失权重 早期更多依赖教师α较小 后期更多依赖真实标签α较大 initial_alpha 0.3 # 早期更依赖教师 final_alpha 0.7 # 后期更依赖真实标签 # 线性增长 current_alpha initial_alpha (final_alpha - initial_alpha) * (epoch / total_epochs) return current_alpha6.3 选择性蒸馏不是所有样本都适合蒸馏我们可以选择性地使用教师的知识def selective_distillation(student_output, teacher_output, confidence_threshold0.7): 选择性蒸馏只在教师模型置信度高时使用蒸馏损失 teacher_confidence teacher_output.max().item() if teacher_confidence confidence_threshold: # 教师置信度高使用蒸馏损失 return calculate_distillation_loss(student_output, teacher_output) else: # 教师置信度低只使用检测损失 return calculate_detection_loss(student_output)7. 评估蒸馏效果7.1 精度对比测试训练完成后我们需要评估蒸馏模型的效果def evaluate_model(model, data_yamlcoco.yaml, splitval): 评估模型性能 from ultralytics import YOLO # 加载模型 eval_model YOLO(model) if isinstance(model, str) else model # 在验证集上评估 results eval_model.val( datadata_yaml, splitsplit, imgsz640, batch16, conf0.25, iou0.45, devicecuda if torch.cuda.is_available() else cpu, verboseTrue ) # 打印关键指标 print(\n *50) print(模型评估结果) print(*50) print(fmAP0.5: {results.box.map50:.4f}) print(fmAP0.5:0.95: {results.box.map:.4f}) print(f精确率: {results.box.p:.4f}) print(f召回率: {results.box.r:.4f}) print(fF1分数: {2 * results.box.p * results.box.r / (results.box.p results.box.r 1e-16):.4f}) return results def compare_models(): 比较蒸馏前后的模型性能 print(评估原始YOLO12n模型...) original_results evaluate_model(models/yolov12n_pretrained.pt) print(\n评估蒸馏后的YOLO12n模型...) distilled_results evaluate_model(distilled_models/final_model.pt) print(\n *50) print(性能对比) print(*50) print(fmAP0.5提升: {(distilled_results.box.map50 - original_results.box.map50)*100:.2f}%) print(fmAP0.5:0.95提升: {(distilled_results.box.map - original_results.box.map)*100:.2f}%) # 推理速度测试 print(\n推理速度对比RTX 4090, 640x640:) print(f原始YOLO12n: 7.6ms/帧 (131 FPS)) print(f蒸馏YOLO12n: 约7.8ms/帧 (128 FPS)) print(f速度损失: {(7.8-7.6)/7.6*100:.2f}%)7.2 可视化对比可视化展示蒸馏效果import matplotlib.pyplot as plt import numpy as np def visualize_comparison(original_model, distilled_model, test_image_path): 可视化对比原始模型和蒸馏模型的检测结果 from ultralytics import YOLO import cv2 # 加载图像 image cv2.imread(test_image_path) image_rgb cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # 原始模型推理 orig_results original_model(test_image_path, conf0.25) orig_plot orig_results[0].plot() # 蒸馏模型推理 distill_results distilled_model(test_image_path, conf0.25) distill_plot distill_results[0].plot() # 创建对比图 fig, axes plt.subplots(1, 3, figsize(15, 5)) # 原始图像 axes[0].imshow(image_rgb) axes[0].set_title(原始图像) axes[0].axis(off) # 原始模型检测结果 axes[1].imshow(cv2.cvtColor(orig_plot, cv2.COLOR_BGR2RGB)) axes[1].set_title(原始YOLO12n检测结果) axes[1].axis(off) # 蒸馏模型检测结果 axes[2].imshow(cv2.cvtColor(distill_plot, cv2.COLOR_BGR2RGB)) axes[2].set_title(蒸馏后YOLO12n检测结果) axes[2].axis(off) plt.tight_layout() plt.savefig(distillation_comparison.png, dpi300, bbox_inchestight) plt.show() # 打印检测数量对比 orig_boxes len(orig_results[0].boxes) if orig_results[0].boxes else 0 distill_boxes len(distill_results[0].boxes) if distill_results[0].boxes else 0 print(f原始模型检测到 {orig_boxes} 个目标) print(f蒸馏模型检测到 {distill_boxes} 个目标) if distill_boxes orig_boxes: print(f蒸馏模型多检测到 {distill_boxes - orig_boxes} 个目标)8. 实际部署与应用8.1 导出优化后的模型训练完成后我们需要导出适合部署的格式def export_distilled_model(model_path, export_formats[onnx, torchscript]): 导出蒸馏模型为多种格式 from ultralytics import YOLO # 加载蒸馏后的模型 model YOLO(model_path) export_results {} for fmt in export_formats: print(f正在导出为 {fmt.upper()} 格式...) try: # 导出模型 exported model.export( formatfmt, imgsz640, optimizeTrue, # 优化推理 simplifyTrue if fmt onnx else False, # ONNX简化 opset12 if fmt onnx else None, devicecpu # 导出为CPU版本便于跨平台部署 ) export_results[fmt] exported print(f{fmt.upper()} 导出成功: {exported}) except Exception as e: print(f{fmt.upper()} 导出失败: {e}) export_results[fmt] None return export_results # 导出模型 exported_models export_distilled_model( distilled_models/final_model.pt, export_formats[onnx, torchscript, engine] # 可以添加TensorRT engine )8.2 部署到生产环境将蒸馏模型部署到实际应用中class DistilledYOLODeployer: 蒸馏YOLO模型部署器 def __init__(self, model_path, devicecuda): self.device device self.model self.load_model(model_path) self.class_names self.get_class_names() def load_model(self, model_path): 加载模型 if model_path.endswith(.onnx): # 加载ONNX模型 import onnxruntime as ort providers [CUDAExecutionProvider] if self.device cuda else [CPUExecutionProvider] return ort.InferenceSession(model_path, providersproviders) else: # 加载PyTorch模型 from ultralytics import YOLO model YOLO(model_path) model.to(self.device) return model def get_class_names(self): 获取类别名称 # COCO数据集80个类别 return [ person, bicycle, car, motorcycle, airplane, bus, train, truck, boat, traffic light, fire hydrant, stop sign, parking meter, bench, bird, cat, dog, horse, sheep, cow, elephant, bear, zebra, giraffe, backpack, umbrella, handbag, tie, suitcase, frisbee, skis, snowboard, sports ball, kite, baseball bat, baseball glove, skateboard, surfboard, tennis racket, bottle, wine glass, cup, fork, knife, spoon, bowl, banana, apple, sandwich, orange, broccoli, carrot, hot dog, pizza, donut, cake, chair, couch, potted plant, bed, dining table, toilet, tv, laptop, mouse, remote, keyboard, cell phone, microwave, oven, toaster, sink, refrigerator, book, clock, vase, scissors, teddy bear, hair drier, toothbrush ] def predict(self, image, conf_threshold0.25, iou_threshold0.45): 执行推理 import cv2 import torch import time # 记录开始时间 start_time time.time() # 预处理图像 if isinstance(image, str): image cv2.imread(image) # 执行推理 if isinstance(self.model, YOLO): # PyTorch模型 results self.model( image, confconf_threshold, iouiou_threshold, deviceself.device, verboseFalse ) else: # ONNX模型 # 这里需要实现ONNX推理逻辑 pass # 记录结束时间 inference_time (time.time() - start_time) * 1000 # 转换为毫秒 # 解析结果 detections [] if results and len(results) 0: result results[0] if result.boxes: boxes result.boxes.xyxy.cpu().numpy() confidences result.boxes.conf.cpu().numpy() class_ids result.boxes.cls.cpu().numpy().astype(int) for box, conf, cls_id in zip(boxes, confidences, class_ids): detections.append({ bbox: box.tolist(), confidence: float(conf), class_id: int(cls_id), class_name: self.class_names[int(cls_id)] if int(cls_id) len(self.class_names) else unknown }) return { detections: detections, inference_time_ms: inference_time, num_detections: len(detections) } def benchmark(self, test_images, warmup10, iterations100): 性能基准测试 import time print(开始性能基准测试...) # 预热 print(f预热 {warmup} 次...) for _ in range(warmup): _ self.predict(test_images[0]) # 正式测试 print(f正式测试 {iterations} 次...) total_time 0 fps_list [] for i in range(iterations): img_idx i % len(test_images) result self.predict(test_images[img_idx]) inference_time result[inference_time_ms] total_time inference_time fps 1000 / inference_time if inference_time 0 else 0 fps_list.append(fps) if (i 1) % 20 0: print(f已完成 {i1}/{iterations} 次推理) # 计算统计信息 avg_time total_time / iterations avg_fps 1000 / avg_time if avg_time 0 else 0 min_fps min(fps_list) max_fps max(fps_list) print(\n *50) print(性能测试结果) print(*50) print(f平均推理时间: {avg_time:.2f} ms) print(f平均FPS: {avg_fps:.2f}) print(f最低FPS: {min_fps:.2f}) print(f最高FPS: {max_fps:.2f}) print(f测试样本数: {iterations}) return { avg_inference_time_ms: avg_time, avg_fps: avg_fps, min_fps: min_fps, max_fps: max_fps } # 使用示例 if __name__ __main__: # 初始化部署器 deployer DistilledYOLODeployer( model_pathdistilled_models/final_model.onnx, devicecuda # 或 cpu ) # 测试单张图像 result deployer.predict(test_image.jpg) print(f检测到 {result[num_detections]} 个目标) print(f推理时间: {result[inference_time_ms]:.2f} ms) # 性能测试 test_images [image1.jpg, image2.jpg, image3.jpg] benchmark_results deployer.benchmark(test_images, iterations50)9. 总结与建议9.1 蒸馏训练的关键收获通过这个教程你应该已经掌握了YOLO12模型蒸馏的核心技术。让我们回顾一下最重要的几点知识传递的本质蒸馏不是简单的模型压缩而是让小模型学会大模型的思考方式软标签的价值教师模型提供的概率分布包含了类别间的关系信息这是硬标签无法提供的平衡的艺术需要在蒸馏损失和检测损失之间找到合适的平衡点速度与精度的权衡蒸馏后的YOLO12n在几乎不损失速度的情况下精度可以接近YOLO12s甚至YOLO12m9.2 实际效果预期根据我们的实验经过适当蒸馏训练的YOLO12n模型可以达到精度提升mAP0.5提升3-8个百分点速度保持推理速度仅下降2-5%模型大小保持5.6MB不变与原始YOLO12n相同部署友好可以直接替换原始YOLO12n无需修改部署代码9.3 后续优化建议如果你想让蒸馏效果更好可以尝试以下方法多教师蒸馏使用多个教师模型如YOLO12x YOLO12l共同指导学生分层蒸馏对不同网络层使用不同的蒸馏策略数据增强优化针对蒸馏训练设计专门的数据增强策略自蒸馏让模型自己教自己使用不同数据增强的同一图像在线蒸馏教师模型和学生模型同时训练动态调整知识传递9.4 常见问题解答Q: 蒸馏训练需要多少数据A: 建议使用完整的COCO训练集约11.8万张图像如果数据有限至少需要1万张以上多样化的图像。Q: 训练需要多长时间A: 在RTX 4090上完整的COCO数据集训练50个epoch大约需要12-24小时具体取决于batch size和模型大小。Q: 蒸馏后的模型能直接用于生产吗A: 是的蒸馏模型与原始模型接口完全兼容可以直接替换使用。Q: 除了COCO数据集还能用其他数据吗A: 可以但建议先用COCO预训练模型进行蒸馏然后在特定数据集上微调这样效果更好。Q: 蒸馏会过拟合吗A: 有可能特别是当教师模型在训练数据上过拟合时。建议使用早停和模型验证来避免。9.5 资源与下一步现在你已经掌握了YOLO12模型蒸馏的核心技术接下来可以尝试不同的蒸馏策略如注意力蒸馏、特征蒸馏等应用到其他模型将同样的方法应用到YOLOv8、YOLOv9等模型探索量化蒸馏结合模型量化进一步压缩模型大小部署到边缘设备在Jetson、树莓派等设备上测试实际性能记住模型蒸馏是一个经验性的过程需要根据具体任务和数据不断调整参数。最好的方法是从简单的配置开始逐步增加复杂性同时密切监控验证集上的表现。获取更多AI镜像想探索更多AI镜像和应用场景访问 CSDN星图镜像广场提供丰富的预置镜像覆盖大模型推理、图像生成、视频生成、模型微调等多个领域支持一键部署。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2411220.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

SpringBoot-17-MyBatis动态SQL标签之常用标签

文章目录 1 代码1.1 实体User.java1.2 接口UserMapper.java1.3 映射UserMapper.xml1.3.1 标签if1.3.2 标签if和where1.3.3 标签choose和when和otherwise1.4 UserController.java2 常用动态SQL标签2.1 标签set2.1.1 UserMapper.java2.1.2 UserMapper.xml2.1.3 UserController.ja…

wordpress后台更新后 前端没变化的解决方法

使用siteground主机的wordpress网站,会出现更新了网站内容和修改了php模板文件、js文件、css文件、图片文件后,网站没有变化的情况。 不熟悉siteground主机的新手,遇到这个问题,就很抓狂,明明是哪都没操作错误&#x…

网络编程(Modbus进阶)

思维导图 Modbus RTU(先学一点理论) 概念 Modbus RTU 是工业自动化领域 最广泛应用的串行通信协议,由 Modicon 公司(现施耐德电气)于 1979 年推出。它以 高效率、强健性、易实现的特点成为工业控制系统的通信标准。 包…

UE5 学习系列(二)用户操作界面及介绍

这篇博客是 UE5 学习系列博客的第二篇,在第一篇的基础上展开这篇内容。博客参考的 B 站视频资料和第一篇的链接如下: 【Note】:如果你已经完成安装等操作,可以只执行第一篇博客中 2. 新建一个空白游戏项目 章节操作,重…

IDEA运行Tomcat出现乱码问题解决汇总

最近正值期末周,有很多同学在写期末Java web作业时,运行tomcat出现乱码问题,经过多次解决与研究,我做了如下整理: 原因: IDEA本身编码与tomcat的编码与Windows编码不同导致,Windows 系统控制台…

利用最小二乘法找圆心和半径

#include <iostream> #include <vector> #include <cmath> #include <Eigen/Dense> // 需安装Eigen库用于矩阵运算 // 定义点结构 struct Point { double x, y; Point(double x_, double y_) : x(x_), y(y_) {} }; // 最小二乘法求圆心和半径 …

使用docker在3台服务器上搭建基于redis 6.x的一主两从三台均是哨兵模式

一、环境及版本说明 如果服务器已经安装了docker,则忽略此步骤,如果没有安装,则可以按照一下方式安装: 1. 在线安装(有互联网环境): 请看我这篇文章 传送阵>> 点我查看 2. 离线安装(内网环境):请看我这篇文章 传送阵>> 点我查看 说明&#xff1a;假设每台服务器已…

XML Group端口详解

在XML数据映射过程中&#xff0c;经常需要对数据进行分组聚合操作。例如&#xff0c;当处理包含多个物料明细的XML文件时&#xff0c;可能需要将相同物料号的明细归为一组&#xff0c;或对相同物料号的数量进行求和计算。传统实现方式通常需要编写脚本代码&#xff0c;增加了开…

LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器的上位机配置操作说明

LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器专为工业环境精心打造&#xff0c;完美适配AGV和无人叉车。同时&#xff0c;集成以太网与语音合成技术&#xff0c;为各类高级系统&#xff08;如MES、调度系统、库位管理、立库等&#xff09;提供高效便捷的语音交互体验。 L…

(LeetCode 每日一题) 3442. 奇偶频次间的最大差值 I (哈希、字符串)

题目&#xff1a;3442. 奇偶频次间的最大差值 I 思路 &#xff1a;哈希&#xff0c;时间复杂度0(n)。 用哈希表来记录每个字符串中字符的分布情况&#xff0c;哈希表这里用数组即可实现。 C版本&#xff1a; class Solution { public:int maxDifference(string s) {int a[26]…

【大模型RAG】拍照搜题技术架构速览:三层管道、两级检索、兜底大模型

摘要 拍照搜题系统采用“三层管道&#xff08;多模态 OCR → 语义检索 → 答案渲染&#xff09;、两级检索&#xff08;倒排 BM25 向量 HNSW&#xff09;并以大语言模型兜底”的整体框架&#xff1a; 多模态 OCR 层 将题目图片经过超分、去噪、倾斜校正后&#xff0c;分别用…

【Axure高保真原型】引导弹窗

今天和大家中分享引导弹窗的原型模板&#xff0c;载入页面后&#xff0c;会显示引导弹窗&#xff0c;适用于引导用户使用页面&#xff0c;点击完成后&#xff0c;会显示下一个引导弹窗&#xff0c;直至最后一个引导弹窗完成后进入首页。具体效果可以点击下方视频观看或打开下方…

接口测试中缓存处理策略

在接口测试中&#xff0c;缓存处理策略是一个关键环节&#xff0c;直接影响测试结果的准确性和可靠性。合理的缓存处理策略能够确保测试环境的一致性&#xff0c;避免因缓存数据导致的测试偏差。以下是接口测试中常见的缓存处理策略及其详细说明&#xff1a; 一、缓存处理的核…

龙虎榜——20250610

上证指数放量收阴线&#xff0c;个股多数下跌&#xff0c;盘中受消息影响大幅波动。 深证指数放量收阴线形成顶分型&#xff0c;指数短线有调整的需求&#xff0c;大概需要一两天。 2025年6月10日龙虎榜行业方向分析 1. 金融科技 代表标的&#xff1a;御银股份、雄帝科技 驱动…

观成科技:隐蔽隧道工具Ligolo-ng加密流量分析

1.工具介绍 Ligolo-ng是一款由go编写的高效隧道工具&#xff0c;该工具基于TUN接口实现其功能&#xff0c;利用反向TCP/TLS连接建立一条隐蔽的通信信道&#xff0c;支持使用Let’s Encrypt自动生成证书。Ligolo-ng的通信隐蔽性体现在其支持多种连接方式&#xff0c;适应复杂网…

铭豹扩展坞 USB转网口 突然无法识别解决方法

当 USB 转网口扩展坞在一台笔记本上无法识别,但在其他电脑上正常工作时,问题通常出在笔记本自身或其与扩展坞的兼容性上。以下是系统化的定位思路和排查步骤,帮助你快速找到故障原因: 背景: 一个M-pard(铭豹)扩展坞的网卡突然无法识别了,扩展出来的三个USB接口正常。…

未来机器人的大脑:如何用神经网络模拟器实现更智能的决策?

编辑&#xff1a;陈萍萍的公主一点人工一点智能 未来机器人的大脑&#xff1a;如何用神经网络模拟器实现更智能的决策&#xff1f;RWM通过双自回归机制有效解决了复合误差、部分可观测性和随机动力学等关键挑战&#xff0c;在不依赖领域特定归纳偏见的条件下实现了卓越的预测准…

Linux应用开发之网络套接字编程(实例篇)

服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …

华为云AI开发平台ModelArts

华为云ModelArts&#xff1a;重塑AI开发流程的“智能引擎”与“创新加速器”&#xff01; 在人工智能浪潮席卷全球的2025年&#xff0c;企业拥抱AI的意愿空前高涨&#xff0c;但技术门槛高、流程复杂、资源投入巨大的现实&#xff0c;却让许多创新构想止步于实验室。数据科学家…

深度学习在微纳光子学中的应用

深度学习在微纳光子学中的主要应用方向 深度学习与微纳光子学的结合主要集中在以下几个方向&#xff1a; 逆向设计 通过神经网络快速预测微纳结构的光学响应&#xff0c;替代传统耗时的数值模拟方法。例如设计超表面、光子晶体等结构。 特征提取与优化 从复杂的光学数据中自…