# naic2020_seg_mindspore **Repository Path**: leetar/naic2020_seg_mindspore ## Basic Information - **Project Name**: naic2020_seg_mindspore - **Description**: NAIC AI+遥感影像 mindspore复现 - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2021-08-22 - **Last Updated**: 2022-06-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # AI+遥感影像 mindspore模型自验报告 队伍: 喵喵(\^o\^) 作者: 万笛文 邮箱: wandiwen@qq.com ## 1. 模型简介 本项目来自于2020年全国人工智能大赛 AI+遥感影像赛道,是喵喵(\^o\^)团队的复赛作品在移植而来。原作品基于pytorch,本项目基于mindspore,并且通用于GPU和Ascend平台。 本项目从UNet, DeepLab等等模型中选择EMANet这样的注意力模型作为基础模型,并尝试融合其他方面的优点,从NonLocal, DNL(Disentangled Non-Local), EMA(Expectation-Maximization Attention)等注意力模块中选择了EMA, 从ASPP、Fluff等模块中选择了FLuff作为多尺度融合模块, 简化了PointRend来得到更精细的结果。 ### 1.1. 网络模型结构简介 网络结构图: ```mermaid graph TB Image((图像)) --> Stem[ResNet50C.stem] subgraph Backbone Stem --> L1[ResNet50C.layer1] --> L2[ResNet50C.layer2] --> L3[ResNet50C.layer3 dilation=2] --> L4[ResNet50C.layer4 dilation=4] end L4--> fluff[Fluff模块] --> ema[EMA模块] --> c1[分类器1] .-> loss1[Loss1] c1 --> sr[SimpleRender模块] --> c2[分类器2] c2 .-> loss2[Loss2] c2 --> o(输出结果) ``` 1. Backbone: [ResNet50-C](https://drive.google.com/file/d/1ibhxxzrc-DpoHbHv4tYrqRPC1Ui7RZ-0/view?usp=sharing) [^1] 在语义分割模型中常被使用的模型,它与普通的ResNet相比,将第一个7x7的卷积层替换为了3个3x3的卷积层,是EMANet[^2]使用的backbone。 2. [EMA模块](extension/blocks/ema.py) 出自EMANet(Expectation-Maximization Attention Networks for Semantic Segmentation)[^2], [github](https://github.com/XiaLiPKU/EMANet) 是一种轻量级的注意力网络。 3. [Fluff模块](extension/blocks/fluff.py) 出自Fast Object Detection with Latticed Multi-Scale Feature Fusion[^3] 起到和DeepLabV3+中ASPP的作用,融合多尺度的信息。 4. [SimpleRender模块](detection/attachment/PointRend.py) 用于精细化边缘信息,是PointRend[^4]的简化版,不再抽取一定数量的点训练,而是所有的点都参与了计算。 ### 1.2. 数据集 仅使用了本次比赛的复赛数据集 ### 1.3. 代码提交地址 ### 1.4. 其它 测试时,生成图像列表 文件目录为 ```text |-- images | |-- .tif | |-- ... | `-- .tif `-- labels |-- .png |-- ... `-- png ``` 运行以下代码生成测试列表文件`test_list.txt`, 具体请参看代码 ``` bash cd python /scripts/gen_test_list.py \ --img-dir images \ --mask-dir labels \ --output test_list.txt ``` ## 2. 代码目录结构说明 ```text |-- scripts // 脚本 | |-- run_eval_ascend.sh // Ascend上单卡测试脚本 | |-- run_eval_gpu.sh // GPU上单卡测试脚本 | |-- run_distribute_gpu.sh // GPU上多卡训练脚本 | |-- root_run_distribute_gpu.sh // GPU上多卡训练脚本 (root用户) | |-- run_standalone_train_gpu.sh // GPU上单卡训练脚本 | |-- gen_test_list.py // 生成测试图像列表 | |-- split_dataset.py // 训练时划分数据集 | `-- gen_multicars_json.py |---- src // 源代码 | |-- config.py // 基础配置文件 | |-- dataset.py // 数据集相关 | |-- network.py // 创建网络 | |-- *** // 其他源代码 | `-- loss.py // 损失函数相关 |---- requirements.txt // 环境依赖 |---- README.md // 本文档 |---- images // 生成本文档所需的图片 | `--- **** |---- train.py // 训练脚本 `---- eval.py // 测试脚本 ``` ## 3. 自验结果 ### 3.1. 自验环境 - 系统: Ubuntu 18.04 - Python: 3.7 - MindSpore版本: 1.0.1 - 其他软件 ``` text matplotlib numpy opencv_python Pillow ``` ### 3.2. 训练超参数 - batch_size: 24 - epoch: 100 - learning rate: 3.5e-4 - loss function: SoftmaxCrossEntropyWithLogits - optimizer: Adam - 配置: 4x2080Ti 详见源代码, 如: `src/config.py`, `train.py` ### 3.3. 训练 本模型可在GPU或Ascend上进行单卡或多卡的训练和测试 ### 3.3.1. 如何启动训练脚本 1. 划分数据集`python scripts/split_dataset.py --root ` 2. 修改训练脚本中的环境变量, 数据集路径等等 3. 启动训练, 如 ``` bash bash scripts/root_run_distribute_gpu.sh ``` #### 3.3.2. 训练性能结果 无 ### 3.4. 推理 #### 3.4.1. 如何启动推理脚本 1. 生成测试图像列表, ![测试图像列表](images/test_list.png) 2. 下载模型文件(链接: https://pan.baidu.com/s/1Y7n3Ur70YkEUA3yYusGlYA 密码: i9gg) MD5: d0adc5c3991aeec969c8865989caf0c6 3. 修改测试脚本`scripts/run_eval_gpu.sh`中的路经,例如 ``` bash cd $(cd `dirname $0`; pwd)/.. export SLOG_PRINT_TO_STDOUT=0 train_code_path=/home/wan/Projects/naic2020/naic2020_seg_mindspore eval_path=/home/wan/Projects/naic2020/naic2020_seg_mindspore/cache if [ -d ${eval_path} ]; then rm -rf ${eval_path} fi mkdir -p ${eval_path} python ${train_code_path}/eval.py \ \ --data_root=/home/wan/data/seg_naic/final_test \ --data_lst=/home/wan/data/seg_naic/final_test/test_list.txt \ --ckpt_path /home/wan/Projects/naic2020/naic2020_seg_mindspore/checkpoints/model.ckpt \ --device GPU \ --batch_size=10 \ --num_classes=17 \ --scales=1.0 \ 2>&1 | tee ${eval_path}/eval_log ``` 4. 启动推理脚本 ```bash bash scripts/run_eval_gpu.sh ``` 5. 多尺度推理, 同上,需要修改和运行的脚本为 `scripts/run_eval_multi_scale.sh` 6. Ascend推理 ![Ascend](images/eval_ascend_1.png) #### 3.4.2. 推理精度结果 1. 运行截图 ![运行截图](images/run_results.png) (推理精度结果,与论文精度进行比对,需附截图或日志文件) 参考的论文精度: (建议附截图) 1P推理结果: (需提供包含训练速度的截图或日志文件) 8P推理结果: (需提供包含训练速度的截图或日志文件) 2. **FWIoU精度: 0.5824897298501495** 3. 其他精度信息 mean IoU: 0.5884895839965739 每一类准确率: | | | | | | | | | -------- | -------- | -------- | -------- | -------- | ------ | ------ | | 水体 | 道路 | 建筑物 | 机场 | 火车站 | 光伏 | 停车场 | | 0.785 | 0.796 | 0.85 | nan | nan | nan | 0.797 | | 操场 | 普通耕地 | 农业大棚 | 自然草地 | 绿地绿化 | 自然林 | 人工林 | | 0.849 | 0.557 | 0.616 | 0.343 | 0.125 | 0.616 | 0.278 | | 自然裸土 | 人为裸土 | 其它 | | 0.617 | 0.592 | 0.418 | 4. 多尺度测试结果 ![运行截图](images/run_results_ms.png) FWIoU 精度 **0.5896759167826026** 5. Ascend推理结果, 与GPU推理相同 ![Ascend结果](images/eval_ascend_2.png) ## 4. 参考资料 ### 4.1. 参考git项目 1. EMA [github](https://github.com/XiaLiPKU/EMANet) 2. DNL [github](https://github.com/XrosLiang/DNL-Object-Detection) 3. mmsegmentation [github](https://github.com/open-mmlab/mmsegmentation) ### 4.2. 参考论文 [^1]: He, T., Zhang, Z., Zhang, H., Zhang, Z., Xie, J., & Li, M. (2019). Bag of tricks for image classification with convolutional neural networks. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (pp. 558-567). [^2]: Li, X., Zhong, Z., Wu, J., Yang, Y., Lin, Z., & Liu, H. (2019). Expectation-maximization attention networks for semantic segmentation. In Proceedings of the IEEE International Conference on Computer Vision (pp. 9167-9176). [^3]: Shi, Y., Jiang, B., Che, Z., & Tang, J. (2020). Fast Object Detection with Latticed Multi-Scale Feature Fusion. arXiv preprint arXiv:2011.02780. [^4]: Kirillov, A., Wu, Y., He, K., & Girshick, R. (2020). PointRend: Image segmentation as rendering. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (pp. 9799-9808).