本人采用voc格式数据集对mmseg底层代码进行分析,本文适合对mmseg使用流程比较熟悉的同学食用

数据增广部分代码分析

1.数据增广使用:

mmsegmentation/tools/convert_datasets/voc_aug.py中修改AUG_LEN参数为对应训练集图片数量,并在config文件声明如下:

train=dict(
ann_dir=[‘SegmentationClass’, ‘SegmentationClassAug’],
split=[
‘ImageSets/Segmentation/train.txt’,
‘ImageSets/Segmentation/aug.txt’
]))

2.代码解析

# Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os.path as osp
from functools import partialimport mmcv
import numpy as np
from PIL import Image
from scipy.io import loadmatAUG_LEN = 10582
#对应训练集图片数量"""将.mat文件转换为.png文件"""
def convert_mat(mat_file, in_dir, out_dir):data = loadmat(osp.join(in_dir, mat_file))mask = data['GTcls'][0]['Segmentation'][0].astype(np.uint8)seg_filename = osp.join(out_dir, mat_file.replace('.mat', '.png'))Image.fromarray(mask).save(seg_filename, 'PNG')#生成
def generate_aug_list(merged_list, excluded_list):return list(set(merged_list) - set(excluded_list))def parse_args():parser = argparse.ArgumentParser(description='Convert PASCAL VOC annotations to mmsegmentation format')parser.add_argument('devkit_path', help='pascal voc devkit path')parser.add_argument('aug_path', help='pascal voc aug path')parser.add_argument('-o', '--out_dir', help='output path')parser.add_argument('--nproc', default=1, type=int, help='number of process')args = parser.parse_args()return argsdef main():"""参数初始化"""args = parse_args()devkit_path = args.devkit_path#VOC2012数据地址aug_path = args.aug_path#数据增广地址nproc = args.nproc#并行数if args.out_dir is None:out_dir = osp.join(devkit_path, 'VOC2012', 'SegmentationClassAug')else:out_dir = args.out_dir#数据增广输出地址mmcv.mkdir_or_exist(out_dir)#创建数据增广输出地址in_dir = osp.join(aug_path, 'dataset', 'cls')#拼接数据增广地址mmcv.track_parallel_progress(partial(convert_mat, in_dir=in_dir, out_dir=out_dir),list(mmcv.scandir(in_dir, suffix='.mat')),nproc=nproc)# 并行任务的跟踪进度full_aug_list = []with open(osp.join(aug_path, 'dataset', 'train.txt')) as f:full_aug_list += [line.strip() for line in f]with open(osp.join(aug_path, 'dataset', 'val.txt')) as f:full_aug_list += [line.strip() for line in f]#从增广处获取训练验证标签名称列表with open(osp.join(devkit_path, 'VOC2012/ImageSets/Segmentation','train.txt')) as f:ori_train_list = [line.strip() for line in f]#获取训练集标签名称列表with open(osp.join(devkit_path, 'VOC2012/ImageSets/Segmentation','val.txt')) as f:val_list = [line.strip() for line in f]# 获取验证集标签名称列表aug_train_list = generate_aug_list(ori_train_list + full_aug_list,val_list)assert len(aug_train_list) == AUG_LEN, 'len(aug_train_list) != {}'.format(AUG_LEN)#生成增广的训练标签列表:set(原训练标签列表+增广数据集列表)-set(验证集标签列表)with open(osp.join(devkit_path, 'VOC2012/ImageSets/Segmentation','trainaug.txt'), 'w') as f:f.writelines(line + '\n' for line in aug_train_list)#增广训练数据标签列表写入trainaug.txtaug_list = generate_aug_list(full_aug_list, ori_train_list + val_list)assert len(aug_list) == AUG_LEN - len(ori_train_list), 'len(aug_list) != {}'.format(AUG_LEN -len(ori_train_list))with open(osp.join(devkit_path, 'VOC2012/ImageSets/Segmentation', 'aug.txt'),'w') as f:f.writelines(line + '\n' for line in aug_list)#获取并写入增广数据标签列表print('Done!')if __name__ == '__main__':main()

本文参考内容:mmseg地址

