当前位置:网站首页>Interpretation of dataset class of mmdetection
Interpretation of dataset class of mmdetection
2022-06-10 22:41:00 【Wu lele~】
List of articles
Preface
This is mmdetection Source code interpretation part 2 , Main explanation mmdetection Is to initialize the data class . This article takes coco Data sets, for example , Of course , Source code interpretation can not be comprehensive , The important thing is to figure out the idea of the designer and the implementation process . in addition , This article will not be introduced for the time being dataloader The build process .
1、 Overall process
Usually we use pytorch Reading a dataset requires building two parts , One is dataset initialization , It mainly completes the storage path of data sets ; One is to realize getitem Method , Become an iterator to train the model :
Here's the explanation pipline. stay mmdetection in ,pipline It's actually A series of Sequential about image reading , enhance , Consolidated function . That is, an image enhancement object , After the getitem In the use of transforms Yes data enhanced . Here is a simple understanding . I'll talk more about .
2、 Implementation process
2.1. coco_detection Training profile
Intercept mmdetection For train Training set configuration file for . Code :configs/_base_/datasets/coco_detection..
dataset_type = 'CocoDataset'
data_root = '/home/wujian/WLL/mmdet-master/data/coco/'
img_norm_cfg = dict(
mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
train_pipeline = [
dict(type='LoadImageFromFile'),
dict(type='LoadAnnotations', with_bbox=True),
dict(type='Resize', img_scale=(800, 512), keep_ratio=True),
dict(type='RandomFlip', flip_ratio=0.5),
dict(type='Normalize', **img_norm_cfg),
dict(type='Pad', size_divisor=32),
dict(type='DefaultFormatBundle'),
dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels']),
]
In the above configuration file ,dataset_type Means read coco Data set in format .data_root Is the data set storage path .train_pipline Parameter file for image enhancement function .
2.2. CocoDataset initialization
mmdetection Use in build_dataset Function to complete dataset Instantiation .
datasets = [build_dataset(cfg.data.train)]
Inside here build_dataset Essentially, an internal call to build_from_cfg function ( I won't introduce this one , Or too redundant , Mainly understand the design idea ), This function will cfg File is used to CocoDataset Class initialization , and CocoDataset Class inherits from CustomDataset class , I mainly intercept important parts , Address :mmdet/datasets/custom.py.
@DATASETS.register_module()
class CustomDataset(Dataset):
CLASSES = None
def __init__(self,
ann_file,
pipeline,
classes=None,
data_root=None,
img_prefix='',
seg_prefix=None,
proposal_file=None,
test_mode=False,
filter_empty_gt=True):
self.ann_file = ann_file
self.data_root = data_root
self.img_prefix = img_prefix
self.seg_prefix = seg_prefix
self.proposal_file = proposal_file
self.test_mode = test_mode
self.filter_empty_gt = filter_empty_gt
self.CLASSES = self.get_classes(classes)
# load annotations (and proposals)
self.data_infos = self.load_annotations(self.ann_file)
# processing pipeline
self.pipeline = Compose(pipeline)
It's initialized here data_root, It is worth noting that the last line self.pipline = Compose(pipline), This is the first part of instantiating an image enhancement class .
Let's take a look at Compose class :
@PIPELINES.register_module()
class Compose(object):
def __init__(self, transforms):
assert isinstance(transforms, collections.abc.Sequence)
self.transforms = [] # transforms That is, the length of the passed in is 8, And each element is a dictionary list.[{'type':'LoadImageFromFile'}]
for transform in transforms:
if isinstance(transform, dict):
transform = build_from_cfg(transform, PIPELINES)
self.transforms.append(transform)
Parameters transfoms The length is 8 Of list, Each element is a dictionary , The content of the dictionary is train_pipline Chinese content . for instance :
trainsfoms=[{‘type’:LoadImageFromFile},{‘type’:LoadAnnotations}. stay Compose In the initialization , By traversing transforms Inside 8 Elements , utilize build_from_cfg Function completes the instantiation of each class , After that, each instance object append Into the self.transforms In the list . thus ,Compose Class actually stores sequential image enhancement instance objects . thus ,CocoDataset Initialization is partially completed .
2.3. CocoDataset in getitem Realization
put down getitem function , Still in CustomDataset Within class :
def __getitem__(self, idx):
if self.test_mode:
return self.prepare_test_img(idx)
while True:
data = self.prepare_train_img(idx)
if data is None:
idx = self._rand_another(idx) # This is robust , if idx invalid , Then read another image randomly
continue
return data
def prepare_train_img(self, idx):
img_info = self.data_infos[idx]
ann_info = self.get_ann_info(idx)
results = dict(img_info=img_info, ann_info=ann_info)
if self.proposals is not None:
results['proposals'] = self.proposals[idx]
self.pre_pipeline(results)
return self.pipeline(results)
You can see from the function that : First of all, with the help of idx Read data, And then use it prepare_train_img complete data Image enhancement of . after ,return data.
summary
That's all mmdetection in dataset Class instance procedure . First initialize the path and complete image enhancement pipline Example . Then finish getitem function . If you have any questions, welcome +vx:wulele2541612007, Pull you into the group to discuss communication .
边栏推荐
- [debug] could not find ref wiht POC XXX
- [tcapulusdb knowledge base] tcapulusdb tcapdb capacity expansion and contraction introduction
- 【TcaplusDB知识库】TcaplusDB shard搬迁介绍
- Basic use of mathtype7.x
- Pytorch 安装超简单
- 罗永浩:我要是负责人 能让苹果产品上去三个台阶不止
- [MySQL] summary of common data types
- Solution de gestion de la zone pittoresque intelligente pour la réunion des baleines
- [XPath] use following sibling to obtain the following peer nodes
- TcaplusDB君 · 行业新闻汇编(五)
猜你喜欢
随机推荐
【TcaplusDB知识库】TcaplusDB推送配置介绍
按位操作符和移位操作符
[tcapulusdb knowledge base] tcapulusdb machine initialization and launch introduction
GMPNN:Drug-drug interaction prediction with learnable size-adaptive molecular substructures.
修改SpriteMask 的 frontSortingLayer 变量
Shell basic concepts
C program example 1 -- personal address book management system
leetcode 130. Surrounded regions (medium)
【Debug】could not find ref wiht poc XXX解决
[tcapulusdb knowledge base] tcapulusdb daily inspection introduction
中银证券开户安全吗?它和中国银行是什么关系呢?
[MySQL] summary of common data types
Back to table query of MySQL? How to avoid it?
记录(三)
Web3生态去中心化金融平台——Sealem Finance
README
CCF CSP 202109-4 收集卡牌
【Xpath】使用following-sibling获取后面的同级节点
[tcapulusdb knowledge base] tcapulusdb transaction management introduction
SQL server queries are case sensitive







