# ringmoe **Repository Path**: ray4future/ringmoe ## Basic Information - **Project Name**: ringmoe - **Description**: ringmoe_test - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: new - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2025-05-16 - **Last Updated**: 2025-09-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README --- license: apache-2.0 --- # **RingMoE-遥感图像分类模型** ## 项目简介 本次发布的RingMoE-Classification遥感图像分类模型,以RingMoE基础模型(https://github.com/HanboBizl/RingMoE)为起点,基于昇思框架与昇腾硬件进行了高性能的监督微调。经过微调,模型在遥感图片能力上取得了显著提升:其在遥感图像分类评测集NWPU-RESISC45上准确率达92%,在同级别模型中稳居前列。 我们开源了RingMoE-Classification的模型权重、微调数据及训练代码。该模型不仅是当下领先的遥感分类模型之一,更为开发者提供了如何在有限资源环境下渐进叠加MOE专家组的宝贵经验。并通过蒸馏预热实现了后训练过程。 ## 开发指导 ### 1. 模型文件 RingMoE-Classification基于swin transformer v2 giant(SOTA)的simmim预训练权重进行微调后,该预训练权重先使用ImageNet-22K数据集预训练500K个循环;后基于ImageNet-1K数据集进行监督学习,预训练模型最终在ImageNet-1k上的分类准确率达到86.53。 环境准备: ``` ringmoe ├── prepare.sh # 环境准备脚本,下载数据及权重,并安装 ``` 环境配置: ``` ringmoe/config ├── finetune_single_moe_swin_giant_p4_w7_nwpu_192_100ep.yaml # 微调训练配置文件 ├── eval_single_moe_swin_giant_p4_w7_nwpu_192_100ep.yaml # 微调完成后推理配置文件 ``` 任务启动脚本: ``` ringmoe/scripts └── graph_nwpu_finetune.sh # 模型微调启动脚本,使用以上finetune配置文件 └── graph_nwpu_eval_after_tranin.sh # 模型微调启动脚本,使用以上eval配置文件 ``` ### 2.环境及数据准备 #### 2.1 安装环境 | 软件| 版本 | | --- | --- | | 固件&驱动| 24.1.rc3.5 | | CANN| 7.7.T9.0.B057:8.1.RC1 | | Python | 3.9-3.10 | | MindSpore | 2.6.0 | | MindSpore Lite | 2.6.0 | 香橙派端侧推理时需要 | aicc-tools| 0.2.1 | | scikit-image| 0.24.0 | #### 2.2 数据处理 ##### 2.2.1 数据集下载 用户可以从[https://opendatalab.org.cn/OpenDataLab/NWPU_Data_Sett](https://opendatalab.org.cn/OpenDataLab/NWPU_Data_Set)查看该数据集介绍: 数据集已经上传昇思大模型平台 [xihe.mindspore.cn/datasets/ray4future/NWPU-RESISC45/tree](xihe.mindspore.cn/datasets/ray4future/NWPU-RESISC45/tree) | 数据集名称 | 数据集下载链接(可预览) | | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | | NWPU-RESISC45 | [https://www.kaggle.com/datasets/happyyang/nwpu-data-set](https://www.kaggle.com/datasets/happyyang/nwpu-data-set) | ### 3 训练策略 #### 3.1 权重准备 用户可以从HuggingFace官方下载预训练权重: | 模型名称 | 权重链接 | | ------------------- | --------------------------------------------------------------------------------- | | SwinV2-giant | [https://huggingface.co/zdaxie/SimMIM/resolve/main/simmim_swinv2_finetune_models/finetune_swinv2_giant_22k_500k.pth](https://huggingface.co/zdaxie/SimMIM/resolve/main/simmim_swinv2_finetune_models/finetune_swinv2_giant_22k_500k.pth) | #### 3.2 微调训练过程 1. 在RingMoE Backbone基础增加分类头,加载非moe架构SwinV2-giant权重,并用10%的数据集作为训练数据,训练200个epoch得到基础权重,评测准确率为91% 2. 在从1得到的权重基础上,增加单组moe架构(4个专家+1个路由),得到单组moe架构:原MLP层作为public expert。得到1 public expert + 4 specialized expert(每个专家初始化复制public expert权重) + 1 specialized router架构; 因算力允许,继续使用全参微调,微调100个epoch。 3. 在2的基础上,参考盘古架构,继续增加一组moe架构(既4个专家+1个路由),得到双组moe架构: 原MLP层继续作为public expert,最终架构为1 public expoert + (4 specialized expert+ 1 specialized router)+ (4 cross expert(初始化时复制specialized expert权重)+ 1 cross router(初始化时复制specialized router权重)); 为了防止灾难性遗忘,我们采用强化学习策略,让单组专家模型作为教师模型,双组专家模型作为学生模型进行强化学习。具体流程:把已经微调过的传统MLP+单组专家组成的ringmoe模型作为参考模型,把新增专家组后的传统MLP+双组专家模型作为策略模型,奖励模型由loss损失函数替代,损失函数包括参考模型和策略模型之间的KL散度损失,奖励模型的分类监督损失,以及moe负载均衡损失三部分组成。最终架构如下图所示: ![输入图片说明](https://obs-xihe-beijing4.obs.cn-north-4.myhuaweicloud.com/xihe-img/competition/poster/call_for_demo/picture/ringmoe_classification%E6%9E%B6%E6%9E%84%E5%9B%BE.jpg) | 蒸馏预热相关超参 | 取值 | | ---------------- | --------------------------------------------- | | temperature | 0.6 | | kl_loss_ratio | 0.8 # Kl散度损失ratio | | aux_loss_factor| 0.001 # moe loss ratio | 此外,还实现了convpass低参微调和peft低参微调两种低参微调方法,可以在finetune_single_moe_swin_giant_p4_w7_nwpu_192_100ep.yaml分别打开convpass开关和peft开关后使用。 该训练方案完整实现了RingMoE: Mixture-of-Modality-Experts Multi-Modal Foundation Models for Universal Remote Sensing Image Interpretation(https://arxiv.org/pdf/2504.03166)论文中的模型架构,并创新性的引入了基于强化学习的后训练过程,帮助多MOE架构模型尽快收敛。 微调训练启动脚本 bash graph_nwpu_finetune.sh ### 4. 云端推理评测流程 我们使用剩余的25200张图片做推理评测。 bash graph_nwpu_eval_after_train.sh ![eval_results](https://obs-xihe-beijing4.obs.cn-north-4.myhuaweicloud.com/xihe-img/competition/poster/call_for_demo/picture/ringmoe%E8%AF%84%E4%BC%B0%E7%BB%93%E6%9E%9C.jpg) ### 5. 非moe架构支持香橙派AIpro端侧部署推理 首先将带权重网络导出为mindir格式,然后基于MindSpore Lite编写推理脚本在香橙派20T24G版本上进行推理。 具体参见https://github.com/mindspore-courses/orange-pi-mindspore中RingMoE-Classification部分。 端侧推理精度及推理速度符合要求的截图如下: ![aipro_transfer_results](https://obs-xihe-beijing4.obs.cn-north-4.myhuaweicloud.com/xihe-img/competition/poster/call_for_demo/picture/xiangchengpai1.jpg)