基于 MMRotate 框架,以 DINOv3 (Meta AI) ViT 为主骨干,在统一的
Backbone → Neck → Head 范式下集成多种旋转目标检测头与多类对照骨干,支持遥感图像 OBB(有向边界框)检测:
- DIOR-R (20 类)
同一套特征可对接不同检测头,便于横向对比。检测头有 Oriented R-CNN / Rotated FCOS / RoI Transformer / YOLO26;骨干覆盖 自监督 DINOv3 ViT、ViT-Adapter、有监督 Swin-Large、DINOv3 蒸馏 Swin、 自研 ViT-L 融合编码(骨干总览见 docs/backbones.md)。
| 检测器 | 类型 | 骨干 / Neck | 配置 |
|---|---|---|---|
| Oriented R-CNN | 两阶段(旋转 RPN + RoI) | ViT-L / ViTDetFPN | configs/oriented_rcnn/oriented_rcnn_dinov3_vitl_fpn_train_dior.py |
| Oriented R-CNN | 两阶段 | ViT-B / ViTDetFPN | configs/oriented_rcnn/oriented_rcnn_dinov3_vitb_fpn_train_dior.py(_trainval 变体) |
| Oriented R-CNN | 两阶段 | ViT-B / SimpleFeaturePyramid | configs/oriented_rcnn/oriented_rcnn_dinov3_vitb_simplefpn_train_dior.py(_trainval) |
| Oriented R-CNN | 两阶段 | ViT-B / SimpleFPN + KFIoU | configs/oriented_rcnn/oriented_rcnn_dinov3_vitb_simplefpn_kfiou_train_dior.py |
| Oriented R-CNN | 两阶段 | ViT-B/L / ViT-Adapter(两阶段训练) | …_dinov3_vit{b,l}_adapter_stage{1,2}_trainval_dior.py |
| Rotated FCOS | 单阶段无锚框 | ViT-L / ViT-Adapter(两阶段训练) | configs/fcos/rotated_fcos_dinov3_vitl_adapter_stage{1,2}_trainval_dior.py |
| YOLO26 | 单阶段无锚框(O2M+O2O 双头,NMS-free) | ViT-B / ViTDetFPN | configs/yolo26/yolo26_dinov3_fpn_train_dior.py |
| YOLO26 | 单阶段无锚框 | ViT-L / ViT-Adapter(两阶段训练) | configs/yolo26/yolo26_dinov3_vitl_adapter_stage{1,2}_trainval_dior.py |
| RoI Transformer | 两阶段(水平 RPN + 旋转细化,KFIoU) | ViT-B / SimpleFPN | configs/roi_trans/roi_trans_dinov3_vitb_simplefpn_kfiou_train_dior.py |
| 骨干 | Neck | 配置 |
|---|---|---|
| Swin-Large(有监督 ImageNet-22k,全参微调) | FPN | configs/oriented_rcnn/oriented_rcnn_swin_large_trainval_dior.py |
Swin-DINOv3 蒸馏(swin_huge,全参 / frozen_stages=4) |
FPN | …_swin_dinov3_trainval_dior.py、…_swin_dinov3_trainval_freeze_dior.py |
| Swin-DINOv3 蒸馏 upsample(全参 / 冻结) | FPN | …_swin_dinov3_upsample_trainval_dior.py、…_upsample_trainval_freeze_dior.py |
| Swin-DINOv3 蒸馏 + Adapter(冻结 Swin + 可变形 Adapter) | FPN | …_swin_dinov3_adapter_trainval_dior.py |
| ViT-L 融合编码(冻结 / 全参) | FusionSimpleFPN | …_custom_dinov3_fusion_freeze_trainval_dior.py、…_custom_dinov3_fusion_trainval_dior.py |
| ViT-L 融合编码 + Adapter(冻结 / 全参) | PassthroughNeck | …_custom_dinov3_fusion_adapter_freeze_trainval_dior.py、…_custom_dinov3_fusion_adapter_trainval_dior.py |
trainval 配置:名称含
_trainval的配置采用「train+val 合并训练 / test 划分用于验证与最终评估」 配方,与同名_train配置(仅用 train 训练、val 验证)相对。
以最常用的 Oriented R-CNN + ViTDetFPN 为例:
输入 (800×800) → DINOv3 ViT → ViTDetFPN → Oriented RPN → Oriented RoI Head → 旋转检测框
| 组件 | 配置 | 说明 |
|---|---|---|
| Backbone | DINOv3 ViT-B/L | 官方 Meta 封装 DinoVisionTransformerBackbone;ViT-B 取 blocks [3,5,8,11],ViT-L 取 [5,11,17,23] |
| ViT-Adapter | 冻结 ViT + 可变形注意力 | 多层 ViT 特征重建为多尺度金字塔,详见 docs/vit_adapter_explained.md |
| 对照 Backbone | Swin-Large / 蒸馏 Swin / 融合编码 | 见 docs/backbones.md |
| Neck | ViTDetFPN(默认)/ SimpleFeaturePyramid / SimpleFPN / FPN / PassthroughNeck / FusionSimpleFPN | 见 docs/backbones.md § Neck |
| 检测头 | OrientedRPN+RoIHead / RotatedFCOS / YOLO26 / RoITrans | 见上表 |
- Python 3.12+
- PyTorch 2.7.1 (CUDA 12.8)
- MMCV 1.7.2 / MMRotate 0.3.4 / MMDetection 2.28.2
- timm >= 1.0
cd third_party/openmmlab/mmrotate
pip install -v -e . --no-build-isolationPyTorch 2.7 兼容性说明:
tools/train.py与tools/test.py内置了 monkey-patch 以适配 PyTorch 2.7+ (_get_stream/Scatter.forward类型修复、_use_replicated_tensor_module属性补充、旋转 NMS 设备修复), 并确保mp_start_method = 'spawn'(CUDA 不支持 fork)。详见 docs/guides/pytorch27_compatibility_fixes.md。
mm_dino/
├── configs/
│ ├── oriented_rcnn/ # Oriented R-CNN(DINOv3 ViT-B/L、Adapter、Swin-Large、Swin-DINOv3、融合)
│ ├── fcos/ # Rotated FCOS(ViT-L + ViT-Adapter 两阶段)
│ ├── roi_trans/ # RoI Transformer
│ └── yolo26/ # YOLO26(ViT-B FPN / ViT-L Adapter 两阶段)
├── models/
│ ├── backbones/
│ │ ├── dinov3_wrapper.py # 官方 DINOv3 封装 DinoVisionTransformerBackbone(主线)
│ │ ├── vit_dinov3.py # timm 版 DINOv3 封装 ViTDinoV3
│ │ ├── _dinov3_specs.py # DINOv3 模型规格共享表(MODEL_SPECS / LVD1689M_CFG)
│ │ ├── dinov3_vit_adapter.py # DINOv3ViTAdapter(可变形注意力多层融合)
│ │ └── custom_dinov3_vit_adapter.py # CustomDINOv3ViTAdapter(自研主干,主线 ViT-L Adapter 系列默认)
│ │ ├── swin_dinov3_wrapper.py # SwinTransformerDINOv3(蒸馏 Swin)
│ │ ├── swin_dinov3_upsample_wrapper.py # SwinTransformerDINOv3Upsample
│ │ ├── swin_dinov3_adapter.py # SwinDINOv3Adapter(蒸馏 Swin + 可变形 Adapter)
│ │ ├── swin_transformer[_upsample].py # 蒸馏 Swin 源码(修了 sys.path / DINOV3_SRC)
│ │ ├── custom_dinov3_fusion.py # CustomDINOv3FusionBackbone(ViT-L + 融合编码)
│ │ └── custom_dinov3_fusion_adapter.py # CustomDINOv3FusionAdapterBackbone(融合 + Adapter)
│ ├── necks/
│ │ ├── vitdet_fpn.py # ViTDetFPN(推荐)
│ │ ├── simple_feature_pyramid.py # SimpleFeaturePyramid(ViTDet 配方)
│ │ ├── simple_fpn.py # SimpleFPN
│ │ ├── passthrough_neck.py # PassthroughNeck(Adapter 透传)
│ │ └── fusion_simple_fpn.py # FusionSimpleFPN(融合骨干配套)
│ ├── heads/yolo26_rotated_head.py # YOLO26 旋转检测头
│ ├── detectors/dinov3_yolo26.py # DINOv3 + YOLO26 检测器
│ ├── detectors/oriented_rcnn_tta.py # OrientedRCNNTTA(多尺度+翻转 TTA,实现 aug_test)
│ ├── datasets/dior.py # DIOR-R 数据集
│ ├── pipelines/albu_metadata.py # Albu 增强 pipeline
│ ├── rsoft_nms.py # 旋转 Soft-NMS + 按类分流(推理后处理,RSOFT_MODE)
│ └── hooks.py # ProgressiveLossHook / RegZeroInitHook
├── tools/ # Python 工具脚本
│ ├── train.py / test.py # 训练 / 评估入口(含 PyTorch 2.7 兼容补丁)
│ ├── plot_loss.py # 训练曲线绘制
│ ├── verify_dinov3_weights.py # DINOv3 权重加载校验
│ ├── verify_adapter_alignment.py # ViT-Adapter 空间对齐校验
│ └── yolo2dota.py # YOLO OBB → DOTA 标注转换
├── scripts/ # 分布式训练/评估 shell 脚本(NUM_GPUS 由 CUDA_VISIBLE_DEVICES 自动推导)
│ ├── orcnn_vit{l,b}_fpn_train.sh、orcnn_vitb_simplefpn_{train,trainval}.sh、orcnn_vitb_kfiou_train.sh
│ ├── orcnn_vit{b,l}_adapter_trainval.sh、fcos_vitl_adapter_trainval.sh、yolo26_vit{b,l}_*.sh、roitrans_vitb_train.sh
│ ├── orcnn_swin_large_trainval.sh
│ ├── orcnn_swin_dinov3_{trainval,trainval_freeze,upsample_trainval,upsample_trainval_freeze,adapter_trainval}.sh
│ ├── orcnn_custom_dinov3_fusion_{freeze,adapter_freeze,adapter,}_trainval.sh
│ ├── orcnn_custom_vitl_adapter_trainval.sh # 主线 ViT-L Adapter 两阶段(含训练后 routed-NMS 测试)
│ ├── eval_oriented.sh # 统一评估入口(routed NMS / 分辨率 / TTA,自动 EMA 提取)
│ ├── test.sh # 分布式评估脚本(基础版)
│ └── train_pipeline.sh # 一键串联主推训练流水线
├── inference/ # 与训练框架解耦的推理(详见 docs/inference.md)
│ ├── torch_inference/ # 纯 PyTorch 推理 + DOTA mAP(零 openmmlab 依赖)
│ └── onnx_inference/ # ONNX (onnxruntime) 推理,支持 GPU/多 GPU/CPU
├── data/
│ ├── prepare_dior.py / convert_dior_xml_to_dota.py / dior_download.py
│ └── weights/ # 预训练权重(见下表)
├── docs/ # 文档(索引见 docs/README.md)
└── third_party/ # 第三方库(DINOv3 / OpenMMLab)
├── dinov3/ # 官方 DINOv3 源码(backbone 经 DINOV3_SRC 引用)
└── openmmlab/mmrotate/ # MMRotate(editable 安装指向此目录)
将 DINOv3 官方权重放入 data/weights/:
| 权重文件 | 模型 | 预训练数据 | 用途 |
|---|---|---|---|
dinov3_vitb16_pretrain_lvd1689m-73cec8be.pth |
ViT-B/16 (768d, 12 blocks) | LVD-1689M | ViT-B 全部配置 |
dinov3_vitl16_pretrain_sat493m-eadcf0ff.pth |
ViT-L/16 (1024d, 24 blocks) | SAT-493M | Oriented R-CNN 非 Adapter 的 ViT-L 配置 |
dinov3_vitl16_pretrain_lvd1689m-8aa4cbdd.pth |
ViT-L/16 (1024d, 24 blocks) | LVD-1689M | ViT-Adapter 系列两阶段配置(orcnn/fcos/yolo26 ViT-L Adapter) |
dinov3_vith16plus_pretrain_lvd1689m-7c1da9a5.pth |
ViT-H+/16 (1280d, 32 blocks) | LVD-1689M | 高精度实验(需手动配置) |
Swin-Large 对照基线用外部 ImageNet-22k 权重
swin_large_patch4_window12_384_22k.pth。 Swin-DINOv3 蒸馏骨干用蒸馏.pth(经SWIN_CKPT注入,须与SWIN_WINDOW_SIZE一致)。 融合骨干用自研weights.pth(含backbone.*+fusion_backbone.*)。
从 DIOR 官网 下载,解压到 data/DIOR-R/ 后转换:
python data/prepare_dior.py --data_root ./data/DIOR-R期望目录结构:
data/DIOR-R/
├── train/{images,labelTxt}/
├── val/{images,labelTxt}/
├── test/{images,labelTxt}/
└── ImageSets/ # train/val/test 划分
# —— 主线(自监督 DINOv3 ViT)——
bash scripts/orcnn_vitl_fpn_train.sh # Oriented R-CNN (ViT-L)
bash scripts/orcnn_vitb_fpn_train.sh # Oriented R-CNN (ViT-B)
bash scripts/yolo26_vitb_train.sh # YOLO26 (ViT-B)
bash scripts/roitrans_vitb_train.sh # RoI Transformer (ViT-B)
bash scripts/orcnn_vitl_adapter_trainval.sh # ViT-Adapter 两阶段(ViT-L)
bash scripts/fcos_vitl_adapter_trainval.sh # Rotated FCOS + ViT-Adapter 两阶段
# ViT-Adapter 只跑某一阶段:STAGE=1 bash scripts/orcnn_vitl_adapter_trainval.sh
# —— 骨干对照实验 ——
bash scripts/orcnn_swin_large_trainval.sh # Swin-Large 有监督对照
bash scripts/orcnn_swin_dinov3_trainval.sh # Swin-DINOv3 蒸馏(全参)
SWIN_CKPT=/path/to/distill.pth bash scripts/orcnn_swin_dinov3_adapter_trainval.sh # 蒸馏 Swin + Adapter
bash scripts/orcnn_custom_dinov3_fusion_trainval.sh # ViT-L 融合编码(全参)
bash scripts/orcnn_custom_dinov3_fusion_adapter_trainval.sh # 融合 + Adapter(全参)
# —— 流水线 / 单卡 / 恢复 ——
bash scripts/train_pipeline.sh # 一键串联主推训练流水线
python tools/train.py configs/oriented_rcnn/oriented_rcnn_dinov3_vitb_fpn_train_dior.py # 单 GPU
python tools/train.py ... --resume-from work_dirs/.../latest.pth # 从检查点恢复python tools/test.py configs/oriented_rcnn/oriented_rcnn_dinov3_vitb_fpn_train_dior.py \
work_dirs/.../best_mAP_epoch_*.pth --eval mAP
# 多卡分布式评估(GPU 数由 CUDA_VISIBLE_DEVICES 自动推导)
CONFIG=...oriented_rcnn_dinov3_vitb_fpn_train_dior.py \
TEST_CKPT=work_dirs/.../best_mAP_epoch_*.pth WORK_DIR=work_dirs/... \
CUDA_VISIBLE_DEVICES=0,1,2,3 SAVE_VIS=0 bash scripts/test.sh
# —— 推荐:统一评估入口 eval_oriented.sh(自动 EMA 提取 + 按需生成配置)——
# 支持 routed NMS / 全 soft / hard(RSOFT_MODE)、输入分辨率(RES)、MS+flip TTA(TTA)
CONFIG=<run>/stage2/..._stage2_trainval_dior.py CKPT=<run>/stage2/best_mAP@*.pth \
bash scripts/eval_oriented.sh # 默认 routed NMS
CONFIG=... CKPT=... RSOFT_MODE=routed TTA=1 bash scripts/eval_oriented.sh # routed + TTA(最高分)
CONFIG=... CKPT=... MODES="hard soft routed" bash scripts/eval_oriented.sh # 三对比训练 checkpoint 可走纯 PyTorch 或 ONNX 推理,详见 docs/inference.md:
bash inference/torch_inference/run.sh # 纯 PyTorch(零 openmmlab 依赖)
python inference/onnx_inference/export/convert.py --config <cfg> --checkpoint <pth> --out model.onnx
ONNX=.../model.onnx bash inference/onnx_inference/run.shpython tools/train.py ... --cfg-options optimizer.lr=5e-5 # 调整学习率
python tools/train.py ... --cfg-options "model.backbone.frozen_stages=4" # 调整冻结层数
python tools/train.py ... --no-validate # 跳过验证加速训练
python tools/train.py ... --cfg-options data.samples_per_gpu=4 data.workers_per_gpu=2 # 显存不足时| airplane | airport | baseballfield | basketballcourt | bridge | | chimney | dam | Expressway-Service-area | Expressway-toll-station | golffield | | groundtrackfield | harbor | overpass | ship | stadium | | storagetank | tenniscourt | trainstation | vehicle | windmill |
| 变体 | 模型名 | embed_dim | depth | 参数量 | 抽取层 |
|---|---|---|---|---|---|
| ViT-S/16 | dinov3_vits16 |
384 | 12 | 22M | — |
| ViT-B/16 ⭐ | dinov3_vitb16 |
768 | 12 | 86M | [3,5,8,11] |
| ViT-L/16 | dinov3_vitl16 |
1024 | 24 | 304M | [5,11,17,23] |
| ViT-H+/16 | dinov3_vith16plus |
1280 | 32 | 632M | [7,15,23,31](需手动配置) |
切换方式:修改 config 中 model.backbone.model_name 与 layers_to_use(并匹配 Neck 的 in_channels)。
Swin / 融合骨干的规格与选型见 docs/backbones.md。
| 配置 | 值 | 说明 |
|---|---|---|
| 优化器 | AdamW (lr=1e-4, weight_decay=0.05) | 分组学习率(backbone lr_mult=0.1~0.25) |
| 学习率调度 | CosineAnnealing + 500 iter warmup | min_lr_ratio=0.1 |
| 批次大小 | 16/GPU(ViT-L 配置 4/GPU) | workers_per_gpu=4 |
| 训练轮数 | 300(两阶段 stage 各 36/24) | evaluation interval=3 |
| 输入分辨率 | 800×800 (多尺度训练) | ViT 特征 50×50 |
| 数据增强 | RandomFlip + PolyRandomRotate + PhotoMetricDistortion + Albu | 多尺度 + 旋转 + 色彩抖动 |
| 混合精度 | fp16 (loss_scale=dynamic) | Adapter/融合冻结配方用 bf16 backbone + fp16=None |
| 梯度裁剪 | max_norm=10 | |
| 多进程方式 | spawn | CUDA 不支持 fork |
| EMA | momentum=0.9998 |
在 9999.pth 主干系列上,通过训练侧 + 推理侧正交杠杆逐步叠加,将测试集 mAP@0.50 从 baseline 0.7575 提升至 0.7940(+3.65,+4.82%):
| 策略 | 重训练 | Best mAP | Δ vs baseline |
|---|---|---|---|
| baseline | — | 0.7575 | — |
RPN 锚框 [8]→[4,8](补小目标召回) |
是 | 0.7600 | +0.25 ↑ |
| + S1/S2 LR/epoch + AdamW 正则 | 是 | 0.7723 | +1.48 ↑ |
+ Routed NMS(按类分流:models/rsoft_nms.py) |
否 | 0.7757 | +1.82 ↑ |
| + 输入分辨率 →1024 | 否 | 0.7796 | +2.21 ↑ |
+ TTA(MS 800/1024 + H/V flip,oriented_rcnn_tta.py) |
否 | 0.7940 | +3.65 ↑ |
弱类改善显著:vehicle +14.6、storagetank +8.8、ship +8.7、golffield +6.5、airport +6.0。
对照消融(均无效或更差,已弃用):Copy-Paste 增强、KFIoU 损失、Fusion backbone、NMS 阈值修改。 完整策略分析、数据集诊断、逐类对比见 docs/mAP_optimization_strategies.md。
完整文档索引见 docs/README.md,要点:
- docs/model_architecture.md — 整体架构详解
- docs/backbones.md — 骨干与 Neck 总览
- docs/vit_adapter_explained.md — ViT-Adapter 原理与诊断
- docs/mAP_optimization_strategies.md — mAP 优化策略汇总(锚框/routed NMS/TTA 等逐类对比)
- docs/inference.md — 推理流水线(纯 PyTorch / ONNX)
- docs/detectors/ — 各检测器详解
- docs/guides/ — 操作指南(权重校验、自定义数据集、兼容修复等)
- docs/archive/ — 历史调试/修复记录
- DINOv3 — Meta AI 自监督 ViT
- Oriented R-CNN — ICCV 2021
- Rotated FCOS — 无锚框旋转检测
- RoI Transformer — CVPR 2019
- YOLO26 — 无锚框旋转检测
- Swin Transformer — 对照基线骨干
- ViT-Adapter — ViT 密集预测适配器
- MMRotate — OpenMMLab 旋转目标检测
- DIOR-R — 遥感旋转目标检测基准
- ViTDet — ViT 用于目标检测
如果本项目对您的研究有帮助,请考虑引用:
@misc{mm_dino,
title = {DINOv3-based Oriented Object Detection for Remote Sensing (mm_dino)},
author = {Tongpeng Guan},
year = {2026},
howpublished = {\url{https://github.com/guantongpeng/mm_dino}},
note = {Oriented R-CNN + DINOv3 ViT-Adapter on DIOR-R; mAP@0.50 = 0.7940}
}主要依赖工作的引用:
@article{dinov3, title={DINOv3}, author={Meta AI}, year={2025}} % 自监督 ViT 主干
@inproceedings{orientedrcnn, title={Oriented R-CNN}, booktitle={ICCV}, year={2021}}
@inproceedings{vitadapter, title={Vision Transformer Adapter for Dense Predictions}, booktitle={CVPR}, year={2023}}
@article{mmrotate, title={MMRotate: A Rotated Object Detection Benchmark using PyTorch}, year={2022}}
@article{dior, title={Object Detection in Optical Remote Sensing Images: A Dataset and Experimental Study}}本项目采用 Apache License 2.0。第三方依赖(DINOv3 / MMRotate / MMDetection 等)保留各自原始许可。