mmseg底层代码分析及修改相关推荐

  1. LDE显示驱动(四):显示驱动内核底层代码分析

    作者:DayInAI 日期:20190124 一.RTMX 1)int de_rtmx_set_route(unsigned int sel, unsigned char pno, unsigned ...

  2. JavaParser生成,分析和修改Java代码

    作为开发人员,我们经常鄙视手动进行重复工作的人员. 我们认为, 他们应该实现这一目标 . 尽管如此,我们还是进行与编码有关的所有活动. 当然,我们使用的高级IDE可以为我们执行一些重构,但这基本上就是 ...

  3. s3c6410 uboot代码分析《一》

    来源:http://hi.baidu.com/__eabi/blog/item/be67533797bc73f014cecb49.html 以下用以记录uboot代码的分析过程,目标是s3c6410, ...

  4. Pixhawk代码分析-启动代码及入口函数

    启动代码及入口函数 基础知识 关于坐标系 1)GeographicCoordinate System Represents position on earth with alongitude and ...

  5. 完整全面的Java资源库(包括构建、操作、代码分析、编译器、数据库、社区等等)...

    构建 这里搜集了用来构建应用程序的工具. Apache Maven:Maven使用声明进行构建并进行依赖管理,偏向于使用约定而不是配置进行构建.Maven优于Apache Ant.后者采用了一种过程化 ...

  6. 基于windows PE文件的恶意代码分析;使用SystemInternal工具与内核调试器研究windows用户空间与内核空间...

    基于windows PE文件的恶意代码分析:使用SystemInternal工具与内核调试器研究windows用户空间与内核空间 ******************** 既然本篇的主角是PE文件,那 ...

  7. linux内存映射起始地址,内存初始化代码分析(三):创建系统内存地址映射

    内存初始化代码分析(三):创建系统内存地址映射 作者:linuxer 发布于:2016-11-24 12:08 分类:内存管理 一.前言 经过内存初始化代码分析(一)和内存初始化代码分析(二)的过渡, ...

  8. Linux GIC代码分析

    一.前言 GIC(Generic Interrupt Controller)是ARM公司提供的一个通用的中断控制器,其architecture specification目前有四个版本,V1-V4(V ...

  9. 三:Sensor SLPI层代码分析---

    三:Sensor SLPI层代码分析 在学习SLPI侧代码前我们先了解下SEE的registry&config. registry 放在/persist/sensors/registry/re ...

最新文章

  1. EasyPHP-2.0b1+ Mantis-1.1.0安装及技巧
  2. 线程池之FixedThreadPool学习
  3. C# CreateParams的使用(解决闪屏问题)
  4. 掌握 Ajax,第 7 部分: 在请求和响应中使用 XML
  5. opencv视频处理和检测学习总结
  6. 【转】Android:ListView常见错位之CheckBox错位
  7. mongodb 库数量限制_使用限制时,使用MongoDB获取文档总数
  8. vs2005设置使用符号服务器
  9. canvas应用之各种游戏转盘
  10. Python TKinter下拉日历控件
  11. 轻量级DI框架Guice使用详解
  12. cadence的工艺角仿真、蒙特卡洛仿真、PSRR
  13. 远程桌面远程控制工具分享
  14. 华为2019数字芯片岗笔试解析(多选部分)
  15. Vue 前端根据坐标点按顺序生成连线
  16. flyingsaucer转换多个html,Flying Saucer实现html转pdf(一些有关问题,持续更新)
  17. 【好消息】高录用、EI检索会议 | 2023年第二届电子信息工程、大数据与计算机技术国际学术会议(EIBDCT 2023)
  18. 三菱PLC QD77定位模块功能块FB ,用私服电机控制中
  19. 不要使用虚函数作为库的接口
  20. Chrome使用独立显卡开启WebGPU

热门文章

  1. 全志A40I方案 全志A40I方案定制 全志A40I软硬件设计定制 全志A40i性能如何
  2. Queue、Deque、LinkedList学习
  3. charles抓手机端的包(android手机)
  4. 团队软件库_if 我是前端团队 Leader,怎么制定前端协作规范?
  5. 工业大数据分析,主要有哪些应用?
  6. 微信小程序引入iconfont
  7. 色卡司 NAS存储器设置
  8. Isaac-gym(3): 官方文档——programming之仿真设置
  9. 关于获取微信小程序码的“47001”错误码的坑
  10. 抖音运营变现必知的几个常识;新手不看后悔一辈子丨国仁网络资讯