Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- mmdet_code/SR-TOD/configs/_base_/datasets/ade20k_instance.py +53 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/ade20k_panoptic.py +38 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/ade20k_semantic.py +48 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/cityscapes_detection.py +84 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/cityscapes_instance.py +113 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/coco_caption.py +60 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/coco_detection_aitod.py +96 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/coco_detection_dota.py +96 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/coco_detection_drones.py +96 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/coco_detection_visdrone.py +96 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/coco_instance.py +95 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/coco_instance_semantic.py +78 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/coco_panoptic.py +94 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/coco_semantic.py +78 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/deepfashion.py +95 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/dsdl.py +62 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/isaid_instance.py +59 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/lvis_v0.5_instance.py +79 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/lvis_v1_instance.py +22 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/mot_challenge.py +90 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/mot_challenge_det.py +66 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/mot_challenge_reid.py +61 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/objects365v1_detection.py +74 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/objects365v2_detection.py +73 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/openimages_detection.py +81 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/refcoco+.py +55 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/refcoco.py +55 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/refcocog.py +55 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/semi_coco_detection.py +178 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/voc0712.py +92 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/wider_face.py +73 -0
- mmdet_code/SR-TOD/configs/_base_/datasets/youtube_vis.py +66 -0
- mmdet_code/SR-TOD/docs/en/Makefile +20 -0
- mmdet_code/SR-TOD/docs/en/_static/css/readthedocs.css +6 -0
- mmdet_code/SR-TOD/docs/en/_static/image/mmdet-logo.png +3 -0
- mmdet_code/SR-TOD/docs/en/advanced_guides/conventions.md +111 -0
- mmdet_code/SR-TOD/docs/en/advanced_guides/customize_dataset.md +433 -0
- mmdet_code/SR-TOD/docs/en/advanced_guides/customize_losses.md +126 -0
- mmdet_code/SR-TOD/docs/en/advanced_guides/customize_models.md +412 -0
- mmdet_code/SR-TOD/docs/en/advanced_guides/customize_runtime.md +391 -0
- mmdet_code/SR-TOD/docs/en/advanced_guides/customize_transforms.md +49 -0
- mmdet_code/SR-TOD/docs/en/advanced_guides/data_flow.md +1 -0
- mmdet_code/SR-TOD/docs/en/advanced_guides/datasets.md +1 -0
- mmdet_code/SR-TOD/docs/en/advanced_guides/engine.md +1 -0
- mmdet_code/SR-TOD/docs/en/advanced_guides/evaluation.md +1 -0
- mmdet_code/SR-TOD/docs/en/advanced_guides/how_to.md +222 -0
- mmdet_code/SR-TOD/docs/en/advanced_guides/index.rst +34 -0
- mmdet_code/SR-TOD/docs/en/advanced_guides/models.md +1 -0
- mmdet_code/SR-TOD/docs/en/advanced_guides/structures.md +1 -0
- mmdet_code/SR-TOD/docs/en/advanced_guides/transforms.md +42 -0
mmdet_code/SR-TOD/configs/_base_/datasets/ade20k_instance.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'ADE20KInstanceDataset'
|
| 3 |
+
data_root = 'data/ADEChallengeData2016/'
|
| 4 |
+
|
| 5 |
+
# Example to use different file client
|
| 6 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 7 |
+
# automatically infer from prefix (not support LMDB and Memcache yet)
|
| 8 |
+
|
| 9 |
+
# data_root = 's3://openmmlab/datasets/detection/ADEChallengeData2016/'
|
| 10 |
+
|
| 11 |
+
# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
|
| 12 |
+
# backend_args = dict(
|
| 13 |
+
# backend='petrel',
|
| 14 |
+
# path_mapping=dict({
|
| 15 |
+
# './data/': 's3://openmmlab/datasets/detection/',
|
| 16 |
+
# 'data/': 's3://openmmlab/datasets/detection/'
|
| 17 |
+
# }))
|
| 18 |
+
backend_args = None
|
| 19 |
+
|
| 20 |
+
test_pipeline = [
|
| 21 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 22 |
+
dict(type='Resize', scale=(2560, 640), keep_ratio=True),
|
| 23 |
+
# If you don't have a gt annotation, delete the pipeline
|
| 24 |
+
dict(type='LoadAnnotations', with_bbox=True, with_mask=True),
|
| 25 |
+
dict(
|
| 26 |
+
type='PackDetInputs',
|
| 27 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 28 |
+
'scale_factor'))
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
val_dataloader = dict(
|
| 32 |
+
batch_size=1,
|
| 33 |
+
num_workers=2,
|
| 34 |
+
persistent_workers=True,
|
| 35 |
+
drop_last=False,
|
| 36 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 37 |
+
dataset=dict(
|
| 38 |
+
type=dataset_type,
|
| 39 |
+
data_root=data_root,
|
| 40 |
+
ann_file='ade20k_instance_val.json',
|
| 41 |
+
data_prefix=dict(img='images/validation'),
|
| 42 |
+
test_mode=True,
|
| 43 |
+
pipeline=test_pipeline,
|
| 44 |
+
backend_args=backend_args))
|
| 45 |
+
test_dataloader = val_dataloader
|
| 46 |
+
|
| 47 |
+
val_evaluator = dict(
|
| 48 |
+
type='CocoMetric',
|
| 49 |
+
ann_file=data_root + 'ade20k_instance_val.json',
|
| 50 |
+
metric=['bbox', 'segm'],
|
| 51 |
+
format_only=False,
|
| 52 |
+
backend_args=backend_args)
|
| 53 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/ade20k_panoptic.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'ADE20KPanopticDataset'
|
| 3 |
+
data_root = 'data/ADEChallengeData2016/'
|
| 4 |
+
|
| 5 |
+
backend_args = None
|
| 6 |
+
|
| 7 |
+
test_pipeline = [
|
| 8 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 9 |
+
dict(type='Resize', scale=(2560, 640), keep_ratio=True),
|
| 10 |
+
dict(type='LoadPanopticAnnotations', backend_args=backend_args),
|
| 11 |
+
dict(
|
| 12 |
+
type='PackDetInputs',
|
| 13 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 14 |
+
'scale_factor'))
|
| 15 |
+
]
|
| 16 |
+
|
| 17 |
+
val_dataloader = dict(
|
| 18 |
+
batch_size=1,
|
| 19 |
+
num_workers=0,
|
| 20 |
+
persistent_workers=False,
|
| 21 |
+
drop_last=False,
|
| 22 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 23 |
+
dataset=dict(
|
| 24 |
+
type=dataset_type,
|
| 25 |
+
data_root=data_root,
|
| 26 |
+
ann_file='ade20k_panoptic_val.json',
|
| 27 |
+
data_prefix=dict(img='images/validation/', seg='ade20k_panoptic_val/'),
|
| 28 |
+
test_mode=True,
|
| 29 |
+
pipeline=test_pipeline,
|
| 30 |
+
backend_args=backend_args))
|
| 31 |
+
test_dataloader = val_dataloader
|
| 32 |
+
|
| 33 |
+
val_evaluator = dict(
|
| 34 |
+
type='CocoPanopticMetric',
|
| 35 |
+
ann_file=data_root + 'ade20k_panoptic_val.json',
|
| 36 |
+
seg_prefix=data_root + 'ade20k_panoptic_val/',
|
| 37 |
+
backend_args=backend_args)
|
| 38 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/ade20k_semantic.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
dataset_type = 'ADE20KSegDataset'
|
| 2 |
+
data_root = 'data/ADEChallengeData2016/'
|
| 3 |
+
|
| 4 |
+
# Example to use different file client
|
| 5 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 6 |
+
# automatically infer from prefix (not support LMDB and Memcache yet)
|
| 7 |
+
|
| 8 |
+
# data_root = 's3://openmmlab/datasets/detection/ADEChallengeData2016/'
|
| 9 |
+
|
| 10 |
+
# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
|
| 11 |
+
# backend_args = dict(
|
| 12 |
+
# backend='petrel',
|
| 13 |
+
# path_mapping=dict({
|
| 14 |
+
# './data/': 's3://openmmlab/datasets/detection/',
|
| 15 |
+
# 'data/': 's3://openmmlab/datasets/detection/'
|
| 16 |
+
# }))
|
| 17 |
+
backend_args = None
|
| 18 |
+
|
| 19 |
+
test_pipeline = [
|
| 20 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 21 |
+
dict(type='Resize', scale=(2048, 512), keep_ratio=True),
|
| 22 |
+
dict(
|
| 23 |
+
type='LoadAnnotations',
|
| 24 |
+
with_bbox=False,
|
| 25 |
+
with_mask=False,
|
| 26 |
+
with_seg=True,
|
| 27 |
+
reduce_zero_label=True),
|
| 28 |
+
dict(
|
| 29 |
+
type='PackDetInputs', meta_keys=('img_path', 'ori_shape', 'img_shape'))
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
val_dataloader = dict(
|
| 33 |
+
batch_size=1,
|
| 34 |
+
num_workers=2,
|
| 35 |
+
persistent_workers=True,
|
| 36 |
+
drop_last=False,
|
| 37 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 38 |
+
dataset=dict(
|
| 39 |
+
type=dataset_type,
|
| 40 |
+
data_root=data_root,
|
| 41 |
+
data_prefix=dict(
|
| 42 |
+
img_path='images/validation',
|
| 43 |
+
seg_map_path='annotations/validation'),
|
| 44 |
+
pipeline=test_pipeline))
|
| 45 |
+
test_dataloader = val_dataloader
|
| 46 |
+
|
| 47 |
+
val_evaluator = dict(type='SemSegMetric', iou_metrics=['mIoU'])
|
| 48 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/cityscapes_detection.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'CityscapesDataset'
|
| 3 |
+
data_root = 'data/cityscapes/'
|
| 4 |
+
|
| 5 |
+
# Example to use different file client
|
| 6 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 7 |
+
# automatically infer from prefix (not support LMDB and Memcache yet)
|
| 8 |
+
|
| 9 |
+
# data_root = 's3://openmmlab/datasets/segmentation/cityscapes/'
|
| 10 |
+
|
| 11 |
+
# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
|
| 12 |
+
# backend_args = dict(
|
| 13 |
+
# backend='petrel',
|
| 14 |
+
# path_mapping=dict({
|
| 15 |
+
# './data/': 's3://openmmlab/datasets/segmentation/',
|
| 16 |
+
# 'data/': 's3://openmmlab/datasets/segmentation/'
|
| 17 |
+
# }))
|
| 18 |
+
backend_args = None
|
| 19 |
+
|
| 20 |
+
train_pipeline = [
|
| 21 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 22 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 23 |
+
dict(
|
| 24 |
+
type='RandomResize',
|
| 25 |
+
scale=[(2048, 800), (2048, 1024)],
|
| 26 |
+
keep_ratio=True),
|
| 27 |
+
dict(type='RandomFlip', prob=0.5),
|
| 28 |
+
dict(type='PackDetInputs')
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
test_pipeline = [
|
| 32 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 33 |
+
dict(type='Resize', scale=(2048, 1024), keep_ratio=True),
|
| 34 |
+
# If you don't have a gt annotation, delete the pipeline
|
| 35 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 36 |
+
dict(
|
| 37 |
+
type='PackDetInputs',
|
| 38 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 39 |
+
'scale_factor'))
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
train_dataloader = dict(
|
| 43 |
+
batch_size=1,
|
| 44 |
+
num_workers=2,
|
| 45 |
+
persistent_workers=True,
|
| 46 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 47 |
+
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
| 48 |
+
dataset=dict(
|
| 49 |
+
type='RepeatDataset',
|
| 50 |
+
times=8,
|
| 51 |
+
dataset=dict(
|
| 52 |
+
type=dataset_type,
|
| 53 |
+
data_root=data_root,
|
| 54 |
+
ann_file='annotations/instancesonly_filtered_gtFine_train.json',
|
| 55 |
+
data_prefix=dict(img='leftImg8bit/train/'),
|
| 56 |
+
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
| 57 |
+
pipeline=train_pipeline,
|
| 58 |
+
backend_args=backend_args)))
|
| 59 |
+
|
| 60 |
+
val_dataloader = dict(
|
| 61 |
+
batch_size=1,
|
| 62 |
+
num_workers=2,
|
| 63 |
+
persistent_workers=True,
|
| 64 |
+
drop_last=False,
|
| 65 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 66 |
+
dataset=dict(
|
| 67 |
+
type=dataset_type,
|
| 68 |
+
data_root=data_root,
|
| 69 |
+
ann_file='annotations/instancesonly_filtered_gtFine_val.json',
|
| 70 |
+
data_prefix=dict(img='leftImg8bit/val/'),
|
| 71 |
+
test_mode=True,
|
| 72 |
+
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
| 73 |
+
pipeline=test_pipeline,
|
| 74 |
+
backend_args=backend_args))
|
| 75 |
+
|
| 76 |
+
test_dataloader = val_dataloader
|
| 77 |
+
|
| 78 |
+
val_evaluator = dict(
|
| 79 |
+
type='CocoMetric',
|
| 80 |
+
ann_file=data_root + 'annotations/instancesonly_filtered_gtFine_val.json',
|
| 81 |
+
metric='bbox',
|
| 82 |
+
backend_args=backend_args)
|
| 83 |
+
|
| 84 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/cityscapes_instance.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'CityscapesDataset'
|
| 3 |
+
data_root = 'data/cityscapes/'
|
| 4 |
+
|
| 5 |
+
# Example to use different file client
|
| 6 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 7 |
+
# automatically infer from prefix (not support LMDB and Memcache yet)
|
| 8 |
+
|
| 9 |
+
# data_root = 's3://openmmlab/datasets/segmentation/cityscapes/'
|
| 10 |
+
|
| 11 |
+
# Method 2: Use backend_args, file_client_args in versions before 3.0.0rc6
|
| 12 |
+
# backend_args = dict(
|
| 13 |
+
# backend='petrel',
|
| 14 |
+
# path_mapping=dict({
|
| 15 |
+
# './data/': 's3://openmmlab/datasets/segmentation/',
|
| 16 |
+
# 'data/': 's3://openmmlab/datasets/segmentation/'
|
| 17 |
+
# }))
|
| 18 |
+
backend_args = None
|
| 19 |
+
|
| 20 |
+
train_pipeline = [
|
| 21 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 22 |
+
dict(type='LoadAnnotations', with_bbox=True, with_mask=True),
|
| 23 |
+
dict(
|
| 24 |
+
type='RandomResize',
|
| 25 |
+
scale=[(2048, 800), (2048, 1024)],
|
| 26 |
+
keep_ratio=True),
|
| 27 |
+
dict(type='RandomFlip', prob=0.5),
|
| 28 |
+
dict(type='PackDetInputs')
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
test_pipeline = [
|
| 32 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 33 |
+
dict(type='Resize', scale=(2048, 1024), keep_ratio=True),
|
| 34 |
+
# If you don't have a gt annotation, delete the pipeline
|
| 35 |
+
dict(type='LoadAnnotations', with_bbox=True, with_mask=True),
|
| 36 |
+
dict(
|
| 37 |
+
type='PackDetInputs',
|
| 38 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 39 |
+
'scale_factor'))
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
train_dataloader = dict(
|
| 43 |
+
batch_size=1,
|
| 44 |
+
num_workers=2,
|
| 45 |
+
persistent_workers=True,
|
| 46 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 47 |
+
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
| 48 |
+
dataset=dict(
|
| 49 |
+
type='RepeatDataset',
|
| 50 |
+
times=8,
|
| 51 |
+
dataset=dict(
|
| 52 |
+
type=dataset_type,
|
| 53 |
+
data_root=data_root,
|
| 54 |
+
ann_file='annotations/instancesonly_filtered_gtFine_train.json',
|
| 55 |
+
data_prefix=dict(img='leftImg8bit/train/'),
|
| 56 |
+
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
| 57 |
+
pipeline=train_pipeline,
|
| 58 |
+
backend_args=backend_args)))
|
| 59 |
+
|
| 60 |
+
val_dataloader = dict(
|
| 61 |
+
batch_size=1,
|
| 62 |
+
num_workers=2,
|
| 63 |
+
persistent_workers=True,
|
| 64 |
+
drop_last=False,
|
| 65 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 66 |
+
dataset=dict(
|
| 67 |
+
type=dataset_type,
|
| 68 |
+
data_root=data_root,
|
| 69 |
+
ann_file='annotations/instancesonly_filtered_gtFine_val.json',
|
| 70 |
+
data_prefix=dict(img='leftImg8bit/val/'),
|
| 71 |
+
test_mode=True,
|
| 72 |
+
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
| 73 |
+
pipeline=test_pipeline,
|
| 74 |
+
backend_args=backend_args))
|
| 75 |
+
|
| 76 |
+
test_dataloader = val_dataloader
|
| 77 |
+
|
| 78 |
+
val_evaluator = [
|
| 79 |
+
dict(
|
| 80 |
+
type='CocoMetric',
|
| 81 |
+
ann_file=data_root +
|
| 82 |
+
'annotations/instancesonly_filtered_gtFine_val.json',
|
| 83 |
+
metric=['bbox', 'segm'],
|
| 84 |
+
backend_args=backend_args),
|
| 85 |
+
dict(
|
| 86 |
+
type='CityScapesMetric',
|
| 87 |
+
seg_prefix=data_root + 'gtFine/val',
|
| 88 |
+
outfile_prefix='./work_dirs/cityscapes_metric/instance',
|
| 89 |
+
backend_args=backend_args)
|
| 90 |
+
]
|
| 91 |
+
|
| 92 |
+
test_evaluator = val_evaluator
|
| 93 |
+
|
| 94 |
+
# inference on test dataset and
|
| 95 |
+
# format the output results for submission.
|
| 96 |
+
# test_dataloader = dict(
|
| 97 |
+
# batch_size=1,
|
| 98 |
+
# num_workers=2,
|
| 99 |
+
# persistent_workers=True,
|
| 100 |
+
# drop_last=False,
|
| 101 |
+
# sampler=dict(type='DefaultSampler', shuffle=False),
|
| 102 |
+
# dataset=dict(
|
| 103 |
+
# type=dataset_type,
|
| 104 |
+
# data_root=data_root,
|
| 105 |
+
# ann_file='annotations/instancesonly_filtered_gtFine_test.json',
|
| 106 |
+
# data_prefix=dict(img='leftImg8bit/test/'),
|
| 107 |
+
# test_mode=True,
|
| 108 |
+
# filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
| 109 |
+
# pipeline=test_pipeline))
|
| 110 |
+
# test_evaluator = dict(
|
| 111 |
+
# type='CityScapesMetric',
|
| 112 |
+
# format_only=True,
|
| 113 |
+
# outfile_prefix='./work_dirs/cityscapes_metric/test')
|
mmdet_code/SR-TOD/configs/_base_/datasets/coco_caption.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# data settings
|
| 2 |
+
|
| 3 |
+
dataset_type = 'CocoCaptionDataset'
|
| 4 |
+
data_root = 'data/coco/'
|
| 5 |
+
|
| 6 |
+
# Example to use different file client
|
| 7 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 8 |
+
# automatically infer from prefix (not support LMDB and Memcache yet)
|
| 9 |
+
|
| 10 |
+
# data_root = 's3://openmmlab/datasets/detection/coco/'
|
| 11 |
+
|
| 12 |
+
# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
|
| 13 |
+
# backend_args = dict(
|
| 14 |
+
# backend='petrel',
|
| 15 |
+
# path_mapping=dict({
|
| 16 |
+
# './data/': 's3://openmmlab/datasets/detection/',
|
| 17 |
+
# 'data/': 's3://openmmlab/datasets/detection/'
|
| 18 |
+
# }))
|
| 19 |
+
backend_args = None
|
| 20 |
+
|
| 21 |
+
test_pipeline = [
|
| 22 |
+
dict(
|
| 23 |
+
type='LoadImageFromFile',
|
| 24 |
+
imdecode_backend='pillow',
|
| 25 |
+
backend_args=backend_args),
|
| 26 |
+
dict(
|
| 27 |
+
type='Resize',
|
| 28 |
+
scale=(224, 224),
|
| 29 |
+
interpolation='bicubic',
|
| 30 |
+
backend='pillow'),
|
| 31 |
+
dict(type='PackInputs', meta_keys=['image_id']),
|
| 32 |
+
]
|
| 33 |
+
|
| 34 |
+
# ann_file download from
|
| 35 |
+
# train dataset: https://storage.googleapis.com/sfr-vision-language-research/datasets/coco_karpathy_train.json # noqa
|
| 36 |
+
# val dataset: https://storage.googleapis.com/sfr-vision-language-research/datasets/coco_karpathy_val.json # noqa
|
| 37 |
+
# test dataset: https://storage.googleapis.com/sfr-vision-language-research/datasets/coco_karpathy_test.json # noqa
|
| 38 |
+
# val evaluator: https://storage.googleapis.com/sfr-vision-language-research/datasets/coco_karpathy_val_gt.json # noqa
|
| 39 |
+
# test evaluator: https://storage.googleapis.com/sfr-vision-language-research/datasets/coco_karpathy_test_gt.json # noqa
|
| 40 |
+
val_dataloader = dict(
|
| 41 |
+
batch_size=1,
|
| 42 |
+
num_workers=2,
|
| 43 |
+
persistent_workers=True,
|
| 44 |
+
drop_last=False,
|
| 45 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 46 |
+
dataset=dict(
|
| 47 |
+
type=dataset_type,
|
| 48 |
+
data_root=data_root,
|
| 49 |
+
ann_file='annotations/coco_karpathy_val.json',
|
| 50 |
+
pipeline=test_pipeline,
|
| 51 |
+
))
|
| 52 |
+
|
| 53 |
+
val_evaluator = dict(
|
| 54 |
+
type='COCOCaptionMetric',
|
| 55 |
+
ann_file=data_root + 'annotations/coco_karpathy_val_gt.json',
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
# # If you want standard test, please manually configure the test dataset
|
| 59 |
+
test_dataloader = val_dataloader
|
| 60 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/coco_detection_aitod.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'AITODDataset'
|
| 3 |
+
data_root = '/root/nas-resource-linkdata/AI-TOD/'
|
| 4 |
+
|
| 5 |
+
# Example to use different file client
|
| 6 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 7 |
+
# automatically infer from prefix (not support LMDB and Memcache yet)
|
| 8 |
+
|
| 9 |
+
# data_root = 's3://openmmlab/datasets/detection/coco/'
|
| 10 |
+
|
| 11 |
+
# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
|
| 12 |
+
# backend_args = dict(
|
| 13 |
+
# backend='petrel',
|
| 14 |
+
# path_mapping=dict({
|
| 15 |
+
# './data/': 's3://openmmlab/datasets/detection/',
|
| 16 |
+
# 'data/': 's3://openmmlab/datasets/detection/'
|
| 17 |
+
# }))
|
| 18 |
+
backend_args = None
|
| 19 |
+
|
| 20 |
+
train_pipeline = [
|
| 21 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 22 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 23 |
+
dict(type='Resize', scale=(800, 800), keep_ratio=True),
|
| 24 |
+
dict(type='RandomFlip', prob=0.5),
|
| 25 |
+
dict(type='PackDetInputs')
|
| 26 |
+
]
|
| 27 |
+
test_pipeline = [
|
| 28 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 29 |
+
dict(type='Resize', scale=(800, 800), keep_ratio=True),
|
| 30 |
+
# If you don't have a gt annotation, delete the pipeline
|
| 31 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 32 |
+
dict(
|
| 33 |
+
type='PackDetInputs',
|
| 34 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 35 |
+
'scale_factor'))
|
| 36 |
+
]
|
| 37 |
+
train_dataloader = dict(
|
| 38 |
+
batch_size=2,
|
| 39 |
+
num_workers=2,
|
| 40 |
+
persistent_workers=True,
|
| 41 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 42 |
+
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
| 43 |
+
dataset=dict(
|
| 44 |
+
type=dataset_type,
|
| 45 |
+
data_root=data_root,
|
| 46 |
+
ann_file=data_root + 'annotations/aitod_trainval_v1.json',
|
| 47 |
+
data_prefix=dict(img='trainval/images/'),
|
| 48 |
+
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
| 49 |
+
pipeline=train_pipeline,
|
| 50 |
+
backend_args=backend_args))
|
| 51 |
+
val_dataloader = dict(
|
| 52 |
+
batch_size=1,
|
| 53 |
+
num_workers=2,
|
| 54 |
+
persistent_workers=True,
|
| 55 |
+
drop_last=False,
|
| 56 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 57 |
+
dataset=dict(
|
| 58 |
+
type=dataset_type,
|
| 59 |
+
data_root=data_root,
|
| 60 |
+
ann_file=data_root + 'annotations/aitod_test_v1.json',
|
| 61 |
+
data_prefix=dict(img='test/images/'),
|
| 62 |
+
test_mode=True,
|
| 63 |
+
pipeline=test_pipeline,
|
| 64 |
+
backend_args=backend_args))
|
| 65 |
+
test_dataloader = val_dataloader
|
| 66 |
+
|
| 67 |
+
val_evaluator = dict(
|
| 68 |
+
#type='CocoMetric',
|
| 69 |
+
type='AITODMetric',
|
| 70 |
+
ann_file=data_root + 'annotations/aitod_test_v1.json',
|
| 71 |
+
metric='bbox',
|
| 72 |
+
format_only=False,
|
| 73 |
+
backend_args=backend_args)
|
| 74 |
+
test_evaluator = val_evaluator
|
| 75 |
+
|
| 76 |
+
# inference on test dataset and
|
| 77 |
+
# format the output results for submission.
|
| 78 |
+
# test_dataloader = dict(
|
| 79 |
+
# batch_size=1,
|
| 80 |
+
# num_workers=2,
|
| 81 |
+
# persistent_workers=True,
|
| 82 |
+
# drop_last=False,
|
| 83 |
+
# sampler=dict(type='DefaultSampler', shuffle=False),
|
| 84 |
+
# dataset=dict(
|
| 85 |
+
# type=dataset_type,
|
| 86 |
+
# data_root=data_root,
|
| 87 |
+
# ann_file=data_root + 'annotations/image_info_test-dev2017.json',
|
| 88 |
+
# data_prefix=dict(img='test2017/'),
|
| 89 |
+
# test_mode=True,
|
| 90 |
+
# pipeline=test_pipeline))
|
| 91 |
+
# test_evaluator = dict(
|
| 92 |
+
# type='CocoMetric',
|
| 93 |
+
# metric='bbox',
|
| 94 |
+
# format_only=True,
|
| 95 |
+
# ann_file=data_root + 'annotations/image_info_test-dev2017.json',
|
| 96 |
+
# outfile_prefix='./work_dirs/coco_detection/test')
|
mmdet_code/SR-TOD/configs/_base_/datasets/coco_detection_dota.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'DOTADataset'
|
| 3 |
+
data_root = "/root/nas-resource-tju/Dataset/DOTA/DOTA_split/"
|
| 4 |
+
|
| 5 |
+
# Example to use different file client
|
| 6 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 7 |
+
# automatically infer from prefix (not support LMDB and Memcache yet)
|
| 8 |
+
|
| 9 |
+
# data_root = 's3://openmmlab/datasets/detection/coco/'
|
| 10 |
+
|
| 11 |
+
# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
|
| 12 |
+
# backend_args = dict(
|
| 13 |
+
# backend='petrel',
|
| 14 |
+
# path_mapping=dict({
|
| 15 |
+
# './data/': 's3://openmmlab/datasets/detection/',
|
| 16 |
+
# 'data/': 's3://openmmlab/datasets/detection/'
|
| 17 |
+
# }))
|
| 18 |
+
backend_args = None
|
| 19 |
+
|
| 20 |
+
train_pipeline = [
|
| 21 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 22 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 23 |
+
dict(type='Resize', scale=(1024, 1024), keep_ratio=True),
|
| 24 |
+
dict(type='RandomFlip', prob=0.5),
|
| 25 |
+
dict(type='PackDetInputs')
|
| 26 |
+
]
|
| 27 |
+
test_pipeline = [
|
| 28 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 29 |
+
dict(type='Resize', scale=(1024, 1024), keep_ratio=True),
|
| 30 |
+
# If you don't have a gt annotation, delete the pipeline
|
| 31 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 32 |
+
dict(
|
| 33 |
+
type='PackDetInputs',
|
| 34 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 35 |
+
'scale_factor'))
|
| 36 |
+
]
|
| 37 |
+
train_dataloader = dict(
|
| 38 |
+
batch_size=2,
|
| 39 |
+
num_workers=2,
|
| 40 |
+
persistent_workers=True,
|
| 41 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 42 |
+
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
| 43 |
+
dataset=dict(
|
| 44 |
+
type=dataset_type,
|
| 45 |
+
data_root=data_root,
|
| 46 |
+
ann_file=data_root + 'train/DOTA_train1024.json',
|
| 47 |
+
data_prefix=dict(img='train/images/'),
|
| 48 |
+
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
| 49 |
+
pipeline=train_pipeline,
|
| 50 |
+
backend_args=backend_args))
|
| 51 |
+
val_dataloader = dict(
|
| 52 |
+
batch_size=1,
|
| 53 |
+
num_workers=2,
|
| 54 |
+
persistent_workers=True,
|
| 55 |
+
drop_last=False,
|
| 56 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 57 |
+
dataset=dict(
|
| 58 |
+
type=dataset_type,
|
| 59 |
+
data_root=data_root,
|
| 60 |
+
ann_file=data_root + 'val/DOTA_val1024.json',
|
| 61 |
+
data_prefix=dict(img='val/images/'),
|
| 62 |
+
test_mode=True,
|
| 63 |
+
pipeline=test_pipeline,
|
| 64 |
+
backend_args=backend_args))
|
| 65 |
+
test_dataloader = val_dataloader
|
| 66 |
+
|
| 67 |
+
val_evaluator = dict(
|
| 68 |
+
#type='CocoMetric',
|
| 69 |
+
type='AITODMetric',
|
| 70 |
+
ann_file=data_root + 'val/DOTA_val1024.json',
|
| 71 |
+
metric='bbox',
|
| 72 |
+
format_only=False,
|
| 73 |
+
backend_args=backend_args)
|
| 74 |
+
test_evaluator = val_evaluator
|
| 75 |
+
|
| 76 |
+
# inference on test dataset and
|
| 77 |
+
# format the output results for submission.
|
| 78 |
+
# test_dataloader = dict(
|
| 79 |
+
# batch_size=1,
|
| 80 |
+
# num_workers=2,
|
| 81 |
+
# persistent_workers=True,
|
| 82 |
+
# drop_last=False,
|
| 83 |
+
# sampler=dict(type='DefaultSampler', shuffle=False),
|
| 84 |
+
# dataset=dict(
|
| 85 |
+
# type=dataset_type,
|
| 86 |
+
# data_root=data_root,
|
| 87 |
+
# ann_file=data_root + 'annotations/image_info_test-dev2017.json',
|
| 88 |
+
# data_prefix=dict(img='test2017/'),
|
| 89 |
+
# test_mode=True,
|
| 90 |
+
# pipeline=test_pipeline))
|
| 91 |
+
# test_evaluator = dict(
|
| 92 |
+
# type='CocoMetric',
|
| 93 |
+
# metric='bbox',
|
| 94 |
+
# format_only=True,
|
| 95 |
+
# ann_file=data_root + 'annotations/image_info_test-dev2017.json',
|
| 96 |
+
# outfile_prefix='./work_dirs/coco_detection/test')
|
mmdet_code/SR-TOD/configs/_base_/datasets/coco_detection_drones.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'DronesDataset'
|
| 3 |
+
data_root = '/root/nas-public-linkdata/dataset/Drones/'
|
| 4 |
+
|
| 5 |
+
# Example to use different file client
|
| 6 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 7 |
+
# automatically infer from prefix (not support LMDB and Memcache yet)
|
| 8 |
+
|
| 9 |
+
# data_root = 's3://openmmlab/datasets/detection/coco/'
|
| 10 |
+
|
| 11 |
+
# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
|
| 12 |
+
# backend_args = dict(
|
| 13 |
+
# backend='petrel',
|
| 14 |
+
# path_mapping=dict({
|
| 15 |
+
# './data/': 's3://openmmlab/datasets/detection/',
|
| 16 |
+
# 'data/': 's3://openmmlab/datasets/detection/'
|
| 17 |
+
# }))
|
| 18 |
+
backend_args = None
|
| 19 |
+
|
| 20 |
+
train_pipeline = [
|
| 21 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 22 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 23 |
+
dict(type='Resize', scale=(1920, 1080), keep_ratio=True),
|
| 24 |
+
dict(type='RandomFlip', prob=0.5),
|
| 25 |
+
dict(type='PackDetInputs')
|
| 26 |
+
]
|
| 27 |
+
test_pipeline = [
|
| 28 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 29 |
+
dict(type='Resize', scale=(1920, 1080), keep_ratio=True),
|
| 30 |
+
# If you don't have a gt annotation, delete the pipeline
|
| 31 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 32 |
+
dict(
|
| 33 |
+
type='PackDetInputs',
|
| 34 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 35 |
+
'scale_factor'))
|
| 36 |
+
]
|
| 37 |
+
train_dataloader = dict(
|
| 38 |
+
batch_size=2,
|
| 39 |
+
num_workers=2,
|
| 40 |
+
persistent_workers=True,
|
| 41 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 42 |
+
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
| 43 |
+
dataset=dict(
|
| 44 |
+
type=dataset_type,
|
| 45 |
+
data_root=data_root,
|
| 46 |
+
ann_file=data_root + 'train/train.json',
|
| 47 |
+
data_prefix=dict(img='train/JPEGImages/'),
|
| 48 |
+
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
| 49 |
+
pipeline=train_pipeline,
|
| 50 |
+
backend_args=backend_args))
|
| 51 |
+
val_dataloader = dict(
|
| 52 |
+
batch_size=1,
|
| 53 |
+
num_workers=2,
|
| 54 |
+
persistent_workers=True,
|
| 55 |
+
drop_last=False,
|
| 56 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 57 |
+
dataset=dict(
|
| 58 |
+
type=dataset_type,
|
| 59 |
+
data_root=data_root,
|
| 60 |
+
ann_file=data_root + 'test/test.json',
|
| 61 |
+
data_prefix=dict(img='test/JPEGImages/'),
|
| 62 |
+
test_mode=True,
|
| 63 |
+
pipeline=test_pipeline,
|
| 64 |
+
backend_args=backend_args))
|
| 65 |
+
test_dataloader = val_dataloader
|
| 66 |
+
|
| 67 |
+
val_evaluator = dict(
|
| 68 |
+
#type='CocoMetric',
|
| 69 |
+
type='AITODMetric',
|
| 70 |
+
ann_file=data_root + 'test/test.json',
|
| 71 |
+
metric='bbox',
|
| 72 |
+
format_only=False,
|
| 73 |
+
backend_args=backend_args)
|
| 74 |
+
test_evaluator = val_evaluator
|
| 75 |
+
|
| 76 |
+
# inference on test dataset and
|
| 77 |
+
# format the output results for submission.
|
| 78 |
+
# test_dataloader = dict(
|
| 79 |
+
# batch_size=1,
|
| 80 |
+
# num_workers=2,
|
| 81 |
+
# persistent_workers=True,
|
| 82 |
+
# drop_last=False,
|
| 83 |
+
# sampler=dict(type='DefaultSampler', shuffle=False),
|
| 84 |
+
# dataset=dict(
|
| 85 |
+
# type=dataset_type,
|
| 86 |
+
# data_root=data_root,
|
| 87 |
+
# ann_file=data_root + 'annotations/image_info_test-dev2017.json',
|
| 88 |
+
# data_prefix=dict(img='test2017/'),
|
| 89 |
+
# test_mode=True,
|
| 90 |
+
# pipeline=test_pipeline))
|
| 91 |
+
# test_evaluator = dict(
|
| 92 |
+
# type='CocoMetric',
|
| 93 |
+
# metric='bbox',
|
| 94 |
+
# format_only=True,
|
| 95 |
+
# ann_file=data_root + 'annotations/image_info_test-dev2017.json',
|
| 96 |
+
# outfile_prefix='./work_dirs/coco_detection/test')
|
mmdet_code/SR-TOD/configs/_base_/datasets/coco_detection_visdrone.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'VisDroneDataset'
|
| 3 |
+
data_root = '/root/nas-resource-linkdata/VisDrone-DET2019/'
|
| 4 |
+
|
| 5 |
+
# Example to use different file client
|
| 6 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 7 |
+
# automatically infer from prefix (not support LMDB and Memcache yet)
|
| 8 |
+
|
| 9 |
+
# data_root = 's3://openmmlab/datasets/detection/coco/'
|
| 10 |
+
|
| 11 |
+
# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
|
| 12 |
+
# backend_args = dict(
|
| 13 |
+
# backend='petrel',
|
| 14 |
+
# path_mapping=dict({
|
| 15 |
+
# './data/': 's3://openmmlab/datasets/detection/',
|
| 16 |
+
# 'data/': 's3://openmmlab/datasets/detection/'
|
| 17 |
+
# }))
|
| 18 |
+
backend_args = None
|
| 19 |
+
|
| 20 |
+
train_pipeline = [
|
| 21 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 22 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 23 |
+
dict(type='Resize', scale=(1280, 1280), keep_ratio=True),
|
| 24 |
+
dict(type='RandomFlip', prob=0.5),
|
| 25 |
+
dict(type='PackDetInputs')
|
| 26 |
+
]
|
| 27 |
+
test_pipeline = [
|
| 28 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 29 |
+
dict(type='Resize', scale=(1280, 1280), keep_ratio=True),
|
| 30 |
+
# If you don't have a gt annotation, delete the pipeline
|
| 31 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 32 |
+
dict(
|
| 33 |
+
type='PackDetInputs',
|
| 34 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 35 |
+
'scale_factor'))
|
| 36 |
+
]
|
| 37 |
+
train_dataloader = dict(
|
| 38 |
+
batch_size=2,
|
| 39 |
+
num_workers=2,
|
| 40 |
+
persistent_workers=True,
|
| 41 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 42 |
+
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
| 43 |
+
dataset=dict(
|
| 44 |
+
type=dataset_type,
|
| 45 |
+
data_root=data_root,
|
| 46 |
+
ann_file=data_root + 'VisDrone2019-DET-train/visdrone_train_coco.json',
|
| 47 |
+
data_prefix=dict(img='VisDrone2019-DET-train/images/'),
|
| 48 |
+
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
| 49 |
+
pipeline=train_pipeline,
|
| 50 |
+
backend_args=backend_args))
|
| 51 |
+
val_dataloader = dict(
|
| 52 |
+
batch_size=1,
|
| 53 |
+
num_workers=2,
|
| 54 |
+
persistent_workers=True,
|
| 55 |
+
drop_last=False,
|
| 56 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 57 |
+
dataset=dict(
|
| 58 |
+
type=dataset_type,
|
| 59 |
+
data_root=data_root,
|
| 60 |
+
ann_file=data_root + 'VisDrone2019-DET-val/visdrone_val_coco.json',
|
| 61 |
+
data_prefix=dict(img='VisDrone2019-DET-val/images/'),
|
| 62 |
+
test_mode=True,
|
| 63 |
+
pipeline=test_pipeline,
|
| 64 |
+
backend_args=backend_args))
|
| 65 |
+
test_dataloader = val_dataloader
|
| 66 |
+
|
| 67 |
+
val_evaluator = dict(
|
| 68 |
+
#type='CocoMetric',
|
| 69 |
+
type='AITODMetric',
|
| 70 |
+
ann_file=data_root + 'VisDrone2019-DET-val/visdrone_val_coco.json',
|
| 71 |
+
metric='bbox',
|
| 72 |
+
format_only=False,
|
| 73 |
+
backend_args=backend_args)
|
| 74 |
+
test_evaluator = val_evaluator
|
| 75 |
+
|
| 76 |
+
# inference on test dataset and
|
| 77 |
+
# format the output results for submission.
|
| 78 |
+
# test_dataloader = dict(
|
| 79 |
+
# batch_size=1,
|
| 80 |
+
# num_workers=2,
|
| 81 |
+
# persistent_workers=True,
|
| 82 |
+
# drop_last=False,
|
| 83 |
+
# sampler=dict(type='DefaultSampler', shuffle=False),
|
| 84 |
+
# dataset=dict(
|
| 85 |
+
# type=dataset_type,
|
| 86 |
+
# data_root=data_root,
|
| 87 |
+
# ann_file=data_root + 'annotations/image_info_test-dev2017.json',
|
| 88 |
+
# data_prefix=dict(img='test2017/'),
|
| 89 |
+
# test_mode=True,
|
| 90 |
+
# pipeline=test_pipeline))
|
| 91 |
+
# test_evaluator = dict(
|
| 92 |
+
# type='CocoMetric',
|
| 93 |
+
# metric='bbox',
|
| 94 |
+
# format_only=True,
|
| 95 |
+
# ann_file=data_root + 'annotations/image_info_test-dev2017.json',
|
| 96 |
+
# outfile_prefix='./work_dirs/coco_detection/test')
|
mmdet_code/SR-TOD/configs/_base_/datasets/coco_instance.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'CocoDataset'
|
| 3 |
+
data_root = 'data/coco/'
|
| 4 |
+
|
| 5 |
+
# Example to use different file client
|
| 6 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 7 |
+
# automatically infer from prefix (not support LMDB and Memcache yet)
|
| 8 |
+
|
| 9 |
+
# data_root = 's3://openmmlab/datasets/detection/coco/'
|
| 10 |
+
|
| 11 |
+
# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
|
| 12 |
+
# backend_args = dict(
|
| 13 |
+
# backend='petrel',
|
| 14 |
+
# path_mapping=dict({
|
| 15 |
+
# './data/': 's3://openmmlab/datasets/detection/',
|
| 16 |
+
# 'data/': 's3://openmmlab/datasets/detection/'
|
| 17 |
+
# }))
|
| 18 |
+
backend_args = None
|
| 19 |
+
|
| 20 |
+
train_pipeline = [
|
| 21 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 22 |
+
dict(type='LoadAnnotations', with_bbox=True, with_mask=True),
|
| 23 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
| 24 |
+
dict(type='RandomFlip', prob=0.5),
|
| 25 |
+
dict(type='PackDetInputs')
|
| 26 |
+
]
|
| 27 |
+
test_pipeline = [
|
| 28 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 29 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
| 30 |
+
# If you don't have a gt annotation, delete the pipeline
|
| 31 |
+
dict(type='LoadAnnotations', with_bbox=True, with_mask=True),
|
| 32 |
+
dict(
|
| 33 |
+
type='PackDetInputs',
|
| 34 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 35 |
+
'scale_factor'))
|
| 36 |
+
]
|
| 37 |
+
train_dataloader = dict(
|
| 38 |
+
batch_size=2,
|
| 39 |
+
num_workers=2,
|
| 40 |
+
persistent_workers=True,
|
| 41 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 42 |
+
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
| 43 |
+
dataset=dict(
|
| 44 |
+
type=dataset_type,
|
| 45 |
+
data_root=data_root,
|
| 46 |
+
ann_file='annotations/instances_train2017.json',
|
| 47 |
+
data_prefix=dict(img='train2017/'),
|
| 48 |
+
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
| 49 |
+
pipeline=train_pipeline,
|
| 50 |
+
backend_args=backend_args))
|
| 51 |
+
val_dataloader = dict(
|
| 52 |
+
batch_size=1,
|
| 53 |
+
num_workers=2,
|
| 54 |
+
persistent_workers=True,
|
| 55 |
+
drop_last=False,
|
| 56 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 57 |
+
dataset=dict(
|
| 58 |
+
type=dataset_type,
|
| 59 |
+
data_root=data_root,
|
| 60 |
+
ann_file='annotations/instances_val2017.json',
|
| 61 |
+
data_prefix=dict(img='val2017/'),
|
| 62 |
+
test_mode=True,
|
| 63 |
+
pipeline=test_pipeline,
|
| 64 |
+
backend_args=backend_args))
|
| 65 |
+
test_dataloader = val_dataloader
|
| 66 |
+
|
| 67 |
+
val_evaluator = dict(
|
| 68 |
+
type='CocoMetric',
|
| 69 |
+
ann_file=data_root + 'annotations/instances_val2017.json',
|
| 70 |
+
metric=['bbox', 'segm'],
|
| 71 |
+
format_only=False,
|
| 72 |
+
backend_args=backend_args)
|
| 73 |
+
test_evaluator = val_evaluator
|
| 74 |
+
|
| 75 |
+
# inference on test dataset and
|
| 76 |
+
# format the output results for submission.
|
| 77 |
+
# test_dataloader = dict(
|
| 78 |
+
# batch_size=1,
|
| 79 |
+
# num_workers=2,
|
| 80 |
+
# persistent_workers=True,
|
| 81 |
+
# drop_last=False,
|
| 82 |
+
# sampler=dict(type='DefaultSampler', shuffle=False),
|
| 83 |
+
# dataset=dict(
|
| 84 |
+
# type=dataset_type,
|
| 85 |
+
# data_root=data_root,
|
| 86 |
+
# ann_file=data_root + 'annotations/image_info_test-dev2017.json',
|
| 87 |
+
# data_prefix=dict(img='test2017/'),
|
| 88 |
+
# test_mode=True,
|
| 89 |
+
# pipeline=test_pipeline))
|
| 90 |
+
# test_evaluator = dict(
|
| 91 |
+
# type='CocoMetric',
|
| 92 |
+
# metric=['bbox', 'segm'],
|
| 93 |
+
# format_only=True,
|
| 94 |
+
# ann_file=data_root + 'annotations/image_info_test-dev2017.json',
|
| 95 |
+
# outfile_prefix='./work_dirs/coco_instance/test')
|
mmdet_code/SR-TOD/configs/_base_/datasets/coco_instance_semantic.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'CocoDataset'
|
| 3 |
+
data_root = 'data/coco/'
|
| 4 |
+
|
| 5 |
+
# Example to use different file client
|
| 6 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 7 |
+
# automatically infer from prefix (not support LMDB and Memcache yet)
|
| 8 |
+
|
| 9 |
+
# data_root = 's3://openmmlab/datasets/detection/coco/'
|
| 10 |
+
|
| 11 |
+
# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
|
| 12 |
+
# backend_args = dict(
|
| 13 |
+
# backend='petrel',
|
| 14 |
+
# path_mapping=dict({
|
| 15 |
+
# './data/': 's3://openmmlab/datasets/detection/',
|
| 16 |
+
# 'data/': 's3://openmmlab/datasets/detection/'
|
| 17 |
+
# }))
|
| 18 |
+
backend_args = None
|
| 19 |
+
|
| 20 |
+
train_pipeline = [
|
| 21 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 22 |
+
dict(
|
| 23 |
+
type='LoadAnnotations', with_bbox=True, with_mask=True, with_seg=True),
|
| 24 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
| 25 |
+
dict(type='RandomFlip', prob=0.5),
|
| 26 |
+
dict(type='PackDetInputs')
|
| 27 |
+
]
|
| 28 |
+
test_pipeline = [
|
| 29 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 30 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
| 31 |
+
# If you don't have a gt annotation, delete the pipeline
|
| 32 |
+
dict(
|
| 33 |
+
type='LoadAnnotations', with_bbox=True, with_mask=True, with_seg=True),
|
| 34 |
+
dict(
|
| 35 |
+
type='PackDetInputs',
|
| 36 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 37 |
+
'scale_factor'))
|
| 38 |
+
]
|
| 39 |
+
|
| 40 |
+
train_dataloader = dict(
|
| 41 |
+
batch_size=2,
|
| 42 |
+
num_workers=2,
|
| 43 |
+
persistent_workers=True,
|
| 44 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 45 |
+
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
| 46 |
+
dataset=dict(
|
| 47 |
+
type=dataset_type,
|
| 48 |
+
data_root=data_root,
|
| 49 |
+
ann_file='annotations/instances_train2017.json',
|
| 50 |
+
data_prefix=dict(img='train2017/', seg='stuffthingmaps/train2017/'),
|
| 51 |
+
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
| 52 |
+
pipeline=train_pipeline,
|
| 53 |
+
backend_args=backend_args))
|
| 54 |
+
|
| 55 |
+
val_dataloader = dict(
|
| 56 |
+
batch_size=1,
|
| 57 |
+
num_workers=2,
|
| 58 |
+
persistent_workers=True,
|
| 59 |
+
drop_last=False,
|
| 60 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 61 |
+
dataset=dict(
|
| 62 |
+
type=dataset_type,
|
| 63 |
+
data_root=data_root,
|
| 64 |
+
ann_file='annotations/instances_val2017.json',
|
| 65 |
+
data_prefix=dict(img='val2017/'),
|
| 66 |
+
test_mode=True,
|
| 67 |
+
pipeline=test_pipeline,
|
| 68 |
+
backend_args=backend_args))
|
| 69 |
+
|
| 70 |
+
test_dataloader = val_dataloader
|
| 71 |
+
|
| 72 |
+
val_evaluator = dict(
|
| 73 |
+
type='CocoMetric',
|
| 74 |
+
ann_file=data_root + 'annotations/instances_val2017.json',
|
| 75 |
+
metric=['bbox', 'segm'],
|
| 76 |
+
format_only=False,
|
| 77 |
+
backend_args=backend_args)
|
| 78 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/coco_panoptic.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'CocoPanopticDataset'
|
| 3 |
+
data_root = 'data/coco/'
|
| 4 |
+
|
| 5 |
+
# Example to use different file client
|
| 6 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 7 |
+
# automatically infer from prefix (not support LMDB and Memcache yet)
|
| 8 |
+
|
| 9 |
+
# data_root = 's3://openmmlab/datasets/detection/coco/'
|
| 10 |
+
|
| 11 |
+
# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
|
| 12 |
+
# backend_args = dict(
|
| 13 |
+
# backend='petrel',
|
| 14 |
+
# path_mapping=dict({
|
| 15 |
+
# './data/': 's3://openmmlab/datasets/detection/',
|
| 16 |
+
# 'data/': 's3://openmmlab/datasets/detection/'
|
| 17 |
+
# }))
|
| 18 |
+
backend_args = None
|
| 19 |
+
|
| 20 |
+
train_pipeline = [
|
| 21 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 22 |
+
dict(type='LoadPanopticAnnotations', backend_args=backend_args),
|
| 23 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
| 24 |
+
dict(type='RandomFlip', prob=0.5),
|
| 25 |
+
dict(type='PackDetInputs')
|
| 26 |
+
]
|
| 27 |
+
test_pipeline = [
|
| 28 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 29 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
| 30 |
+
dict(type='LoadPanopticAnnotations', backend_args=backend_args),
|
| 31 |
+
dict(
|
| 32 |
+
type='PackDetInputs',
|
| 33 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 34 |
+
'scale_factor'))
|
| 35 |
+
]
|
| 36 |
+
|
| 37 |
+
train_dataloader = dict(
|
| 38 |
+
batch_size=2,
|
| 39 |
+
num_workers=2,
|
| 40 |
+
persistent_workers=True,
|
| 41 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 42 |
+
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
| 43 |
+
dataset=dict(
|
| 44 |
+
type=dataset_type,
|
| 45 |
+
data_root=data_root,
|
| 46 |
+
ann_file='annotations/panoptic_train2017.json',
|
| 47 |
+
data_prefix=dict(
|
| 48 |
+
img='train2017/', seg='annotations/panoptic_train2017/'),
|
| 49 |
+
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
| 50 |
+
pipeline=train_pipeline,
|
| 51 |
+
backend_args=backend_args))
|
| 52 |
+
val_dataloader = dict(
|
| 53 |
+
batch_size=1,
|
| 54 |
+
num_workers=2,
|
| 55 |
+
persistent_workers=True,
|
| 56 |
+
drop_last=False,
|
| 57 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 58 |
+
dataset=dict(
|
| 59 |
+
type=dataset_type,
|
| 60 |
+
data_root=data_root,
|
| 61 |
+
ann_file='annotations/panoptic_val2017.json',
|
| 62 |
+
data_prefix=dict(img='val2017/', seg='annotations/panoptic_val2017/'),
|
| 63 |
+
test_mode=True,
|
| 64 |
+
pipeline=test_pipeline,
|
| 65 |
+
backend_args=backend_args))
|
| 66 |
+
test_dataloader = val_dataloader
|
| 67 |
+
|
| 68 |
+
val_evaluator = dict(
|
| 69 |
+
type='CocoPanopticMetric',
|
| 70 |
+
ann_file=data_root + 'annotations/panoptic_val2017.json',
|
| 71 |
+
seg_prefix=data_root + 'annotations/panoptic_val2017/',
|
| 72 |
+
backend_args=backend_args)
|
| 73 |
+
test_evaluator = val_evaluator
|
| 74 |
+
|
| 75 |
+
# inference on test dataset and
|
| 76 |
+
# format the output results for submission.
|
| 77 |
+
# test_dataloader = dict(
|
| 78 |
+
# batch_size=1,
|
| 79 |
+
# num_workers=1,
|
| 80 |
+
# persistent_workers=True,
|
| 81 |
+
# drop_last=False,
|
| 82 |
+
# sampler=dict(type='DefaultSampler', shuffle=False),
|
| 83 |
+
# dataset=dict(
|
| 84 |
+
# type=dataset_type,
|
| 85 |
+
# data_root=data_root,
|
| 86 |
+
# ann_file='annotations/panoptic_image_info_test-dev2017.json',
|
| 87 |
+
# data_prefix=dict(img='test2017/'),
|
| 88 |
+
# test_mode=True,
|
| 89 |
+
# pipeline=test_pipeline))
|
| 90 |
+
# test_evaluator = dict(
|
| 91 |
+
# type='CocoPanopticMetric',
|
| 92 |
+
# format_only=True,
|
| 93 |
+
# ann_file=data_root + 'annotations/panoptic_image_info_test-dev2017.json',
|
| 94 |
+
# outfile_prefix='./work_dirs/coco_panoptic/test')
|
mmdet_code/SR-TOD/configs/_base_/datasets/coco_semantic.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'CocoSegDataset'
|
| 3 |
+
data_root = 'data/coco/'
|
| 4 |
+
|
| 5 |
+
# Example to use different file client
|
| 6 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 7 |
+
# automatically infer from prefix (not support LMDB and Memcache yet)
|
| 8 |
+
|
| 9 |
+
# data_root = 's3://openmmlab/datasets/detection/coco/'
|
| 10 |
+
|
| 11 |
+
# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
|
| 12 |
+
# backend_args = dict(
|
| 13 |
+
# backend='petrel',
|
| 14 |
+
# path_mapping=dict({
|
| 15 |
+
# './data/': 's3://openmmlab/datasets/detection/',
|
| 16 |
+
# 'data/': 's3://openmmlab/datasets/detection/'
|
| 17 |
+
# }))
|
| 18 |
+
backend_args = None
|
| 19 |
+
|
| 20 |
+
train_pipeline = [
|
| 21 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 22 |
+
dict(
|
| 23 |
+
type='LoadAnnotations',
|
| 24 |
+
with_bbox=False,
|
| 25 |
+
with_label=False,
|
| 26 |
+
with_seg=True),
|
| 27 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
| 28 |
+
dict(type='RandomFlip', prob=0.5),
|
| 29 |
+
dict(type='PackDetInputs')
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
test_pipeline = [
|
| 33 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 34 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
| 35 |
+
dict(
|
| 36 |
+
type='LoadAnnotations',
|
| 37 |
+
with_bbox=False,
|
| 38 |
+
with_label=False,
|
| 39 |
+
with_seg=True),
|
| 40 |
+
dict(
|
| 41 |
+
type='PackDetInputs',
|
| 42 |
+
meta_keys=('img_path', 'ori_shape', 'img_shape', 'scale_factor'))
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
# For stuffthingmaps_semseg, please refer to
|
| 46 |
+
# `docs/en/user_guides/dataset_prepare.md`
|
| 47 |
+
train_dataloader = dict(
|
| 48 |
+
batch_size=2,
|
| 49 |
+
num_workers=2,
|
| 50 |
+
persistent_workers=True,
|
| 51 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 52 |
+
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
| 53 |
+
dataset=dict(
|
| 54 |
+
type=dataset_type,
|
| 55 |
+
data_root=data_root,
|
| 56 |
+
data_prefix=dict(
|
| 57 |
+
img_path='train2017/',
|
| 58 |
+
seg_map_path='stuffthingmaps_semseg/train2017/'),
|
| 59 |
+
pipeline=train_pipeline))
|
| 60 |
+
|
| 61 |
+
val_dataloader = dict(
|
| 62 |
+
batch_size=1,
|
| 63 |
+
num_workers=2,
|
| 64 |
+
persistent_workers=True,
|
| 65 |
+
drop_last=False,
|
| 66 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 67 |
+
dataset=dict(
|
| 68 |
+
type=dataset_type,
|
| 69 |
+
data_root=data_root,
|
| 70 |
+
data_prefix=dict(
|
| 71 |
+
img_path='val2017/',
|
| 72 |
+
seg_map_path='stuffthingmaps_semseg/val2017/'),
|
| 73 |
+
pipeline=test_pipeline))
|
| 74 |
+
|
| 75 |
+
test_dataloader = val_dataloader
|
| 76 |
+
|
| 77 |
+
val_evaluator = dict(type='SemSegMetric', iou_metrics=['mIoU'])
|
| 78 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/deepfashion.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'DeepFashionDataset'
|
| 3 |
+
data_root = 'data/DeepFashion/In-shop/'
|
| 4 |
+
|
| 5 |
+
# Example to use different file client
|
| 6 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 7 |
+
# automatically infer from prefix (not support LMDB and Memcache yet)
|
| 8 |
+
|
| 9 |
+
# data_root = 's3://openmmlab/datasets/detection/coco/'
|
| 10 |
+
|
| 11 |
+
# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
|
| 12 |
+
# backend_args = dict(
|
| 13 |
+
# backend='petrel',
|
| 14 |
+
# path_mapping=dict({
|
| 15 |
+
# './data/': 's3://openmmlab/datasets/detection/',
|
| 16 |
+
# 'data/': 's3://openmmlab/datasets/detection/'
|
| 17 |
+
# }))
|
| 18 |
+
backend_args = None
|
| 19 |
+
|
| 20 |
+
train_pipeline = [
|
| 21 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 22 |
+
dict(type='LoadAnnotations', with_bbox=True, with_mask=True),
|
| 23 |
+
dict(type='Resize', scale=(750, 1101), keep_ratio=True),
|
| 24 |
+
dict(type='RandomFlip', prob=0.5),
|
| 25 |
+
dict(type='PackDetInputs')
|
| 26 |
+
]
|
| 27 |
+
test_pipeline = [
|
| 28 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 29 |
+
dict(type='Resize', scale=(750, 1101), keep_ratio=True),
|
| 30 |
+
dict(type='LoadAnnotations', with_bbox=True, with_mask=True),
|
| 31 |
+
dict(
|
| 32 |
+
type='PackDetInputs',
|
| 33 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 34 |
+
'scale_factor'))
|
| 35 |
+
]
|
| 36 |
+
train_dataloader = dict(
|
| 37 |
+
batch_size=2,
|
| 38 |
+
num_workers=2,
|
| 39 |
+
persistent_workers=True,
|
| 40 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 41 |
+
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
| 42 |
+
dataset=dict(
|
| 43 |
+
type='RepeatDataset',
|
| 44 |
+
times=2,
|
| 45 |
+
dataset=dict(
|
| 46 |
+
type=dataset_type,
|
| 47 |
+
data_root=data_root,
|
| 48 |
+
ann_file='Anno/segmentation/DeepFashion_segmentation_train.json',
|
| 49 |
+
data_prefix=dict(img='Img/'),
|
| 50 |
+
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
| 51 |
+
pipeline=train_pipeline,
|
| 52 |
+
backend_args=backend_args)))
|
| 53 |
+
val_dataloader = dict(
|
| 54 |
+
batch_size=1,
|
| 55 |
+
num_workers=2,
|
| 56 |
+
persistent_workers=True,
|
| 57 |
+
drop_last=False,
|
| 58 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 59 |
+
dataset=dict(
|
| 60 |
+
type=dataset_type,
|
| 61 |
+
data_root=data_root,
|
| 62 |
+
ann_file='Anno/segmentation/DeepFashion_segmentation_query.json',
|
| 63 |
+
data_prefix=dict(img='Img/'),
|
| 64 |
+
test_mode=True,
|
| 65 |
+
pipeline=test_pipeline,
|
| 66 |
+
backend_args=backend_args))
|
| 67 |
+
test_dataloader = dict(
|
| 68 |
+
batch_size=1,
|
| 69 |
+
num_workers=2,
|
| 70 |
+
persistent_workers=True,
|
| 71 |
+
drop_last=False,
|
| 72 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 73 |
+
dataset=dict(
|
| 74 |
+
type=dataset_type,
|
| 75 |
+
data_root=data_root,
|
| 76 |
+
ann_file='Anno/segmentation/DeepFashion_segmentation_gallery.json',
|
| 77 |
+
data_prefix=dict(img='Img/'),
|
| 78 |
+
test_mode=True,
|
| 79 |
+
pipeline=test_pipeline,
|
| 80 |
+
backend_args=backend_args))
|
| 81 |
+
|
| 82 |
+
val_evaluator = dict(
|
| 83 |
+
type='CocoMetric',
|
| 84 |
+
ann_file=data_root +
|
| 85 |
+
'Anno/segmentation/DeepFashion_segmentation_query.json',
|
| 86 |
+
metric=['bbox', 'segm'],
|
| 87 |
+
format_only=False,
|
| 88 |
+
backend_args=backend_args)
|
| 89 |
+
test_evaluator = dict(
|
| 90 |
+
type='CocoMetric',
|
| 91 |
+
ann_file=data_root +
|
| 92 |
+
'Anno/segmentation/DeepFashion_segmentation_gallery.json',
|
| 93 |
+
metric=['bbox', 'segm'],
|
| 94 |
+
format_only=False,
|
| 95 |
+
backend_args=backend_args)
|
mmdet_code/SR-TOD/configs/_base_/datasets/dsdl.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
dataset_type = 'DSDLDetDataset'
|
| 2 |
+
data_root = 'path to dataset folder'
|
| 3 |
+
train_ann = 'path to train yaml file'
|
| 4 |
+
val_ann = 'path to val yaml file'
|
| 5 |
+
|
| 6 |
+
backend_args = None
|
| 7 |
+
# backend_args = dict(
|
| 8 |
+
# backend='petrel',
|
| 9 |
+
# path_mapping=dict({
|
| 10 |
+
# './data/': "s3://open_data/",
|
| 11 |
+
# 'data/': "s3://open_data/"
|
| 12 |
+
# }))
|
| 13 |
+
|
| 14 |
+
train_pipeline = [
|
| 15 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 16 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 17 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
| 18 |
+
dict(type='RandomFlip', prob=0.5),
|
| 19 |
+
dict(type='PackDetInputs')
|
| 20 |
+
]
|
| 21 |
+
test_pipeline = [
|
| 22 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 23 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
| 24 |
+
# If you don't have a gt annotation, delete the pipeline
|
| 25 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 26 |
+
dict(
|
| 27 |
+
type='PackDetInputs',
|
| 28 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 29 |
+
'scale_factor', 'instances'))
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
train_dataloader = dict(
|
| 33 |
+
batch_size=2,
|
| 34 |
+
num_workers=2,
|
| 35 |
+
persistent_workers=True,
|
| 36 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 37 |
+
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
| 38 |
+
dataset=dict(
|
| 39 |
+
type=dataset_type,
|
| 40 |
+
data_root=data_root,
|
| 41 |
+
ann_file=train_ann,
|
| 42 |
+
filter_cfg=dict(filter_empty_gt=True, min_size=32, bbox_min_size=32),
|
| 43 |
+
pipeline=train_pipeline))
|
| 44 |
+
|
| 45 |
+
val_dataloader = dict(
|
| 46 |
+
batch_size=1,
|
| 47 |
+
num_workers=2,
|
| 48 |
+
persistent_workers=True,
|
| 49 |
+
drop_last=False,
|
| 50 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 51 |
+
dataset=dict(
|
| 52 |
+
type=dataset_type,
|
| 53 |
+
data_root=data_root,
|
| 54 |
+
ann_file=val_ann,
|
| 55 |
+
test_mode=True,
|
| 56 |
+
pipeline=test_pipeline))
|
| 57 |
+
|
| 58 |
+
test_dataloader = val_dataloader
|
| 59 |
+
|
| 60 |
+
val_evaluator = dict(type='CocoMetric', metric='bbox')
|
| 61 |
+
# val_evaluator = dict(type='VOCMetric', metric='mAP', eval_mode='11points')
|
| 62 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/isaid_instance.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'iSAIDDataset'
|
| 3 |
+
data_root = 'data/iSAID/'
|
| 4 |
+
backend_args = None
|
| 5 |
+
|
| 6 |
+
# Please see `projects/iSAID/README.md` for data preparation
|
| 7 |
+
train_pipeline = [
|
| 8 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 9 |
+
dict(type='LoadAnnotations', with_bbox=True, with_mask=True),
|
| 10 |
+
dict(type='Resize', scale=(800, 800), keep_ratio=True),
|
| 11 |
+
dict(type='RandomFlip', prob=0.5),
|
| 12 |
+
dict(type='PackDetInputs')
|
| 13 |
+
]
|
| 14 |
+
test_pipeline = [
|
| 15 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 16 |
+
dict(type='Resize', scale=(800, 800), keep_ratio=True),
|
| 17 |
+
dict(type='LoadAnnotations', with_bbox=True, with_mask=True),
|
| 18 |
+
dict(
|
| 19 |
+
type='PackDetInputs',
|
| 20 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 21 |
+
'scale_factor'))
|
| 22 |
+
]
|
| 23 |
+
train_dataloader = dict(
|
| 24 |
+
batch_size=2,
|
| 25 |
+
num_workers=2,
|
| 26 |
+
persistent_workers=True,
|
| 27 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 28 |
+
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
| 29 |
+
dataset=dict(
|
| 30 |
+
type=dataset_type,
|
| 31 |
+
data_root=data_root,
|
| 32 |
+
ann_file='train/instancesonly_filtered_train.json',
|
| 33 |
+
data_prefix=dict(img='train/images/'),
|
| 34 |
+
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
| 35 |
+
pipeline=train_pipeline,
|
| 36 |
+
backend_args=backend_args))
|
| 37 |
+
val_dataloader = dict(
|
| 38 |
+
batch_size=1,
|
| 39 |
+
num_workers=2,
|
| 40 |
+
persistent_workers=True,
|
| 41 |
+
drop_last=False,
|
| 42 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 43 |
+
dataset=dict(
|
| 44 |
+
type=dataset_type,
|
| 45 |
+
data_root=data_root,
|
| 46 |
+
ann_file='val/instancesonly_filtered_val.json',
|
| 47 |
+
data_prefix=dict(img='val/images/'),
|
| 48 |
+
test_mode=True,
|
| 49 |
+
pipeline=test_pipeline,
|
| 50 |
+
backend_args=backend_args))
|
| 51 |
+
test_dataloader = val_dataloader
|
| 52 |
+
|
| 53 |
+
val_evaluator = dict(
|
| 54 |
+
type='CocoMetric',
|
| 55 |
+
ann_file=data_root + 'val/instancesonly_filtered_val.json',
|
| 56 |
+
metric=['bbox', 'segm'],
|
| 57 |
+
format_only=False,
|
| 58 |
+
backend_args=backend_args)
|
| 59 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/lvis_v0.5_instance.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'LVISV05Dataset'
|
| 3 |
+
data_root = 'data/lvis_v0.5/'
|
| 4 |
+
|
| 5 |
+
# Example to use different file client
|
| 6 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 7 |
+
# automatically infer from prefix (not support LMDB and Memcache yet)
|
| 8 |
+
|
| 9 |
+
# data_root = 's3://openmmlab/datasets/detection/lvis_v0.5/'
|
| 10 |
+
|
| 11 |
+
# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
|
| 12 |
+
# backend_args = dict(
|
| 13 |
+
# backend='petrel',
|
| 14 |
+
# path_mapping=dict({
|
| 15 |
+
# './data/': 's3://openmmlab/datasets/detection/',
|
| 16 |
+
# 'data/': 's3://openmmlab/datasets/detection/'
|
| 17 |
+
# }))
|
| 18 |
+
backend_args = None
|
| 19 |
+
|
| 20 |
+
train_pipeline = [
|
| 21 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 22 |
+
dict(type='LoadAnnotations', with_bbox=True, with_mask=True),
|
| 23 |
+
dict(
|
| 24 |
+
type='RandomChoiceResize',
|
| 25 |
+
scales=[(1333, 640), (1333, 672), (1333, 704), (1333, 736),
|
| 26 |
+
(1333, 768), (1333, 800)],
|
| 27 |
+
keep_ratio=True),
|
| 28 |
+
dict(type='RandomFlip', prob=0.5),
|
| 29 |
+
dict(type='PackDetInputs')
|
| 30 |
+
]
|
| 31 |
+
test_pipeline = [
|
| 32 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 33 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
| 34 |
+
dict(type='LoadAnnotations', with_bbox=True, with_mask=True),
|
| 35 |
+
dict(
|
| 36 |
+
type='PackDetInputs',
|
| 37 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 38 |
+
'scale_factor'))
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
+
train_dataloader = dict(
|
| 42 |
+
batch_size=2,
|
| 43 |
+
num_workers=2,
|
| 44 |
+
persistent_workers=True,
|
| 45 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 46 |
+
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
| 47 |
+
dataset=dict(
|
| 48 |
+
type='ClassBalancedDataset',
|
| 49 |
+
oversample_thr=1e-3,
|
| 50 |
+
dataset=dict(
|
| 51 |
+
type=dataset_type,
|
| 52 |
+
data_root=data_root,
|
| 53 |
+
ann_file='annotations/lvis_v0.5_train.json',
|
| 54 |
+
data_prefix=dict(img='train2017/'),
|
| 55 |
+
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
| 56 |
+
pipeline=train_pipeline,
|
| 57 |
+
backend_args=backend_args)))
|
| 58 |
+
val_dataloader = dict(
|
| 59 |
+
batch_size=1,
|
| 60 |
+
num_workers=2,
|
| 61 |
+
persistent_workers=True,
|
| 62 |
+
drop_last=False,
|
| 63 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 64 |
+
dataset=dict(
|
| 65 |
+
type=dataset_type,
|
| 66 |
+
data_root=data_root,
|
| 67 |
+
ann_file='annotations/lvis_v0.5_val.json',
|
| 68 |
+
data_prefix=dict(img='val2017/'),
|
| 69 |
+
test_mode=True,
|
| 70 |
+
pipeline=test_pipeline,
|
| 71 |
+
backend_args=backend_args))
|
| 72 |
+
test_dataloader = val_dataloader
|
| 73 |
+
|
| 74 |
+
val_evaluator = dict(
|
| 75 |
+
type='LVISMetric',
|
| 76 |
+
ann_file=data_root + 'annotations/lvis_v0.5_val.json',
|
| 77 |
+
metric=['bbox', 'segm'],
|
| 78 |
+
backend_args=backend_args)
|
| 79 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/lvis_v1_instance.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
_base_ = 'lvis_v0.5_instance.py'
|
| 3 |
+
dataset_type = 'LVISV1Dataset'
|
| 4 |
+
data_root = 'data/lvis_v1/'
|
| 5 |
+
|
| 6 |
+
train_dataloader = dict(
|
| 7 |
+
dataset=dict(
|
| 8 |
+
dataset=dict(
|
| 9 |
+
type=dataset_type,
|
| 10 |
+
data_root=data_root,
|
| 11 |
+
ann_file='annotations/lvis_v1_train.json',
|
| 12 |
+
data_prefix=dict(img=''))))
|
| 13 |
+
val_dataloader = dict(
|
| 14 |
+
dataset=dict(
|
| 15 |
+
type=dataset_type,
|
| 16 |
+
data_root=data_root,
|
| 17 |
+
ann_file='annotations/lvis_v1_val.json',
|
| 18 |
+
data_prefix=dict(img='')))
|
| 19 |
+
test_dataloader = val_dataloader
|
| 20 |
+
|
| 21 |
+
val_evaluator = dict(ann_file=data_root + 'annotations/lvis_v1_val.json')
|
| 22 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/mot_challenge.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'MOTChallengeDataset'
|
| 3 |
+
data_root = 'data/MOT17/'
|
| 4 |
+
img_scale = (1088, 1088)
|
| 5 |
+
|
| 6 |
+
backend_args = None
|
| 7 |
+
# data pipeline
|
| 8 |
+
train_pipeline = [
|
| 9 |
+
dict(
|
| 10 |
+
type='UniformRefFrameSample',
|
| 11 |
+
num_ref_imgs=1,
|
| 12 |
+
frame_range=10,
|
| 13 |
+
filter_key_img=True),
|
| 14 |
+
dict(
|
| 15 |
+
type='TransformBroadcaster',
|
| 16 |
+
share_random_params=True,
|
| 17 |
+
transforms=[
|
| 18 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 19 |
+
dict(type='LoadTrackAnnotations'),
|
| 20 |
+
dict(
|
| 21 |
+
type='RandomResize',
|
| 22 |
+
scale=img_scale,
|
| 23 |
+
ratio_range=(0.8, 1.2),
|
| 24 |
+
keep_ratio=True,
|
| 25 |
+
clip_object_border=False),
|
| 26 |
+
dict(type='PhotoMetricDistortion')
|
| 27 |
+
]),
|
| 28 |
+
dict(
|
| 29 |
+
type='TransformBroadcaster',
|
| 30 |
+
# different cropped positions for different frames
|
| 31 |
+
share_random_params=False,
|
| 32 |
+
transforms=[
|
| 33 |
+
dict(
|
| 34 |
+
type='RandomCrop', crop_size=img_scale, bbox_clip_border=False)
|
| 35 |
+
]),
|
| 36 |
+
dict(
|
| 37 |
+
type='TransformBroadcaster',
|
| 38 |
+
share_random_params=True,
|
| 39 |
+
transforms=[
|
| 40 |
+
dict(type='RandomFlip', prob=0.5),
|
| 41 |
+
]),
|
| 42 |
+
dict(type='PackTrackInputs')
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
test_pipeline = [
|
| 46 |
+
dict(
|
| 47 |
+
type='TransformBroadcaster',
|
| 48 |
+
transforms=[
|
| 49 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 50 |
+
dict(type='Resize', scale=img_scale, keep_ratio=True),
|
| 51 |
+
dict(type='LoadTrackAnnotations')
|
| 52 |
+
]),
|
| 53 |
+
dict(type='PackTrackInputs')
|
| 54 |
+
]
|
| 55 |
+
|
| 56 |
+
# dataloader
|
| 57 |
+
train_dataloader = dict(
|
| 58 |
+
batch_size=2,
|
| 59 |
+
num_workers=2,
|
| 60 |
+
persistent_workers=True,
|
| 61 |
+
sampler=dict(type='TrackImgSampler'), # image-based sampling
|
| 62 |
+
dataset=dict(
|
| 63 |
+
type=dataset_type,
|
| 64 |
+
data_root=data_root,
|
| 65 |
+
visibility_thr=-1,
|
| 66 |
+
ann_file='annotations/half-train_cocoformat.json',
|
| 67 |
+
data_prefix=dict(img_path='train'),
|
| 68 |
+
metainfo=dict(classes=('pedestrian', )),
|
| 69 |
+
pipeline=train_pipeline))
|
| 70 |
+
val_dataloader = dict(
|
| 71 |
+
batch_size=1,
|
| 72 |
+
num_workers=2,
|
| 73 |
+
persistent_workers=True,
|
| 74 |
+
# Now we support two ways to test, image_based and video_based
|
| 75 |
+
# if you want to use video_based sampling, you can use as follows
|
| 76 |
+
# sampler=dict(type='DefaultSampler', shuffle=False, round_up=False),
|
| 77 |
+
sampler=dict(type='TrackImgSampler'), # image-based sampling
|
| 78 |
+
dataset=dict(
|
| 79 |
+
type=dataset_type,
|
| 80 |
+
data_root=data_root,
|
| 81 |
+
ann_file='annotations/half-val_cocoformat.json',
|
| 82 |
+
data_prefix=dict(img_path='train'),
|
| 83 |
+
test_mode=True,
|
| 84 |
+
pipeline=test_pipeline))
|
| 85 |
+
test_dataloader = val_dataloader
|
| 86 |
+
|
| 87 |
+
# evaluator
|
| 88 |
+
val_evaluator = dict(
|
| 89 |
+
type='MOTChallengeMetric', metric=['HOTA', 'CLEAR', 'Identity'])
|
| 90 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/mot_challenge_det.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'CocoDataset'
|
| 3 |
+
data_root = 'data/MOT17/'
|
| 4 |
+
|
| 5 |
+
backend_args = None
|
| 6 |
+
train_pipeline = [
|
| 7 |
+
dict(type='LoadImageFromFile', backend_args=backend_args, to_float32=True),
|
| 8 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 9 |
+
dict(
|
| 10 |
+
type='RandomResize',
|
| 11 |
+
scale=(1088, 1088),
|
| 12 |
+
ratio_range=(0.8, 1.2),
|
| 13 |
+
keep_ratio=True,
|
| 14 |
+
clip_object_border=False),
|
| 15 |
+
dict(type='PhotoMetricDistortion'),
|
| 16 |
+
dict(type='RandomCrop', crop_size=(1088, 1088), bbox_clip_border=False),
|
| 17 |
+
dict(type='RandomFlip', prob=0.5),
|
| 18 |
+
dict(type='PackDetInputs')
|
| 19 |
+
]
|
| 20 |
+
|
| 21 |
+
test_pipeline = [
|
| 22 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 23 |
+
dict(type='Resize', scale=(1088, 1088), keep_ratio=True),
|
| 24 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 25 |
+
dict(
|
| 26 |
+
type='PackDetInputs',
|
| 27 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 28 |
+
'scale_factor'))
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
train_dataloader = dict(
|
| 32 |
+
batch_size=2,
|
| 33 |
+
num_workers=2,
|
| 34 |
+
persistent_workers=True,
|
| 35 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 36 |
+
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
| 37 |
+
dataset=dict(
|
| 38 |
+
type=dataset_type,
|
| 39 |
+
data_root=data_root,
|
| 40 |
+
ann_file='annotations/half-train_cocoformat.json',
|
| 41 |
+
data_prefix=dict(img='train/'),
|
| 42 |
+
metainfo=dict(classes=('pedestrian', )),
|
| 43 |
+
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
| 44 |
+
pipeline=train_pipeline))
|
| 45 |
+
val_dataloader = dict(
|
| 46 |
+
batch_size=1,
|
| 47 |
+
num_workers=2,
|
| 48 |
+
persistent_workers=True,
|
| 49 |
+
drop_last=False,
|
| 50 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 51 |
+
dataset=dict(
|
| 52 |
+
type=dataset_type,
|
| 53 |
+
data_root=data_root,
|
| 54 |
+
ann_file='annotations/half-val_cocoformat.json',
|
| 55 |
+
data_prefix=dict(img='train/'),
|
| 56 |
+
metainfo=dict(classes=('pedestrian', )),
|
| 57 |
+
test_mode=True,
|
| 58 |
+
pipeline=test_pipeline))
|
| 59 |
+
test_dataloader = val_dataloader
|
| 60 |
+
|
| 61 |
+
val_evaluator = dict(
|
| 62 |
+
type='CocoMetric',
|
| 63 |
+
ann_file=data_root + 'annotations/half-val_cocoformat.json',
|
| 64 |
+
metric='bbox',
|
| 65 |
+
format_only=False)
|
| 66 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/mot_challenge_reid.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'ReIDDataset'
|
| 3 |
+
data_root = 'data/MOT17/'
|
| 4 |
+
|
| 5 |
+
backend_args = None
|
| 6 |
+
# data pipeline
|
| 7 |
+
train_pipeline = [
|
| 8 |
+
dict(
|
| 9 |
+
type='TransformBroadcaster',
|
| 10 |
+
share_random_params=False,
|
| 11 |
+
transforms=[
|
| 12 |
+
dict(
|
| 13 |
+
type='LoadImageFromFile',
|
| 14 |
+
backend_args=backend_args,
|
| 15 |
+
to_float32=True),
|
| 16 |
+
dict(
|
| 17 |
+
type='Resize',
|
| 18 |
+
scale=(128, 256),
|
| 19 |
+
keep_ratio=False,
|
| 20 |
+
clip_object_border=False),
|
| 21 |
+
dict(type='RandomFlip', prob=0.5, direction='horizontal'),
|
| 22 |
+
]),
|
| 23 |
+
dict(type='PackReIDInputs', meta_keys=('flip', 'flip_direction'))
|
| 24 |
+
]
|
| 25 |
+
test_pipeline = [
|
| 26 |
+
dict(type='LoadImageFromFile', backend_args=backend_args, to_float32=True),
|
| 27 |
+
dict(type='Resize', scale=(128, 256), keep_ratio=False),
|
| 28 |
+
dict(type='PackReIDInputs')
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
# dataloader
|
| 32 |
+
train_dataloader = dict(
|
| 33 |
+
batch_size=1,
|
| 34 |
+
num_workers=2,
|
| 35 |
+
persistent_workers=True,
|
| 36 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 37 |
+
dataset=dict(
|
| 38 |
+
type=dataset_type,
|
| 39 |
+
data_root=data_root,
|
| 40 |
+
triplet_sampler=dict(num_ids=8, ins_per_id=4),
|
| 41 |
+
data_prefix=dict(img_path='reid/imgs'),
|
| 42 |
+
ann_file='reid/meta/train_80.txt',
|
| 43 |
+
pipeline=train_pipeline))
|
| 44 |
+
val_dataloader = dict(
|
| 45 |
+
batch_size=1,
|
| 46 |
+
num_workers=2,
|
| 47 |
+
persistent_workers=True,
|
| 48 |
+
drop_last=False,
|
| 49 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 50 |
+
dataset=dict(
|
| 51 |
+
type=dataset_type,
|
| 52 |
+
data_root=data_root,
|
| 53 |
+
triplet_sampler=None,
|
| 54 |
+
data_prefix=dict(img_path='reid/imgs'),
|
| 55 |
+
ann_file='reid/meta/val_20.txt',
|
| 56 |
+
pipeline=test_pipeline))
|
| 57 |
+
test_dataloader = val_dataloader
|
| 58 |
+
|
| 59 |
+
# evaluator
|
| 60 |
+
val_evaluator = dict(type='ReIDMetrics', metric=['mAP', 'CMC'])
|
| 61 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/objects365v1_detection.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'Objects365V1Dataset'
|
| 3 |
+
data_root = 'data/Objects365/Obj365_v1/'
|
| 4 |
+
|
| 5 |
+
# Example to use different file client
|
| 6 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 7 |
+
# automatically infer from prefix (not support LMDB and Memcache yet)
|
| 8 |
+
|
| 9 |
+
# data_root = 's3://openmmlab/datasets/detection/coco/'
|
| 10 |
+
|
| 11 |
+
# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
|
| 12 |
+
# backend_args = dict(
|
| 13 |
+
# backend='petrel',
|
| 14 |
+
# path_mapping=dict({
|
| 15 |
+
# './data/': 's3://openmmlab/datasets/detection/',
|
| 16 |
+
# 'data/': 's3://openmmlab/datasets/detection/'
|
| 17 |
+
# }))
|
| 18 |
+
backend_args = None
|
| 19 |
+
|
| 20 |
+
train_pipeline = [
|
| 21 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 22 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 23 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
| 24 |
+
dict(type='RandomFlip', prob=0.5),
|
| 25 |
+
dict(type='PackDetInputs')
|
| 26 |
+
]
|
| 27 |
+
test_pipeline = [
|
| 28 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 29 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
| 30 |
+
# If you don't have a gt annotation, delete the pipeline
|
| 31 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 32 |
+
dict(
|
| 33 |
+
type='PackDetInputs',
|
| 34 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 35 |
+
'scale_factor'))
|
| 36 |
+
]
|
| 37 |
+
train_dataloader = dict(
|
| 38 |
+
batch_size=2,
|
| 39 |
+
num_workers=2,
|
| 40 |
+
persistent_workers=True,
|
| 41 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 42 |
+
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
| 43 |
+
dataset=dict(
|
| 44 |
+
type=dataset_type,
|
| 45 |
+
data_root=data_root,
|
| 46 |
+
ann_file='annotations/objects365_train.json',
|
| 47 |
+
data_prefix=dict(img='train/'),
|
| 48 |
+
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
| 49 |
+
pipeline=train_pipeline,
|
| 50 |
+
backend_args=backend_args))
|
| 51 |
+
val_dataloader = dict(
|
| 52 |
+
batch_size=1,
|
| 53 |
+
num_workers=2,
|
| 54 |
+
persistent_workers=True,
|
| 55 |
+
drop_last=False,
|
| 56 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 57 |
+
dataset=dict(
|
| 58 |
+
type=dataset_type,
|
| 59 |
+
data_root=data_root,
|
| 60 |
+
ann_file='annotations/objects365_val.json',
|
| 61 |
+
data_prefix=dict(img='val/'),
|
| 62 |
+
test_mode=True,
|
| 63 |
+
pipeline=test_pipeline,
|
| 64 |
+
backend_args=backend_args))
|
| 65 |
+
test_dataloader = val_dataloader
|
| 66 |
+
|
| 67 |
+
val_evaluator = dict(
|
| 68 |
+
type='CocoMetric',
|
| 69 |
+
ann_file=data_root + 'annotations/objects365_val.json',
|
| 70 |
+
metric='bbox',
|
| 71 |
+
sort_categories=True,
|
| 72 |
+
format_only=False,
|
| 73 |
+
backend_args=backend_args)
|
| 74 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/objects365v2_detection.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'Objects365V2Dataset'
|
| 3 |
+
data_root = 'data/Objects365/Obj365_v2/'
|
| 4 |
+
|
| 5 |
+
# Example to use different file client
|
| 6 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 7 |
+
# automatically infer from prefix (not support LMDB and Memcache yet)
|
| 8 |
+
|
| 9 |
+
# data_root = 's3://openmmlab/datasets/detection/coco/'
|
| 10 |
+
|
| 11 |
+
# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
|
| 12 |
+
# backend_args = dict(
|
| 13 |
+
# backend='petrel',
|
| 14 |
+
# path_mapping=dict({
|
| 15 |
+
# './data/': 's3://openmmlab/datasets/detection/',
|
| 16 |
+
# 'data/': 's3://openmmlab/datasets/detection/'
|
| 17 |
+
# }))
|
| 18 |
+
backend_args = None
|
| 19 |
+
|
| 20 |
+
train_pipeline = [
|
| 21 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 22 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 23 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
| 24 |
+
dict(type='RandomFlip', prob=0.5),
|
| 25 |
+
dict(type='PackDetInputs')
|
| 26 |
+
]
|
| 27 |
+
test_pipeline = [
|
| 28 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 29 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
| 30 |
+
# If you don't have a gt annotation, delete the pipeline
|
| 31 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 32 |
+
dict(
|
| 33 |
+
type='PackDetInputs',
|
| 34 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 35 |
+
'scale_factor'))
|
| 36 |
+
]
|
| 37 |
+
train_dataloader = dict(
|
| 38 |
+
batch_size=2,
|
| 39 |
+
num_workers=2,
|
| 40 |
+
persistent_workers=True,
|
| 41 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 42 |
+
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
| 43 |
+
dataset=dict(
|
| 44 |
+
type=dataset_type,
|
| 45 |
+
data_root=data_root,
|
| 46 |
+
ann_file='annotations/zhiyuan_objv2_train.json',
|
| 47 |
+
data_prefix=dict(img='train/'),
|
| 48 |
+
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
| 49 |
+
pipeline=train_pipeline,
|
| 50 |
+
backend_args=backend_args))
|
| 51 |
+
val_dataloader = dict(
|
| 52 |
+
batch_size=1,
|
| 53 |
+
num_workers=2,
|
| 54 |
+
persistent_workers=True,
|
| 55 |
+
drop_last=False,
|
| 56 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 57 |
+
dataset=dict(
|
| 58 |
+
type=dataset_type,
|
| 59 |
+
data_root=data_root,
|
| 60 |
+
ann_file='annotations/zhiyuan_objv2_val.json',
|
| 61 |
+
data_prefix=dict(img='val/'),
|
| 62 |
+
test_mode=True,
|
| 63 |
+
pipeline=test_pipeline,
|
| 64 |
+
backend_args=backend_args))
|
| 65 |
+
test_dataloader = val_dataloader
|
| 66 |
+
|
| 67 |
+
val_evaluator = dict(
|
| 68 |
+
type='CocoMetric',
|
| 69 |
+
ann_file=data_root + 'annotations/zhiyuan_objv2_val.json',
|
| 70 |
+
metric='bbox',
|
| 71 |
+
format_only=False,
|
| 72 |
+
backend_args=backend_args)
|
| 73 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/openimages_detection.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'OpenImagesDataset'
|
| 3 |
+
data_root = 'data/OpenImages/'
|
| 4 |
+
|
| 5 |
+
# Example to use different file client
|
| 6 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 7 |
+
# automatically infer from prefix (not support LMDB and Memcache yet)
|
| 8 |
+
|
| 9 |
+
# data_root = 's3://openmmlab/datasets/detection/coco/'
|
| 10 |
+
|
| 11 |
+
# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
|
| 12 |
+
# backend_args = dict(
|
| 13 |
+
# backend='petrel',
|
| 14 |
+
# path_mapping=dict({
|
| 15 |
+
# './data/': 's3://openmmlab/datasets/detection/',
|
| 16 |
+
# 'data/': 's3://openmmlab/datasets/detection/'
|
| 17 |
+
# }))
|
| 18 |
+
backend_args = None
|
| 19 |
+
|
| 20 |
+
train_pipeline = [
|
| 21 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 22 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 23 |
+
dict(type='Resize', scale=(1024, 800), keep_ratio=True),
|
| 24 |
+
dict(type='RandomFlip', prob=0.5),
|
| 25 |
+
dict(type='PackDetInputs')
|
| 26 |
+
]
|
| 27 |
+
test_pipeline = [
|
| 28 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 29 |
+
dict(type='Resize', scale=(1024, 800), keep_ratio=True),
|
| 30 |
+
# avoid bboxes being resized
|
| 31 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 32 |
+
# TODO: find a better way to collect image_level_labels
|
| 33 |
+
dict(
|
| 34 |
+
type='PackDetInputs',
|
| 35 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 36 |
+
'scale_factor', 'instances', 'image_level_labels'))
|
| 37 |
+
]
|
| 38 |
+
|
| 39 |
+
train_dataloader = dict(
|
| 40 |
+
batch_size=2,
|
| 41 |
+
num_workers=0, # workers_per_gpu > 0 may occur out of memory
|
| 42 |
+
persistent_workers=False,
|
| 43 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 44 |
+
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
| 45 |
+
dataset=dict(
|
| 46 |
+
type=dataset_type,
|
| 47 |
+
data_root=data_root,
|
| 48 |
+
ann_file='annotations/oidv6-train-annotations-bbox.csv',
|
| 49 |
+
data_prefix=dict(img='OpenImages/train/'),
|
| 50 |
+
label_file='annotations/class-descriptions-boxable.csv',
|
| 51 |
+
hierarchy_file='annotations/bbox_labels_600_hierarchy.json',
|
| 52 |
+
meta_file='annotations/train-image-metas.pkl',
|
| 53 |
+
pipeline=train_pipeline,
|
| 54 |
+
backend_args=backend_args))
|
| 55 |
+
val_dataloader = dict(
|
| 56 |
+
batch_size=1,
|
| 57 |
+
num_workers=0,
|
| 58 |
+
persistent_workers=False,
|
| 59 |
+
drop_last=False,
|
| 60 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 61 |
+
dataset=dict(
|
| 62 |
+
type=dataset_type,
|
| 63 |
+
data_root=data_root,
|
| 64 |
+
ann_file='annotations/validation-annotations-bbox.csv',
|
| 65 |
+
data_prefix=dict(img='OpenImages/validation/'),
|
| 66 |
+
label_file='annotations/class-descriptions-boxable.csv',
|
| 67 |
+
hierarchy_file='annotations/bbox_labels_600_hierarchy.json',
|
| 68 |
+
meta_file='annotations/validation-image-metas.pkl',
|
| 69 |
+
image_level_ann_file='annotations/validation-'
|
| 70 |
+
'annotations-human-imagelabels-boxable.csv',
|
| 71 |
+
pipeline=test_pipeline,
|
| 72 |
+
backend_args=backend_args))
|
| 73 |
+
test_dataloader = val_dataloader
|
| 74 |
+
|
| 75 |
+
val_evaluator = dict(
|
| 76 |
+
type='OpenImagesMetric',
|
| 77 |
+
iou_thrs=0.5,
|
| 78 |
+
ioa_thrs=0.5,
|
| 79 |
+
use_group_of=True,
|
| 80 |
+
get_supercategory=True)
|
| 81 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/refcoco+.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'RefCocoDataset'
|
| 3 |
+
data_root = 'data/coco/'
|
| 4 |
+
|
| 5 |
+
backend_args = None
|
| 6 |
+
|
| 7 |
+
test_pipeline = [
|
| 8 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 9 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
| 10 |
+
dict(
|
| 11 |
+
type='LoadAnnotations',
|
| 12 |
+
with_mask=True,
|
| 13 |
+
with_bbox=False,
|
| 14 |
+
with_seg=False,
|
| 15 |
+
with_label=False),
|
| 16 |
+
dict(
|
| 17 |
+
type='PackDetInputs',
|
| 18 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 19 |
+
'scale_factor', 'gt_masks', 'text'))
|
| 20 |
+
]
|
| 21 |
+
|
| 22 |
+
val_dataloader = dict(
|
| 23 |
+
batch_size=1,
|
| 24 |
+
num_workers=2,
|
| 25 |
+
persistent_workers=True,
|
| 26 |
+
drop_last=False,
|
| 27 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 28 |
+
dataset=dict(
|
| 29 |
+
type=dataset_type,
|
| 30 |
+
data_root=data_root,
|
| 31 |
+
data_prefix=dict(img_path='train2014/'),
|
| 32 |
+
ann_file='refcoco+/instances.json',
|
| 33 |
+
split_file='refcoco+/refs(unc).p',
|
| 34 |
+
split='val',
|
| 35 |
+
text_mode='select_first',
|
| 36 |
+
pipeline=test_pipeline))
|
| 37 |
+
|
| 38 |
+
test_dataloader = dict(
|
| 39 |
+
batch_size=1,
|
| 40 |
+
num_workers=2,
|
| 41 |
+
persistent_workers=True,
|
| 42 |
+
drop_last=False,
|
| 43 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 44 |
+
dataset=dict(
|
| 45 |
+
type=dataset_type,
|
| 46 |
+
data_root=data_root,
|
| 47 |
+
data_prefix=dict(img_path='train2014/'),
|
| 48 |
+
ann_file='refcoco+/instances.json',
|
| 49 |
+
split_file='refcoco+/refs(unc).p',
|
| 50 |
+
split='testA', # or 'testB'
|
| 51 |
+
text_mode='select_first',
|
| 52 |
+
pipeline=test_pipeline))
|
| 53 |
+
|
| 54 |
+
val_evaluator = dict(type='RefSegMetric', metric=['cIoU', 'mIoU'])
|
| 55 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/refcoco.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'RefCocoDataset'
|
| 3 |
+
data_root = 'data/coco/'
|
| 4 |
+
|
| 5 |
+
backend_args = None
|
| 6 |
+
|
| 7 |
+
test_pipeline = [
|
| 8 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 9 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
| 10 |
+
dict(
|
| 11 |
+
type='LoadAnnotations',
|
| 12 |
+
with_mask=True,
|
| 13 |
+
with_bbox=False,
|
| 14 |
+
with_seg=False,
|
| 15 |
+
with_label=False),
|
| 16 |
+
dict(
|
| 17 |
+
type='PackDetInputs',
|
| 18 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 19 |
+
'scale_factor', 'gt_masks', 'text'))
|
| 20 |
+
]
|
| 21 |
+
|
| 22 |
+
val_dataloader = dict(
|
| 23 |
+
batch_size=1,
|
| 24 |
+
num_workers=2,
|
| 25 |
+
persistent_workers=True,
|
| 26 |
+
drop_last=False,
|
| 27 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 28 |
+
dataset=dict(
|
| 29 |
+
type=dataset_type,
|
| 30 |
+
data_root=data_root,
|
| 31 |
+
data_prefix=dict(img_path='train2014/'),
|
| 32 |
+
ann_file='refcoco/instances.json',
|
| 33 |
+
split_file='refcoco/refs(unc).p',
|
| 34 |
+
split='val',
|
| 35 |
+
text_mode='select_first',
|
| 36 |
+
pipeline=test_pipeline))
|
| 37 |
+
|
| 38 |
+
test_dataloader = dict(
|
| 39 |
+
batch_size=1,
|
| 40 |
+
num_workers=2,
|
| 41 |
+
persistent_workers=True,
|
| 42 |
+
drop_last=False,
|
| 43 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 44 |
+
dataset=dict(
|
| 45 |
+
type=dataset_type,
|
| 46 |
+
data_root=data_root,
|
| 47 |
+
data_prefix=dict(img_path='train2014/'),
|
| 48 |
+
ann_file='refcoco/instances.json',
|
| 49 |
+
split_file='refcoco/refs(unc).p',
|
| 50 |
+
split='testA', # or 'testB'
|
| 51 |
+
text_mode='select_first',
|
| 52 |
+
pipeline=test_pipeline))
|
| 53 |
+
|
| 54 |
+
val_evaluator = dict(type='RefSegMetric', metric=['cIoU', 'mIoU'])
|
| 55 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/refcocog.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'RefCocoDataset'
|
| 3 |
+
data_root = 'data/coco/'
|
| 4 |
+
|
| 5 |
+
backend_args = None
|
| 6 |
+
|
| 7 |
+
test_pipeline = [
|
| 8 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 9 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
| 10 |
+
dict(
|
| 11 |
+
type='LoadAnnotations',
|
| 12 |
+
with_mask=True,
|
| 13 |
+
with_bbox=False,
|
| 14 |
+
with_seg=False,
|
| 15 |
+
with_label=False),
|
| 16 |
+
dict(
|
| 17 |
+
type='PackDetInputs',
|
| 18 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 19 |
+
'scale_factor', 'gt_masks', 'text'))
|
| 20 |
+
]
|
| 21 |
+
|
| 22 |
+
val_dataloader = dict(
|
| 23 |
+
batch_size=1,
|
| 24 |
+
num_workers=2,
|
| 25 |
+
persistent_workers=True,
|
| 26 |
+
drop_last=False,
|
| 27 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 28 |
+
dataset=dict(
|
| 29 |
+
type=dataset_type,
|
| 30 |
+
data_root=data_root,
|
| 31 |
+
data_prefix=dict(img_path='train2014/'),
|
| 32 |
+
ann_file='refcocog/instances.json',
|
| 33 |
+
split_file='refcocog/refs(umd).p',
|
| 34 |
+
split='val',
|
| 35 |
+
text_mode='select_first',
|
| 36 |
+
pipeline=test_pipeline))
|
| 37 |
+
|
| 38 |
+
test_dataloader = dict(
|
| 39 |
+
batch_size=1,
|
| 40 |
+
num_workers=2,
|
| 41 |
+
persistent_workers=True,
|
| 42 |
+
drop_last=False,
|
| 43 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 44 |
+
dataset=dict(
|
| 45 |
+
type=dataset_type,
|
| 46 |
+
data_root=data_root,
|
| 47 |
+
data_prefix=dict(img_path='train2014/'),
|
| 48 |
+
ann_file='refcocog/instances.json',
|
| 49 |
+
split_file='refcocog/refs(umd).p',
|
| 50 |
+
split='test',
|
| 51 |
+
text_mode='select_first',
|
| 52 |
+
pipeline=test_pipeline))
|
| 53 |
+
|
| 54 |
+
val_evaluator = dict(type='RefSegMetric', metric=['cIoU', 'mIoU'])
|
| 55 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/semi_coco_detection.py
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'CocoDataset'
|
| 3 |
+
data_root = 'data/coco/'
|
| 4 |
+
|
| 5 |
+
# Example to use different file client
|
| 6 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 7 |
+
# automatically infer from prefix (not support LMDB and Memcache yet)
|
| 8 |
+
|
| 9 |
+
# data_root = 's3://openmmlab/datasets/detection/coco/'
|
| 10 |
+
|
| 11 |
+
# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
|
| 12 |
+
# backend_args = dict(
|
| 13 |
+
# backend='petrel',
|
| 14 |
+
# path_mapping=dict({
|
| 15 |
+
# './data/': 's3://openmmlab/datasets/detection/',
|
| 16 |
+
# 'data/': 's3://openmmlab/datasets/detection/'
|
| 17 |
+
# }))
|
| 18 |
+
backend_args = None
|
| 19 |
+
|
| 20 |
+
color_space = [
|
| 21 |
+
[dict(type='ColorTransform')],
|
| 22 |
+
[dict(type='AutoContrast')],
|
| 23 |
+
[dict(type='Equalize')],
|
| 24 |
+
[dict(type='Sharpness')],
|
| 25 |
+
[dict(type='Posterize')],
|
| 26 |
+
[dict(type='Solarize')],
|
| 27 |
+
[dict(type='Color')],
|
| 28 |
+
[dict(type='Contrast')],
|
| 29 |
+
[dict(type='Brightness')],
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
geometric = [
|
| 33 |
+
[dict(type='Rotate')],
|
| 34 |
+
[dict(type='ShearX')],
|
| 35 |
+
[dict(type='ShearY')],
|
| 36 |
+
[dict(type='TranslateX')],
|
| 37 |
+
[dict(type='TranslateY')],
|
| 38 |
+
]
|
| 39 |
+
|
| 40 |
+
scale = [(1333, 400), (1333, 1200)]
|
| 41 |
+
|
| 42 |
+
branch_field = ['sup', 'unsup_teacher', 'unsup_student']
|
| 43 |
+
# pipeline used to augment labeled data,
|
| 44 |
+
# which will be sent to student model for supervised training.
|
| 45 |
+
sup_pipeline = [
|
| 46 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 47 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 48 |
+
dict(type='RandomResize', scale=scale, keep_ratio=True),
|
| 49 |
+
dict(type='RandomFlip', prob=0.5),
|
| 50 |
+
dict(type='RandAugment', aug_space=color_space, aug_num=1),
|
| 51 |
+
dict(type='FilterAnnotations', min_gt_bbox_wh=(1e-2, 1e-2)),
|
| 52 |
+
dict(
|
| 53 |
+
type='MultiBranch',
|
| 54 |
+
branch_field=branch_field,
|
| 55 |
+
sup=dict(type='PackDetInputs'))
|
| 56 |
+
]
|
| 57 |
+
|
| 58 |
+
# pipeline used to augment unlabeled data weakly,
|
| 59 |
+
# which will be sent to teacher model for predicting pseudo instances.
|
| 60 |
+
weak_pipeline = [
|
| 61 |
+
dict(type='RandomResize', scale=scale, keep_ratio=True),
|
| 62 |
+
dict(type='RandomFlip', prob=0.5),
|
| 63 |
+
dict(
|
| 64 |
+
type='PackDetInputs',
|
| 65 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 66 |
+
'scale_factor', 'flip', 'flip_direction',
|
| 67 |
+
'homography_matrix')),
|
| 68 |
+
]
|
| 69 |
+
|
| 70 |
+
# pipeline used to augment unlabeled data strongly,
|
| 71 |
+
# which will be sent to student model for unsupervised training.
|
| 72 |
+
strong_pipeline = [
|
| 73 |
+
dict(type='RandomResize', scale=scale, keep_ratio=True),
|
| 74 |
+
dict(type='RandomFlip', prob=0.5),
|
| 75 |
+
dict(
|
| 76 |
+
type='RandomOrder',
|
| 77 |
+
transforms=[
|
| 78 |
+
dict(type='RandAugment', aug_space=color_space, aug_num=1),
|
| 79 |
+
dict(type='RandAugment', aug_space=geometric, aug_num=1),
|
| 80 |
+
]),
|
| 81 |
+
dict(type='RandomErasing', n_patches=(1, 5), ratio=(0, 0.2)),
|
| 82 |
+
dict(type='FilterAnnotations', min_gt_bbox_wh=(1e-2, 1e-2)),
|
| 83 |
+
dict(
|
| 84 |
+
type='PackDetInputs',
|
| 85 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 86 |
+
'scale_factor', 'flip', 'flip_direction',
|
| 87 |
+
'homography_matrix')),
|
| 88 |
+
]
|
| 89 |
+
|
| 90 |
+
# pipeline used to augment unlabeled data into different views
|
| 91 |
+
unsup_pipeline = [
|
| 92 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 93 |
+
dict(type='LoadEmptyAnnotations'),
|
| 94 |
+
dict(
|
| 95 |
+
type='MultiBranch',
|
| 96 |
+
branch_field=branch_field,
|
| 97 |
+
unsup_teacher=weak_pipeline,
|
| 98 |
+
unsup_student=strong_pipeline,
|
| 99 |
+
)
|
| 100 |
+
]
|
| 101 |
+
|
| 102 |
+
test_pipeline = [
|
| 103 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 104 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
| 105 |
+
dict(
|
| 106 |
+
type='PackDetInputs',
|
| 107 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 108 |
+
'scale_factor'))
|
| 109 |
+
]
|
| 110 |
+
|
| 111 |
+
batch_size = 5
|
| 112 |
+
num_workers = 5
|
| 113 |
+
# There are two common semi-supervised learning settings on the coco dataset:
|
| 114 |
+
# (1) Divide the train2017 into labeled and unlabeled datasets
|
| 115 |
+
# by a fixed percentage, such as 1%, 2%, 5% and 10%.
|
| 116 |
+
# The format of labeled_ann_file and unlabeled_ann_file are
|
| 117 |
+
# instances_train2017.{fold}@{percent}.json, and
|
| 118 |
+
# instances_train2017.{fold}@{percent}-unlabeled.json
|
| 119 |
+
# `fold` is used for cross-validation, and `percent` represents
|
| 120 |
+
# the proportion of labeled data in the train2017.
|
| 121 |
+
# (2) Choose the train2017 as the labeled dataset
|
| 122 |
+
# and unlabeled2017 as the unlabeled dataset.
|
| 123 |
+
# The labeled_ann_file and unlabeled_ann_file are
|
| 124 |
+
# instances_train2017.json and image_info_unlabeled2017.json
|
| 125 |
+
# We use this configuration by default.
|
| 126 |
+
labeled_dataset = dict(
|
| 127 |
+
type=dataset_type,
|
| 128 |
+
data_root=data_root,
|
| 129 |
+
ann_file='annotations/instances_train2017.json',
|
| 130 |
+
data_prefix=dict(img='train2017/'),
|
| 131 |
+
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
| 132 |
+
pipeline=sup_pipeline,
|
| 133 |
+
backend_args=backend_args)
|
| 134 |
+
|
| 135 |
+
unlabeled_dataset = dict(
|
| 136 |
+
type=dataset_type,
|
| 137 |
+
data_root=data_root,
|
| 138 |
+
ann_file='annotations/instances_unlabeled2017.json',
|
| 139 |
+
data_prefix=dict(img='unlabeled2017/'),
|
| 140 |
+
filter_cfg=dict(filter_empty_gt=False),
|
| 141 |
+
pipeline=unsup_pipeline,
|
| 142 |
+
backend_args=backend_args)
|
| 143 |
+
|
| 144 |
+
train_dataloader = dict(
|
| 145 |
+
batch_size=batch_size,
|
| 146 |
+
num_workers=num_workers,
|
| 147 |
+
persistent_workers=True,
|
| 148 |
+
sampler=dict(
|
| 149 |
+
type='GroupMultiSourceSampler',
|
| 150 |
+
batch_size=batch_size,
|
| 151 |
+
source_ratio=[1, 4]),
|
| 152 |
+
dataset=dict(
|
| 153 |
+
type='ConcatDataset', datasets=[labeled_dataset, unlabeled_dataset]))
|
| 154 |
+
|
| 155 |
+
val_dataloader = dict(
|
| 156 |
+
batch_size=1,
|
| 157 |
+
num_workers=2,
|
| 158 |
+
persistent_workers=True,
|
| 159 |
+
drop_last=False,
|
| 160 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 161 |
+
dataset=dict(
|
| 162 |
+
type=dataset_type,
|
| 163 |
+
data_root=data_root,
|
| 164 |
+
ann_file='annotations/instances_val2017.json',
|
| 165 |
+
data_prefix=dict(img='val2017/'),
|
| 166 |
+
test_mode=True,
|
| 167 |
+
pipeline=test_pipeline,
|
| 168 |
+
backend_args=backend_args))
|
| 169 |
+
|
| 170 |
+
test_dataloader = val_dataloader
|
| 171 |
+
|
| 172 |
+
val_evaluator = dict(
|
| 173 |
+
type='CocoMetric',
|
| 174 |
+
ann_file=data_root + 'annotations/instances_val2017.json',
|
| 175 |
+
metric='bbox',
|
| 176 |
+
format_only=False,
|
| 177 |
+
backend_args=backend_args)
|
| 178 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/voc0712.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'VOCDataset'
|
| 3 |
+
data_root = 'data/VOCdevkit/'
|
| 4 |
+
|
| 5 |
+
# Example to use different file client
|
| 6 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 7 |
+
# automatically Infer from prefix (not support LMDB and Memcache yet)
|
| 8 |
+
|
| 9 |
+
# data_root = 's3://openmmlab/datasets/detection/segmentation/VOCdevkit/'
|
| 10 |
+
|
| 11 |
+
# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
|
| 12 |
+
# backend_args = dict(
|
| 13 |
+
# backend='petrel',
|
| 14 |
+
# path_mapping=dict({
|
| 15 |
+
# './data/': 's3://openmmlab/datasets/segmentation/',
|
| 16 |
+
# 'data/': 's3://openmmlab/datasets/segmentation/'
|
| 17 |
+
# }))
|
| 18 |
+
backend_args = None
|
| 19 |
+
|
| 20 |
+
train_pipeline = [
|
| 21 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 22 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 23 |
+
dict(type='Resize', scale=(1000, 600), keep_ratio=True),
|
| 24 |
+
dict(type='RandomFlip', prob=0.5),
|
| 25 |
+
dict(type='PackDetInputs')
|
| 26 |
+
]
|
| 27 |
+
test_pipeline = [
|
| 28 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 29 |
+
dict(type='Resize', scale=(1000, 600), keep_ratio=True),
|
| 30 |
+
# avoid bboxes being resized
|
| 31 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 32 |
+
dict(
|
| 33 |
+
type='PackDetInputs',
|
| 34 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 35 |
+
'scale_factor'))
|
| 36 |
+
]
|
| 37 |
+
train_dataloader = dict(
|
| 38 |
+
batch_size=2,
|
| 39 |
+
num_workers=2,
|
| 40 |
+
persistent_workers=True,
|
| 41 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 42 |
+
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
| 43 |
+
dataset=dict(
|
| 44 |
+
type='RepeatDataset',
|
| 45 |
+
times=3,
|
| 46 |
+
dataset=dict(
|
| 47 |
+
type='ConcatDataset',
|
| 48 |
+
# VOCDataset will add different `dataset_type` in dataset.metainfo,
|
| 49 |
+
# which will get error if using ConcatDataset. Adding
|
| 50 |
+
# `ignore_keys` can avoid this error.
|
| 51 |
+
ignore_keys=['dataset_type'],
|
| 52 |
+
datasets=[
|
| 53 |
+
dict(
|
| 54 |
+
type=dataset_type,
|
| 55 |
+
data_root=data_root,
|
| 56 |
+
ann_file='VOC2007/ImageSets/Main/trainval.txt',
|
| 57 |
+
data_prefix=dict(sub_data_root='VOC2007/'),
|
| 58 |
+
filter_cfg=dict(
|
| 59 |
+
filter_empty_gt=True, min_size=32, bbox_min_size=32),
|
| 60 |
+
pipeline=train_pipeline,
|
| 61 |
+
backend_args=backend_args),
|
| 62 |
+
dict(
|
| 63 |
+
type=dataset_type,
|
| 64 |
+
data_root=data_root,
|
| 65 |
+
ann_file='VOC2012/ImageSets/Main/trainval.txt',
|
| 66 |
+
data_prefix=dict(sub_data_root='VOC2012/'),
|
| 67 |
+
filter_cfg=dict(
|
| 68 |
+
filter_empty_gt=True, min_size=32, bbox_min_size=32),
|
| 69 |
+
pipeline=train_pipeline,
|
| 70 |
+
backend_args=backend_args)
|
| 71 |
+
])))
|
| 72 |
+
|
| 73 |
+
val_dataloader = dict(
|
| 74 |
+
batch_size=1,
|
| 75 |
+
num_workers=2,
|
| 76 |
+
persistent_workers=True,
|
| 77 |
+
drop_last=False,
|
| 78 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 79 |
+
dataset=dict(
|
| 80 |
+
type=dataset_type,
|
| 81 |
+
data_root=data_root,
|
| 82 |
+
ann_file='VOC2007/ImageSets/Main/test.txt',
|
| 83 |
+
data_prefix=dict(sub_data_root='VOC2007/'),
|
| 84 |
+
test_mode=True,
|
| 85 |
+
pipeline=test_pipeline,
|
| 86 |
+
backend_args=backend_args))
|
| 87 |
+
test_dataloader = val_dataloader
|
| 88 |
+
|
| 89 |
+
# Pascal VOC2007 uses `11points` as default evaluate mode, while PASCAL
|
| 90 |
+
# VOC2012 defaults to use 'area'.
|
| 91 |
+
val_evaluator = dict(type='VOCMetric', metric='mAP', eval_mode='11points')
|
| 92 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/wider_face.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset settings
|
| 2 |
+
dataset_type = 'WIDERFaceDataset'
|
| 3 |
+
data_root = 'data/WIDERFace/'
|
| 4 |
+
# Example to use different file client
|
| 5 |
+
# Method 1: simply set the data root and let the file I/O module
|
| 6 |
+
# automatically infer from prefix (not support LMDB and Memcache yet)
|
| 7 |
+
|
| 8 |
+
# data_root = 's3://openmmlab/datasets/detection/cityscapes/'
|
| 9 |
+
|
| 10 |
+
# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
|
| 11 |
+
# backend_args = dict(
|
| 12 |
+
# backend='petrel',
|
| 13 |
+
# path_mapping=dict({
|
| 14 |
+
# './data/': 's3://openmmlab/datasets/detection/',
|
| 15 |
+
# 'data/': 's3://openmmlab/datasets/detection/'
|
| 16 |
+
# }))
|
| 17 |
+
backend_args = None
|
| 18 |
+
|
| 19 |
+
img_scale = (640, 640) # VGA resolution
|
| 20 |
+
|
| 21 |
+
train_pipeline = [
|
| 22 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 23 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 24 |
+
dict(type='Resize', scale=img_scale, keep_ratio=True),
|
| 25 |
+
dict(type='RandomFlip', prob=0.5),
|
| 26 |
+
dict(type='PackDetInputs')
|
| 27 |
+
]
|
| 28 |
+
test_pipeline = [
|
| 29 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 30 |
+
dict(type='Resize', scale=img_scale, keep_ratio=True),
|
| 31 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 32 |
+
dict(
|
| 33 |
+
type='PackDetInputs',
|
| 34 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 35 |
+
'scale_factor'))
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
train_dataloader = dict(
|
| 39 |
+
batch_size=2,
|
| 40 |
+
num_workers=2,
|
| 41 |
+
persistent_workers=True,
|
| 42 |
+
drop_last=False,
|
| 43 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 44 |
+
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
| 45 |
+
dataset=dict(
|
| 46 |
+
type=dataset_type,
|
| 47 |
+
data_root=data_root,
|
| 48 |
+
ann_file='train.txt',
|
| 49 |
+
data_prefix=dict(img='WIDER_train'),
|
| 50 |
+
filter_cfg=dict(filter_empty_gt=True, bbox_min_size=17, min_size=32),
|
| 51 |
+
pipeline=train_pipeline))
|
| 52 |
+
|
| 53 |
+
val_dataloader = dict(
|
| 54 |
+
batch_size=1,
|
| 55 |
+
num_workers=2,
|
| 56 |
+
persistent_workers=True,
|
| 57 |
+
drop_last=False,
|
| 58 |
+
sampler=dict(type='DefaultSampler', shuffle=False),
|
| 59 |
+
dataset=dict(
|
| 60 |
+
type=dataset_type,
|
| 61 |
+
data_root=data_root,
|
| 62 |
+
ann_file='val.txt',
|
| 63 |
+
data_prefix=dict(img='WIDER_val'),
|
| 64 |
+
test_mode=True,
|
| 65 |
+
pipeline=test_pipeline))
|
| 66 |
+
test_dataloader = val_dataloader
|
| 67 |
+
|
| 68 |
+
val_evaluator = dict(
|
| 69 |
+
# TODO: support WiderFace-Evaluation for easy, medium, hard cases
|
| 70 |
+
type='VOCMetric',
|
| 71 |
+
metric='mAP',
|
| 72 |
+
eval_mode='11points')
|
| 73 |
+
test_evaluator = val_evaluator
|
mmdet_code/SR-TOD/configs/_base_/datasets/youtube_vis.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
dataset_type = 'YouTubeVISDataset'
|
| 2 |
+
data_root = 'data/youtube_vis_2019/'
|
| 3 |
+
dataset_version = data_root[-5:-1] # 2019 or 2021
|
| 4 |
+
|
| 5 |
+
backend_args = None
|
| 6 |
+
|
| 7 |
+
# dataset settings
|
| 8 |
+
train_pipeline = [
|
| 9 |
+
dict(
|
| 10 |
+
type='UniformRefFrameSample',
|
| 11 |
+
num_ref_imgs=1,
|
| 12 |
+
frame_range=100,
|
| 13 |
+
filter_key_img=True),
|
| 14 |
+
dict(
|
| 15 |
+
type='TransformBroadcaster',
|
| 16 |
+
share_random_params=True,
|
| 17 |
+
transforms=[
|
| 18 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 19 |
+
dict(type='LoadTrackAnnotations', with_mask=True),
|
| 20 |
+
dict(type='Resize', scale=(640, 360), keep_ratio=True),
|
| 21 |
+
dict(type='RandomFlip', prob=0.5),
|
| 22 |
+
]),
|
| 23 |
+
dict(type='PackTrackInputs')
|
| 24 |
+
]
|
| 25 |
+
|
| 26 |
+
test_pipeline = [
|
| 27 |
+
dict(
|
| 28 |
+
type='TransformBroadcaster',
|
| 29 |
+
transforms=[
|
| 30 |
+
dict(type='LoadImageFromFile', backend_args=backend_args),
|
| 31 |
+
dict(type='Resize', scale=(640, 360), keep_ratio=True),
|
| 32 |
+
dict(type='LoadTrackAnnotations', with_mask=True),
|
| 33 |
+
]),
|
| 34 |
+
dict(type='PackTrackInputs')
|
| 35 |
+
]
|
| 36 |
+
|
| 37 |
+
# dataloader
|
| 38 |
+
train_dataloader = dict(
|
| 39 |
+
batch_size=2,
|
| 40 |
+
num_workers=2,
|
| 41 |
+
persistent_workers=True,
|
| 42 |
+
# sampler=dict(type='TrackImgSampler'), # image-based sampling
|
| 43 |
+
sampler=dict(type='DefaultSampler', shuffle=True),
|
| 44 |
+
batch_sampler=dict(type='TrackAspectRatioBatchSampler'),
|
| 45 |
+
dataset=dict(
|
| 46 |
+
type=dataset_type,
|
| 47 |
+
data_root=data_root,
|
| 48 |
+
dataset_version=dataset_version,
|
| 49 |
+
ann_file='annotations/youtube_vis_2019_train.json',
|
| 50 |
+
data_prefix=dict(img_path='train/JPEGImages'),
|
| 51 |
+
pipeline=train_pipeline))
|
| 52 |
+
val_dataloader = dict(
|
| 53 |
+
batch_size=1,
|
| 54 |
+
num_workers=2,
|
| 55 |
+
persistent_workers=True,
|
| 56 |
+
drop_last=False,
|
| 57 |
+
sampler=dict(type='DefaultSampler', shuffle=False, round_up=False),
|
| 58 |
+
dataset=dict(
|
| 59 |
+
type=dataset_type,
|
| 60 |
+
data_root=data_root,
|
| 61 |
+
dataset_version=dataset_version,
|
| 62 |
+
ann_file='annotations/youtube_vis_2019_valid.json',
|
| 63 |
+
data_prefix=dict(img_path='valid/JPEGImages'),
|
| 64 |
+
test_mode=True,
|
| 65 |
+
pipeline=test_pipeline))
|
| 66 |
+
test_dataloader = val_dataloader
|
mmdet_code/SR-TOD/docs/en/Makefile
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Minimal makefile for Sphinx documentation
|
| 2 |
+
#
|
| 3 |
+
|
| 4 |
+
# You can set these variables from the command line, and also
|
| 5 |
+
# from the environment for the first two.
|
| 6 |
+
SPHINXOPTS ?=
|
| 7 |
+
SPHINXBUILD ?= sphinx-build
|
| 8 |
+
SOURCEDIR = .
|
| 9 |
+
BUILDDIR = _build
|
| 10 |
+
|
| 11 |
+
# Put it first so that "make" without argument is like "make help".
|
| 12 |
+
help:
|
| 13 |
+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
| 14 |
+
|
| 15 |
+
.PHONY: help Makefile
|
| 16 |
+
|
| 17 |
+
# Catch-all target: route all unknown targets to Sphinx using the new
|
| 18 |
+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
| 19 |
+
%: Makefile
|
| 20 |
+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
mmdet_code/SR-TOD/docs/en/_static/css/readthedocs.css
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.header-logo {
|
| 2 |
+
background-image: url("../image/mmdet-logo.png");
|
| 3 |
+
background-size: 156px 40px;
|
| 4 |
+
height: 40px;
|
| 5 |
+
width: 156px;
|
| 6 |
+
}
|
mmdet_code/SR-TOD/docs/en/_static/image/mmdet-logo.png
ADDED
|
Git LFS Details
|
mmdet_code/SR-TOD/docs/en/advanced_guides/conventions.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Conventions
|
| 2 |
+
|
| 3 |
+
Please check the following conventions if you would like to modify MMDetection as your own project.
|
| 4 |
+
|
| 5 |
+
## About the order of image shape
|
| 6 |
+
|
| 7 |
+
In OpenMMLab 2.0, to be consistent with the input argument of OpenCV, the argument about image shape in the data transformation pipeline is always in the `(width, height)` order. On the contrary, for computation convenience, the order of the field going through the data pipeline and the model is `(height, width)`. Specifically, in the results processed by each data transform pipeline, the fields and their value meaning is as below:
|
| 8 |
+
|
| 9 |
+
- img_shape: (height, width)
|
| 10 |
+
- ori_shape: (height, width)
|
| 11 |
+
- pad_shape: (height, width)
|
| 12 |
+
- batch_input_shape: (height, width)
|
| 13 |
+
|
| 14 |
+
As an example, the initialization arguments of `Mosaic` are as below:
|
| 15 |
+
|
| 16 |
+
```python
|
| 17 |
+
@TRANSFORMS.register_module()
|
| 18 |
+
class Mosaic(BaseTransform):
|
| 19 |
+
def __init__(self,
|
| 20 |
+
img_scale: Tuple[int, int] = (640, 640),
|
| 21 |
+
center_ratio_range: Tuple[float, float] = (0.5, 1.5),
|
| 22 |
+
bbox_clip_border: bool = True,
|
| 23 |
+
pad_val: float = 114.0,
|
| 24 |
+
prob: float = 1.0) -> None:
|
| 25 |
+
...
|
| 26 |
+
|
| 27 |
+
# img_scale order should be (width, height)
|
| 28 |
+
self.img_scale = img_scale
|
| 29 |
+
|
| 30 |
+
def transform(self, results: dict) -> dict:
|
| 31 |
+
...
|
| 32 |
+
|
| 33 |
+
results['img'] = mosaic_img
|
| 34 |
+
# (height, width)
|
| 35 |
+
results['img_shape'] = mosaic_img.shape[:2]
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
## Loss
|
| 39 |
+
|
| 40 |
+
In MMDetection, a `dict` containing losses and metrics will be returned by `model(**data)`.
|
| 41 |
+
|
| 42 |
+
For example, in bbox head,
|
| 43 |
+
|
| 44 |
+
```python
|
| 45 |
+
class BBoxHead(nn.Module):
|
| 46 |
+
...
|
| 47 |
+
def loss(self, ...):
|
| 48 |
+
losses = dict()
|
| 49 |
+
# classification loss
|
| 50 |
+
losses['loss_cls'] = self.loss_cls(...)
|
| 51 |
+
# classification accuracy
|
| 52 |
+
losses['acc'] = accuracy(...)
|
| 53 |
+
# bbox regression loss
|
| 54 |
+
losses['loss_bbox'] = self.loss_bbox(...)
|
| 55 |
+
return losses
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
`bbox_head.loss()` will be called during model forward.
|
| 59 |
+
The returned dict contains `'loss_bbox'`, `'loss_cls'`, `'acc'` .
|
| 60 |
+
Only `'loss_bbox'`, `'loss_cls'` will be used during back propagation,
|
| 61 |
+
`'acc'` will only be used as a metric to monitor training process.
|
| 62 |
+
|
| 63 |
+
By default, only values whose keys contain `'loss'` will be back propagated.
|
| 64 |
+
This behavior could be changed by modifying `BaseDetector.train_step()`.
|
| 65 |
+
|
| 66 |
+
## Empty Proposals
|
| 67 |
+
|
| 68 |
+
In MMDetection, We have added special handling and unit test for empty proposals of two-stage. We need to deal with the empty proposals of the entire batch and single image at the same time. For example, in CascadeRoIHead,
|
| 69 |
+
|
| 70 |
+
```python
|
| 71 |
+
# simple_test method
|
| 72 |
+
...
|
| 73 |
+
# There is no proposal in the whole batch
|
| 74 |
+
if rois.shape[0] == 0:
|
| 75 |
+
bbox_results = [[
|
| 76 |
+
np.zeros((0, 5), dtype=np.float32)
|
| 77 |
+
for _ in range(self.bbox_head[-1].num_classes)
|
| 78 |
+
]] * num_imgs
|
| 79 |
+
if self.with_mask:
|
| 80 |
+
mask_classes = self.mask_head[-1].num_classes
|
| 81 |
+
segm_results = [[[] for _ in range(mask_classes)]
|
| 82 |
+
for _ in range(num_imgs)]
|
| 83 |
+
results = list(zip(bbox_results, segm_results))
|
| 84 |
+
else:
|
| 85 |
+
results = bbox_results
|
| 86 |
+
return results
|
| 87 |
+
...
|
| 88 |
+
|
| 89 |
+
# There is no proposal in the single image
|
| 90 |
+
for i in range(self.num_stages):
|
| 91 |
+
...
|
| 92 |
+
if i < self.num_stages - 1:
|
| 93 |
+
for j in range(num_imgs):
|
| 94 |
+
# Handle empty proposal
|
| 95 |
+
if rois[j].shape[0] > 0:
|
| 96 |
+
bbox_label = cls_score[j][:, :-1].argmax(dim=1)
|
| 97 |
+
refine_roi = self.bbox_head[i].regress_by_class(
|
| 98 |
+
rois[j], bbox_label, bbox_pred[j], img_metas[j])
|
| 99 |
+
refine_roi_list.append(refine_roi)
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
If you have customized `RoIHead`, you can refer to the above method to deal with empty proposals.
|
| 103 |
+
|
| 104 |
+
## Coco Panoptic Dataset
|
| 105 |
+
|
| 106 |
+
In MMDetection, we have supported COCO Panoptic dataset. We clarify a few conventions about the implementation of `CocoPanopticDataset` here.
|
| 107 |
+
|
| 108 |
+
1. For mmdet\<=2.16.0, the range of foreground and background labels in semantic segmentation are different from the default setting of MMDetection. The label `0` stands for `VOID` label and the category labels start from `1`.
|
| 109 |
+
Since mmdet=2.17.0, the category labels of semantic segmentation start from `0` and label `255` stands for `VOID` for consistency with labels of bounding boxes.
|
| 110 |
+
To achieve that, the `Pad` pipeline supports setting the padding value for `seg`.
|
| 111 |
+
2. In the evaluation, the panoptic result is a map with the same shape as the original image. Each value in the result map has the format of `instance_id * INSTANCE_OFFSET + category_id`.
|
mmdet_code/SR-TOD/docs/en/advanced_guides/customize_dataset.md
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Customize Datasets
|
| 2 |
+
|
| 3 |
+
## Support new data format
|
| 4 |
+
|
| 5 |
+
To support a new data format, you can either convert them to existing formats (COCO format or PASCAL format) or directly convert them to the middle format. You could also choose to convert them offline (before training by a script) or online (implement a new dataset and do the conversion at training). In MMDetection, we recommend to convert the data into COCO formats and do the conversion offline, thus you only need to modify the config's data annotation paths and classes after the conversion of your data.
|
| 6 |
+
|
| 7 |
+
### Reorganize new data formats to existing format
|
| 8 |
+
|
| 9 |
+
The simplest way is to convert your dataset to existing dataset formats (COCO or PASCAL VOC).
|
| 10 |
+
|
| 11 |
+
The annotation JSON files in COCO format has the following necessary keys:
|
| 12 |
+
|
| 13 |
+
```python
|
| 14 |
+
'images': [
|
| 15 |
+
{
|
| 16 |
+
'file_name': 'COCO_val2014_000000001268.jpg',
|
| 17 |
+
'height': 427,
|
| 18 |
+
'width': 640,
|
| 19 |
+
'id': 1268
|
| 20 |
+
},
|
| 21 |
+
...
|
| 22 |
+
],
|
| 23 |
+
|
| 24 |
+
'annotations': [
|
| 25 |
+
{
|
| 26 |
+
'segmentation': [[192.81,
|
| 27 |
+
247.09,
|
| 28 |
+
...
|
| 29 |
+
219.03,
|
| 30 |
+
249.06]], # If you have mask labels, and it is in polygon XY point coordinate format, you need to ensure that at least 3 point coordinates are included. Otherwise, it is an invalid polygon.
|
| 31 |
+
'area': 1035.749,
|
| 32 |
+
'iscrowd': 0,
|
| 33 |
+
'image_id': 1268,
|
| 34 |
+
'bbox': [192.81, 224.8, 74.73, 33.43],
|
| 35 |
+
'category_id': 16,
|
| 36 |
+
'id': 42986
|
| 37 |
+
},
|
| 38 |
+
...
|
| 39 |
+
],
|
| 40 |
+
|
| 41 |
+
'categories': [
|
| 42 |
+
{'id': 0, 'name': 'car'},
|
| 43 |
+
]
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
There are three necessary keys in the JSON file:
|
| 47 |
+
|
| 48 |
+
- `images`: contains a list of images with their information like `file_name`, `height`, `width`, and `id`.
|
| 49 |
+
- `annotations`: contains the list of instance annotations.
|
| 50 |
+
- `categories`: contains the list of categories names and their ID.
|
| 51 |
+
|
| 52 |
+
After the data pre-processing, there are two steps for users to train the customized new dataset with existing format (e.g. COCO format):
|
| 53 |
+
|
| 54 |
+
1. Modify the config file for using the customized dataset.
|
| 55 |
+
2. Check the annotations of the customized dataset.
|
| 56 |
+
|
| 57 |
+
Here we give an example to show the above two steps, which uses a customized dataset of 5 classes with COCO format to train an existing Cascade Mask R-CNN R50-FPN detector.
|
| 58 |
+
|
| 59 |
+
#### 1. Modify the config file for using the customized dataset
|
| 60 |
+
|
| 61 |
+
There are two aspects involved in the modification of config file:
|
| 62 |
+
|
| 63 |
+
1. The `data` field. Specifically, you need to explicitly add the `metainfo=dict(classes=classes)` fields in `train_dataloader.dataset`, `val_dataloader.dataset` and `test_dataloader.dataset` and `classes` must be a tuple type.
|
| 64 |
+
2. The `num_classes` field in the `model` part. Explicitly over-write all the `num_classes` from default value (e.g. 80 in COCO) to your classes number.
|
| 65 |
+
|
| 66 |
+
In `configs/my_custom_config.py`:
|
| 67 |
+
|
| 68 |
+
```python
|
| 69 |
+
|
| 70 |
+
# the new config inherits the base configs to highlight the necessary modification
|
| 71 |
+
_base_ = './cascade_mask_rcnn_r50_fpn_1x_coco.py'
|
| 72 |
+
|
| 73 |
+
# 1. dataset settings
|
| 74 |
+
dataset_type = 'CocoDataset'
|
| 75 |
+
classes = ('a', 'b', 'c', 'd', 'e')
|
| 76 |
+
data_root='path/to/your/'
|
| 77 |
+
|
| 78 |
+
train_dataloader = dict(
|
| 79 |
+
batch_size=2,
|
| 80 |
+
num_workers=2,
|
| 81 |
+
dataset=dict(
|
| 82 |
+
type=dataset_type,
|
| 83 |
+
# explicitly add your class names to the field `metainfo`
|
| 84 |
+
metainfo=dict(classes=classes),
|
| 85 |
+
data_root=data_root,
|
| 86 |
+
ann_file='train/annotation_data',
|
| 87 |
+
data_prefix=dict(img='train/image_data')
|
| 88 |
+
)
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
val_dataloader = dict(
|
| 92 |
+
batch_size=1,
|
| 93 |
+
num_workers=2,
|
| 94 |
+
dataset=dict(
|
| 95 |
+
type=dataset_type,
|
| 96 |
+
test_mode=True,
|
| 97 |
+
# explicitly add your class names to the field `metainfo`
|
| 98 |
+
metainfo=dict(classes=classes),
|
| 99 |
+
data_root=data_root,
|
| 100 |
+
ann_file='val/annotation_data',
|
| 101 |
+
data_prefix=dict(img='val/image_data')
|
| 102 |
+
)
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
test_dataloader = dict(
|
| 106 |
+
batch_size=1,
|
| 107 |
+
num_workers=2,
|
| 108 |
+
dataset=dict(
|
| 109 |
+
type=dataset_type,
|
| 110 |
+
test_mode=True,
|
| 111 |
+
# explicitly add your class names to the field `metainfo`
|
| 112 |
+
metainfo=dict(classes=classes),
|
| 113 |
+
data_root=data_root,
|
| 114 |
+
ann_file='test/annotation_data',
|
| 115 |
+
data_prefix=dict(img='test/image_data')
|
| 116 |
+
)
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
# 2. model settings
|
| 120 |
+
|
| 121 |
+
# explicitly over-write all the `num_classes` field from default 80 to 5.
|
| 122 |
+
model = dict(
|
| 123 |
+
roi_head=dict(
|
| 124 |
+
bbox_head=[
|
| 125 |
+
dict(
|
| 126 |
+
type='Shared2FCBBoxHead',
|
| 127 |
+
# explicitly over-write all the `num_classes` field from default 80 to 5.
|
| 128 |
+
num_classes=5),
|
| 129 |
+
dict(
|
| 130 |
+
type='Shared2FCBBoxHead',
|
| 131 |
+
# explicitly over-write all the `num_classes` field from default 80 to 5.
|
| 132 |
+
num_classes=5),
|
| 133 |
+
dict(
|
| 134 |
+
type='Shared2FCBBoxHead',
|
| 135 |
+
# explicitly over-write all the `num_classes` field from default 80 to 5.
|
| 136 |
+
num_classes=5)],
|
| 137 |
+
# explicitly over-write all the `num_classes` field from default 80 to 5.
|
| 138 |
+
mask_head=dict(num_classes=5)))
|
| 139 |
+
```
|
| 140 |
+
|
| 141 |
+
#### 2. Check the annotations of the customized dataset
|
| 142 |
+
|
| 143 |
+
Assuming your customized dataset is COCO format, make sure you have the correct annotations in the customized dataset:
|
| 144 |
+
|
| 145 |
+
1. The length for `categories` field in annotations should exactly equal the tuple length of `classes` fields in your config, meaning the number of classes (e.g. 5 in this example).
|
| 146 |
+
2. The `classes` fields in your config file should have exactly the same elements and the same order with the `name` in `categories` of annotations. MMDetection automatically maps the uncontinuous `id` in `categories` to the continuous label indices, so the string order of `name` in `categories` field affects the order of label indices. Meanwhile, the string order of `classes` in config affects the label text during visualization of predicted bounding boxes.
|
| 147 |
+
3. The `category_id` in `annotations` field should be valid, i.e., all values in `category_id` should belong to `id` in `categories`.
|
| 148 |
+
|
| 149 |
+
Here is a valid example of annotations:
|
| 150 |
+
|
| 151 |
+
```python
|
| 152 |
+
|
| 153 |
+
'annotations': [
|
| 154 |
+
{
|
| 155 |
+
'segmentation': [[192.81,
|
| 156 |
+
247.09,
|
| 157 |
+
...
|
| 158 |
+
219.03,
|
| 159 |
+
249.06]], # if you have mask labels
|
| 160 |
+
'area': 1035.749,
|
| 161 |
+
'iscrowd': 0,
|
| 162 |
+
'image_id': 1268,
|
| 163 |
+
'bbox': [192.81, 224.8, 74.73, 33.43],
|
| 164 |
+
'category_id': 16,
|
| 165 |
+
'id': 42986
|
| 166 |
+
},
|
| 167 |
+
...
|
| 168 |
+
],
|
| 169 |
+
|
| 170 |
+
# MMDetection automatically maps the uncontinuous `id` to the continuous label indices.
|
| 171 |
+
'categories': [
|
| 172 |
+
{'id': 1, 'name': 'a'}, {'id': 3, 'name': 'b'}, {'id': 4, 'name': 'c'}, {'id': 16, 'name': 'd'}, {'id': 17, 'name': 'e'},
|
| 173 |
+
]
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
We use this way to support CityScapes dataset. The script is in [cityscapes.py](../../../tools/dataset_converters/cityscapes.py) and we also provide the finetuning [configs](../../../configs/cityscapes).
|
| 177 |
+
|
| 178 |
+
**Note**
|
| 179 |
+
|
| 180 |
+
1. For instance segmentation datasets, **MMDetection only supports evaluating mask AP of dataset in COCO format for now**.
|
| 181 |
+
2. It is recommended to convert the data offline before training, thus you can still use `CocoDataset` and only need to modify the path of annotations and the training classes.
|
| 182 |
+
|
| 183 |
+
### Reorganize new data format to middle format
|
| 184 |
+
|
| 185 |
+
It is also fine if you do not want to convert the annotation format to COCO or PASCAL format.
|
| 186 |
+
Actually, we define a simple annotation format in MMEninge's [BaseDataset](https://github.com/open-mmlab/mmengine/blob/main/mmengine/dataset/base_dataset.py#L116) and all existing datasets are
|
| 187 |
+
processed to be compatible with it, either online or offline.
|
| 188 |
+
|
| 189 |
+
The annotation of the dataset must be in `json` or `yaml`, `yml` or `pickle`, `pkl` format; the dictionary stored in the annotation file must contain two fields `metainfo` and `data_list`. The `metainfo` is a dictionary, which contains the metadata of the dataset, such as class information; `data_list` is a list, each element in the list is a dictionary, the dictionary defines the raw data of one image, and each raw data contains a or several training/testing samples.
|
| 190 |
+
|
| 191 |
+
Here is an example.
|
| 192 |
+
|
| 193 |
+
```python
|
| 194 |
+
{
|
| 195 |
+
'metainfo':
|
| 196 |
+
{
|
| 197 |
+
'classes': ('person', 'bicycle', 'car', 'motorcycle'),
|
| 198 |
+
...
|
| 199 |
+
},
|
| 200 |
+
'data_list':
|
| 201 |
+
[
|
| 202 |
+
{
|
| 203 |
+
"img_path": "xxx/xxx_1.jpg",
|
| 204 |
+
"height": 604,
|
| 205 |
+
"width": 640,
|
| 206 |
+
"instances":
|
| 207 |
+
[
|
| 208 |
+
{
|
| 209 |
+
"bbox": [0, 0, 10, 20],
|
| 210 |
+
"bbox_label": 1,
|
| 211 |
+
"ignore_flag": 0
|
| 212 |
+
},
|
| 213 |
+
{
|
| 214 |
+
"bbox": [10, 10, 110, 120],
|
| 215 |
+
"bbox_label": 2,
|
| 216 |
+
"ignore_flag": 0
|
| 217 |
+
}
|
| 218 |
+
]
|
| 219 |
+
},
|
| 220 |
+
{
|
| 221 |
+
"img_path": "xxx/xxx_2.jpg",
|
| 222 |
+
"height": 320,
|
| 223 |
+
"width": 460,
|
| 224 |
+
"instances":
|
| 225 |
+
[
|
| 226 |
+
{
|
| 227 |
+
"bbox": [10, 0, 20, 20],
|
| 228 |
+
"bbox_label": 3,
|
| 229 |
+
"ignore_flag": 1,
|
| 230 |
+
}
|
| 231 |
+
]
|
| 232 |
+
},
|
| 233 |
+
...
|
| 234 |
+
]
|
| 235 |
+
}
|
| 236 |
+
```
|
| 237 |
+
|
| 238 |
+
Some datasets may provide annotations like crowd/difficult/ignored bboxes, we use `ignore_flag`to cover them.
|
| 239 |
+
|
| 240 |
+
After obtaining the above standard data annotation format, you can directly use [BaseDetDataset](../../../mmdet/datasets/base_det_dataset.py#L13) of MMDetection in the configuration , without conversion.
|
| 241 |
+
|
| 242 |
+
### An example of customized dataset
|
| 243 |
+
|
| 244 |
+
Assume the annotation is in a new format in text files.
|
| 245 |
+
The bounding boxes annotations are stored in text file `annotation.txt` as the following
|
| 246 |
+
|
| 247 |
+
```
|
| 248 |
+
#
|
| 249 |
+
000001.jpg
|
| 250 |
+
1280 720
|
| 251 |
+
2
|
| 252 |
+
10 20 40 60 1
|
| 253 |
+
20 40 50 60 2
|
| 254 |
+
#
|
| 255 |
+
000002.jpg
|
| 256 |
+
1280 720
|
| 257 |
+
3
|
| 258 |
+
50 20 40 60 2
|
| 259 |
+
20 40 30 45 2
|
| 260 |
+
30 40 50 60 3
|
| 261 |
+
```
|
| 262 |
+
|
| 263 |
+
We can create a new dataset in `mmdet/datasets/my_dataset.py` to load the data.
|
| 264 |
+
|
| 265 |
+
```python
|
| 266 |
+
import mmengine
|
| 267 |
+
|
| 268 |
+
from mmdet.base_det_dataset import BaseDetDataset
|
| 269 |
+
from mmdet.registry import DATASETS
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
@DATASETS.register_module()
|
| 273 |
+
class MyDataset(BaseDetDataset):
|
| 274 |
+
|
| 275 |
+
METAINFO = {
|
| 276 |
+
'classes': ('person', 'bicycle', 'car', 'motorcycle'),
|
| 277 |
+
'palette': [(220, 20, 60), (119, 11, 32), (0, 0, 142), (0, 0, 230)]
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
def load_data_list(self, ann_file):
|
| 281 |
+
ann_list = mmengine.list_from_file(ann_file)
|
| 282 |
+
|
| 283 |
+
data_infos = []
|
| 284 |
+
for i, ann_line in enumerate(ann_list):
|
| 285 |
+
if ann_line != '#':
|
| 286 |
+
continue
|
| 287 |
+
|
| 288 |
+
img_shape = ann_list[i + 2].split(' ')
|
| 289 |
+
width = int(img_shape[0])
|
| 290 |
+
height = int(img_shape[1])
|
| 291 |
+
bbox_number = int(ann_list[i + 3])
|
| 292 |
+
|
| 293 |
+
instances = []
|
| 294 |
+
for anns in ann_list[i + 4:i + 4 + bbox_number]:
|
| 295 |
+
instance = {}
|
| 296 |
+
instance['bbox'] = [float(ann) for ann in anns.split(' ')[:4]]
|
| 297 |
+
instance['bbox_label']=int(anns[4])
|
| 298 |
+
instances.append(instance)
|
| 299 |
+
|
| 300 |
+
data_infos.append(
|
| 301 |
+
dict(
|
| 302 |
+
img_path=ann_list[i + 1],
|
| 303 |
+
img_id=i,
|
| 304 |
+
width=width,
|
| 305 |
+
height=height,
|
| 306 |
+
instances=instances
|
| 307 |
+
))
|
| 308 |
+
|
| 309 |
+
return data_infos
|
| 310 |
+
```
|
| 311 |
+
|
| 312 |
+
Then in the config, to use `MyDataset` you can modify the config as the following
|
| 313 |
+
|
| 314 |
+
```python
|
| 315 |
+
dataset_A_train = dict(
|
| 316 |
+
type='MyDataset',
|
| 317 |
+
ann_file = 'image_list.txt',
|
| 318 |
+
pipeline=train_pipeline
|
| 319 |
+
)
|
| 320 |
+
```
|
| 321 |
+
|
| 322 |
+
## Customize datasets by dataset wrappers
|
| 323 |
+
|
| 324 |
+
MMEngine also supports many dataset wrappers to mix the dataset or modify the dataset distribution for training.
|
| 325 |
+
Currently it supports to three dataset wrappers as below:
|
| 326 |
+
|
| 327 |
+
- `RepeatDataset`: simply repeat the whole dataset.
|
| 328 |
+
- `ClassBalancedDataset`: repeat dataset in a class balanced manner.
|
| 329 |
+
- `ConcatDataset`: concat datasets.
|
| 330 |
+
|
| 331 |
+
For detailed usage, see [MMEngine Dataset Wrapper](#TODO).
|
| 332 |
+
|
| 333 |
+
## Modify Dataset Classes
|
| 334 |
+
|
| 335 |
+
With existing dataset types, we can modify the metainfo of them to train subset of the annotations.
|
| 336 |
+
For example, if you want to train only three classes of the current dataset,
|
| 337 |
+
you can modify the classes of dataset.
|
| 338 |
+
The dataset will filter out the ground truth boxes of other classes automatically.
|
| 339 |
+
|
| 340 |
+
```python
|
| 341 |
+
classes = ('person', 'bicycle', 'car')
|
| 342 |
+
train_dataloader = dict(
|
| 343 |
+
dataset=dict(
|
| 344 |
+
metainfo=dict(classes=classes))
|
| 345 |
+
)
|
| 346 |
+
val_dataloader = dict(
|
| 347 |
+
dataset=dict(
|
| 348 |
+
metainfo=dict(classes=classes))
|
| 349 |
+
)
|
| 350 |
+
test_dataloader = dict(
|
| 351 |
+
dataset=dict(
|
| 352 |
+
metainfo=dict(classes=classes))
|
| 353 |
+
)
|
| 354 |
+
```
|
| 355 |
+
|
| 356 |
+
**Note**:
|
| 357 |
+
|
| 358 |
+
- Before MMDetection v2.5.0, the dataset will filter out the empty GT images automatically if the classes are set and there is no way to disable that through config. This is an undesirable behavior and introduces confusion because if the classes are not set, the dataset only filter the empty GT images when `filter_empty_gt=True` and `test_mode=False`. After MMDetection v2.5.0, we decouple the image filtering process and the classes modification, i.e., the dataset will only filter empty GT images when `filter_cfg=dict(filter_empty_gt=True)` and `test_mode=False`, no matter whether the classes are set. Thus, setting the classes only influences the annotations of classes used for training and users could decide whether to filter empty GT images by themselves.
|
| 359 |
+
- When directly using `BaseDataset` in MMEngine or `BaseDetDataset` in MMDetection, users cannot filter images without GT by modifying the configuration, but it can be solved in an offline way.
|
| 360 |
+
- Please remember to modify the `num_classes` in the head when specifying `classes` in dataset. We implemented [NumClassCheckHook](../../../mmdet/engine/hooks/num_class_check_hook.py) to check whether the numbers are consistent since v2.9.0(after PR#4508).
|
| 361 |
+
|
| 362 |
+
## COCO Panoptic Dataset
|
| 363 |
+
|
| 364 |
+
Now we support COCO Panoptic Dataset, the format of panoptic annotations is different from COCO format.
|
| 365 |
+
Both the foreground and the background will exist in the annotation file.
|
| 366 |
+
The annotation json files in COCO Panoptic format has the following necessary keys:
|
| 367 |
+
|
| 368 |
+
```python
|
| 369 |
+
'images': [
|
| 370 |
+
{
|
| 371 |
+
'file_name': '000000001268.jpg',
|
| 372 |
+
'height': 427,
|
| 373 |
+
'width': 640,
|
| 374 |
+
'id': 1268
|
| 375 |
+
},
|
| 376 |
+
...
|
| 377 |
+
]
|
| 378 |
+
|
| 379 |
+
'annotations': [
|
| 380 |
+
{
|
| 381 |
+
'filename': '000000001268.jpg',
|
| 382 |
+
'image_id': 1268,
|
| 383 |
+
'segments_info': [
|
| 384 |
+
{
|
| 385 |
+
'id':8345037, # One-to-one correspondence with the id in the annotation map.
|
| 386 |
+
'category_id': 51,
|
| 387 |
+
'iscrowd': 0,
|
| 388 |
+
'bbox': (x1, y1, w, h), # The bbox of the background is the outer rectangle of its mask.
|
| 389 |
+
'area': 24315
|
| 390 |
+
},
|
| 391 |
+
...
|
| 392 |
+
]
|
| 393 |
+
},
|
| 394 |
+
...
|
| 395 |
+
]
|
| 396 |
+
|
| 397 |
+
'categories': [ # including both foreground categories and background categories
|
| 398 |
+
{'id': 0, 'name': 'person'},
|
| 399 |
+
...
|
| 400 |
+
]
|
| 401 |
+
```
|
| 402 |
+
|
| 403 |
+
Moreover, the `seg` must be set to the path of the panoptic annotation images.
|
| 404 |
+
|
| 405 |
+
```python
|
| 406 |
+
dataset_type = 'CocoPanopticDataset'
|
| 407 |
+
data_root='path/to/your/'
|
| 408 |
+
|
| 409 |
+
train_dataloader = dict(
|
| 410 |
+
dataset=dict(
|
| 411 |
+
type=dataset_type,
|
| 412 |
+
data_root=data_root,
|
| 413 |
+
data_prefix=dict(
|
| 414 |
+
img='train/image_data/', seg='train/panoptic/image_annotation_data/')
|
| 415 |
+
)
|
| 416 |
+
)
|
| 417 |
+
val_dataloader = dict(
|
| 418 |
+
dataset=dict(
|
| 419 |
+
type=dataset_type,
|
| 420 |
+
data_root=data_root,
|
| 421 |
+
data_prefix=dict(
|
| 422 |
+
img='val/image_data/', seg='val/panoptic/image_annotation_data/')
|
| 423 |
+
)
|
| 424 |
+
)
|
| 425 |
+
test_dataloader = dict(
|
| 426 |
+
dataset=dict(
|
| 427 |
+
type=dataset_type,
|
| 428 |
+
data_root=data_root,
|
| 429 |
+
data_prefix=dict(
|
| 430 |
+
img='test/image_data/', seg='test/panoptic/image_annotation_data/')
|
| 431 |
+
)
|
| 432 |
+
)
|
| 433 |
+
```
|
mmdet_code/SR-TOD/docs/en/advanced_guides/customize_losses.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Customize Losses
|
| 2 |
+
|
| 3 |
+
MMDetection provides users with different loss functions. But the default configuration may be not applicable for different datasets or models, so users may want to modify a specific loss to adapt the new situation.
|
| 4 |
+
|
| 5 |
+
This tutorial first elaborate the computation pipeline of losses, then give some instructions about how to modify each step. The modification can be categorized as tweaking and weighting.
|
| 6 |
+
|
| 7 |
+
## Computation pipeline of a loss
|
| 8 |
+
|
| 9 |
+
Given the input prediction and target, as well as the weights, a loss function maps the input tensor to the final loss scalar. The mapping can be divided into five steps:
|
| 10 |
+
|
| 11 |
+
1. Set the sampling method to sample positive and negative samples.
|
| 12 |
+
|
| 13 |
+
2. Get **element-wise** or **sample-wise** loss by the loss kernel function.
|
| 14 |
+
|
| 15 |
+
3. Weighting the loss with a weight tensor **element-wisely**.
|
| 16 |
+
|
| 17 |
+
4. Reduce the loss tensor to a **scalar**.
|
| 18 |
+
|
| 19 |
+
5. Weighting the loss with a **scalar**.
|
| 20 |
+
|
| 21 |
+
## Set sampling method (step 1)
|
| 22 |
+
|
| 23 |
+
For some loss functions, sampling strategies are needed to avoid imbalance between positive and negative samples.
|
| 24 |
+
|
| 25 |
+
For example, when using `CrossEntropyLoss` in RPN head, we need to set `RandomSampler` in `train_cfg`
|
| 26 |
+
|
| 27 |
+
```python
|
| 28 |
+
train_cfg=dict(
|
| 29 |
+
rpn=dict(
|
| 30 |
+
sampler=dict(
|
| 31 |
+
type='RandomSampler',
|
| 32 |
+
num=256,
|
| 33 |
+
pos_fraction=0.5,
|
| 34 |
+
neg_pos_ub=-1,
|
| 35 |
+
add_gt_as_proposals=False))
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
For some other losses which have positive and negative sample balance mechanism such as Focal Loss, GHMC, and QualityFocalLoss, the sampler is no more necessary.
|
| 39 |
+
|
| 40 |
+
## Tweaking loss
|
| 41 |
+
|
| 42 |
+
Tweaking a loss is more related with step 2, 4, 5, and most modifications can be specified in the config.
|
| 43 |
+
Here we take [Focal Loss (FL)](../../../mmdet/models/losses/focal_loss.py) as an example.
|
| 44 |
+
The following code sniper are the construction method and config of FL respectively, they are actually one to one correspondence.
|
| 45 |
+
|
| 46 |
+
```python
|
| 47 |
+
@LOSSES.register_module()
|
| 48 |
+
class FocalLoss(nn.Module):
|
| 49 |
+
|
| 50 |
+
def __init__(self,
|
| 51 |
+
use_sigmoid=True,
|
| 52 |
+
gamma=2.0,
|
| 53 |
+
alpha=0.25,
|
| 54 |
+
reduction='mean',
|
| 55 |
+
loss_weight=1.0):
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
```python
|
| 59 |
+
loss_cls=dict(
|
| 60 |
+
type='FocalLoss',
|
| 61 |
+
use_sigmoid=True,
|
| 62 |
+
gamma=2.0,
|
| 63 |
+
alpha=0.25,
|
| 64 |
+
loss_weight=1.0)
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
### Tweaking hyper-parameters (step 2)
|
| 68 |
+
|
| 69 |
+
`gamma` and `beta` are two hyper-parameters in the Focal Loss. Say if we want to change the value of `gamma` to be 1.5 and `alpha` to be 0.5, then we can specify them in the config as follows:
|
| 70 |
+
|
| 71 |
+
```python
|
| 72 |
+
loss_cls=dict(
|
| 73 |
+
type='FocalLoss',
|
| 74 |
+
use_sigmoid=True,
|
| 75 |
+
gamma=1.5,
|
| 76 |
+
alpha=0.5,
|
| 77 |
+
loss_weight=1.0)
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
### Tweaking the way of reduction (step 3)
|
| 81 |
+
|
| 82 |
+
The default way of reduction is `mean` for FL. Say if we want to change the reduction from `mean` to `sum`, we can specify it in the config as follows:
|
| 83 |
+
|
| 84 |
+
```python
|
| 85 |
+
loss_cls=dict(
|
| 86 |
+
type='FocalLoss',
|
| 87 |
+
use_sigmoid=True,
|
| 88 |
+
gamma=2.0,
|
| 89 |
+
alpha=0.25,
|
| 90 |
+
loss_weight=1.0,
|
| 91 |
+
reduction='sum')
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
### Tweaking loss weight (step 5)
|
| 95 |
+
|
| 96 |
+
The loss weight here is a scalar which controls the weight of different losses in multi-task learning, e.g. classification loss and regression loss. Say if we want to change to loss weight of classification loss to be 0.5, we can specify it in the config as follows:
|
| 97 |
+
|
| 98 |
+
```python
|
| 99 |
+
loss_cls=dict(
|
| 100 |
+
type='FocalLoss',
|
| 101 |
+
use_sigmoid=True,
|
| 102 |
+
gamma=2.0,
|
| 103 |
+
alpha=0.25,
|
| 104 |
+
loss_weight=0.5)
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
## Weighting loss (step 3)
|
| 108 |
+
|
| 109 |
+
Weighting loss means we re-weight the loss element-wisely. To be more specific, we multiply the loss tensor with a weight tensor which has the same shape. As a result, different entries of the loss can be scaled differently, and so called element-wisely.
|
| 110 |
+
The loss weight varies across different models and highly context related, but overall there are two kinds of loss weights, `label_weights` for classification loss and `bbox_weights` for bbox regression loss. You can find them in the `get_target` method of the corresponding head. Here we take [ATSSHead](../../../mmdet/models/dense_heads/atss_head.py#L322) as an example, which inherit [AnchorHead](../../../mmdet/models/dense_heads/anchor_head.py) but overwrite its `get_targets` method which yields different `label_weights` and `bbox_weights`.
|
| 111 |
+
|
| 112 |
+
```
|
| 113 |
+
class ATSSHead(AnchorHead):
|
| 114 |
+
|
| 115 |
+
...
|
| 116 |
+
|
| 117 |
+
def get_targets(self,
|
| 118 |
+
anchor_list,
|
| 119 |
+
valid_flag_list,
|
| 120 |
+
gt_bboxes_list,
|
| 121 |
+
img_metas,
|
| 122 |
+
gt_bboxes_ignore_list=None,
|
| 123 |
+
gt_labels_list=None,
|
| 124 |
+
label_channels=1,
|
| 125 |
+
unmap_outputs=True):
|
| 126 |
+
```
|
mmdet_code/SR-TOD/docs/en/advanced_guides/customize_models.md
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Customize Models
|
| 2 |
+
|
| 3 |
+
We basically categorize model components into 5 types.
|
| 4 |
+
|
| 5 |
+
- backbone: usually an FCN network to extract feature maps, e.g., ResNet, MobileNet.
|
| 6 |
+
- neck: the component between backbones and heads, e.g., FPN, PAFPN.
|
| 7 |
+
- head: the component for specific tasks, e.g., bbox prediction and mask prediction.
|
| 8 |
+
- roi extractor: the part for extracting RoI features from feature maps, e.g., RoI Align.
|
| 9 |
+
- loss: the component in head for calculating losses, e.g., FocalLoss, L1Loss, and GHMLoss.
|
| 10 |
+
|
| 11 |
+
## Develop new components
|
| 12 |
+
|
| 13 |
+
### Add a new backbone
|
| 14 |
+
|
| 15 |
+
Here we show how to develop new components with an example of MobileNet.
|
| 16 |
+
|
| 17 |
+
#### 1. Define a new backbone (e.g. MobileNet)
|
| 18 |
+
|
| 19 |
+
Create a new file `mmdet/models/backbones/mobilenet.py`.
|
| 20 |
+
|
| 21 |
+
```python
|
| 22 |
+
import torch.nn as nn
|
| 23 |
+
|
| 24 |
+
from mmdet.registry import MODELS
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@MODELS.register_module()
|
| 28 |
+
class MobileNet(nn.Module):
|
| 29 |
+
|
| 30 |
+
def __init__(self, arg1, arg2):
|
| 31 |
+
pass
|
| 32 |
+
|
| 33 |
+
def forward(self, x): # should return a tuple
|
| 34 |
+
pass
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
#### 2. Import the module
|
| 38 |
+
|
| 39 |
+
You can either add the following line to `mmdet/models/backbones/__init__.py`
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
from .mobilenet import MobileNet
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
or alternatively add
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
custom_imports = dict(
|
| 49 |
+
imports=['mmdet.models.backbones.mobilenet'],
|
| 50 |
+
allow_failed_imports=False)
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
to the config file to avoid modifying the original code.
|
| 54 |
+
|
| 55 |
+
#### 3. Use the backbone in your config file
|
| 56 |
+
|
| 57 |
+
```python
|
| 58 |
+
model = dict(
|
| 59 |
+
...
|
| 60 |
+
backbone=dict(
|
| 61 |
+
type='MobileNet',
|
| 62 |
+
arg1=xxx,
|
| 63 |
+
arg2=xxx),
|
| 64 |
+
...
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
### Add new necks
|
| 68 |
+
|
| 69 |
+
#### 1. Define a neck (e.g. PAFPN)
|
| 70 |
+
|
| 71 |
+
Create a new file `mmdet/models/necks/pafpn.py`.
|
| 72 |
+
|
| 73 |
+
```python
|
| 74 |
+
import torch.nn as nn
|
| 75 |
+
|
| 76 |
+
from mmdet.registry import MODELS
|
| 77 |
+
|
| 78 |
+
@MODELS.register_module()
|
| 79 |
+
class PAFPN(nn.Module):
|
| 80 |
+
|
| 81 |
+
def __init__(self,
|
| 82 |
+
in_channels,
|
| 83 |
+
out_channels,
|
| 84 |
+
num_outs,
|
| 85 |
+
start_level=0,
|
| 86 |
+
end_level=-1,
|
| 87 |
+
add_extra_convs=False):
|
| 88 |
+
pass
|
| 89 |
+
|
| 90 |
+
def forward(self, inputs):
|
| 91 |
+
# implementation is ignored
|
| 92 |
+
pass
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
#### 2. Import the module
|
| 96 |
+
|
| 97 |
+
You can either add the following line to `mmdet/models/necks/__init__.py`,
|
| 98 |
+
|
| 99 |
+
```python
|
| 100 |
+
from .pafpn import PAFPN
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
or alternatively add
|
| 104 |
+
|
| 105 |
+
```python
|
| 106 |
+
custom_imports = dict(
|
| 107 |
+
imports=['mmdet.models.necks.pafpn'],
|
| 108 |
+
allow_failed_imports=False)
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
to the config file and avoid modifying the original code.
|
| 112 |
+
|
| 113 |
+
#### 3. Modify the config file
|
| 114 |
+
|
| 115 |
+
```python
|
| 116 |
+
neck=dict(
|
| 117 |
+
type='PAFPN',
|
| 118 |
+
in_channels=[256, 512, 1024, 2048],
|
| 119 |
+
out_channels=256,
|
| 120 |
+
num_outs=5)
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
### Add new heads
|
| 124 |
+
|
| 125 |
+
Here we show how to develop a new head with the example of [Double Head R-CNN](https://arxiv.org/abs/1904.06493) as the following.
|
| 126 |
+
|
| 127 |
+
First, add a new bbox head in `mmdet/models/roi_heads/bbox_heads/double_bbox_head.py`.
|
| 128 |
+
Double Head R-CNN implements a new bbox head for object detection.
|
| 129 |
+
To implement a bbox head, basically we need to implement three functions of the new module as the following.
|
| 130 |
+
|
| 131 |
+
```python
|
| 132 |
+
from typing import Tuple
|
| 133 |
+
|
| 134 |
+
import torch.nn as nn
|
| 135 |
+
from mmcv.cnn import ConvModule
|
| 136 |
+
from mmengine.model import BaseModule, ModuleList
|
| 137 |
+
from torch import Tensor
|
| 138 |
+
|
| 139 |
+
from mmdet.models.backbones.resnet import Bottleneck
|
| 140 |
+
from mmdet.registry import MODELS
|
| 141 |
+
from mmdet.utils import ConfigType, MultiConfig, OptConfigType, OptMultiConfig
|
| 142 |
+
from .bbox_head import BBoxHead
|
| 143 |
+
|
| 144 |
+
@MODELS.register_module()
|
| 145 |
+
class DoubleConvFCBBoxHead(BBoxHead):
|
| 146 |
+
r"""Bbox head used in Double-Head R-CNN
|
| 147 |
+
|
| 148 |
+
.. code-block:: none
|
| 149 |
+
|
| 150 |
+
/-> cls
|
| 151 |
+
/-> shared convs ->
|
| 152 |
+
\-> reg
|
| 153 |
+
roi features
|
| 154 |
+
/-> cls
|
| 155 |
+
\-> shared fc ->
|
| 156 |
+
\-> reg
|
| 157 |
+
""" # noqa: W605
|
| 158 |
+
|
| 159 |
+
def __init__(self,
|
| 160 |
+
num_convs: int = 0,
|
| 161 |
+
num_fcs: int = 0,
|
| 162 |
+
conv_out_channels: int = 1024,
|
| 163 |
+
fc_out_channels: int = 1024,
|
| 164 |
+
conv_cfg: OptConfigType = None,
|
| 165 |
+
norm_cfg: ConfigType = dict(type='BN'),
|
| 166 |
+
init_cfg: MultiConfig = dict(
|
| 167 |
+
type='Normal',
|
| 168 |
+
override=[
|
| 169 |
+
dict(type='Normal', name='fc_cls', std=0.01),
|
| 170 |
+
dict(type='Normal', name='fc_reg', std=0.001),
|
| 171 |
+
dict(
|
| 172 |
+
type='Xavier',
|
| 173 |
+
name='fc_branch',
|
| 174 |
+
distribution='uniform')
|
| 175 |
+
]),
|
| 176 |
+
**kwargs) -> None:
|
| 177 |
+
kwargs.setdefault('with_avg_pool', True)
|
| 178 |
+
super().__init__(init_cfg=init_cfg, **kwargs)
|
| 179 |
+
|
| 180 |
+
def forward(self, x_cls: Tensor, x_reg: Tensor) -> Tuple[Tensor]:
|
| 181 |
+
|
| 182 |
+
```
|
| 183 |
+
|
| 184 |
+
Second, implement a new RoI Head if it is necessary. We plan to inherit the new `DoubleHeadRoIHead` from `StandardRoIHead`. We can find that a `StandardRoIHead` already implements the following functions.
|
| 185 |
+
|
| 186 |
+
```python
|
| 187 |
+
from typing import List, Optional, Tuple
|
| 188 |
+
|
| 189 |
+
import torch
|
| 190 |
+
from torch import Tensor
|
| 191 |
+
|
| 192 |
+
from mmdet.registry import MODELS, TASK_UTILS
|
| 193 |
+
from mmdet.structures import DetDataSample
|
| 194 |
+
from mmdet.structures.bbox import bbox2roi
|
| 195 |
+
from mmdet.utils import ConfigType, InstanceList
|
| 196 |
+
from ..task_modules.samplers import SamplingResult
|
| 197 |
+
from ..utils import empty_instances, unpack_gt_instances
|
| 198 |
+
from .base_roi_head import BaseRoIHead
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
@MODELS.register_module()
|
| 202 |
+
class StandardRoIHead(BaseRoIHead):
|
| 203 |
+
"""Simplest base roi head including one bbox head and one mask head."""
|
| 204 |
+
|
| 205 |
+
def init_assigner_sampler(self) -> None:
|
| 206 |
+
|
| 207 |
+
def init_bbox_head(self, bbox_roi_extractor: ConfigType,
|
| 208 |
+
bbox_head: ConfigType) -> None:
|
| 209 |
+
|
| 210 |
+
def init_mask_head(self, mask_roi_extractor: ConfigType,
|
| 211 |
+
mask_head: ConfigType) -> None:
|
| 212 |
+
|
| 213 |
+
def forward(self, x: Tuple[Tensor],
|
| 214 |
+
rpn_results_list: InstanceList) -> tuple:
|
| 215 |
+
|
| 216 |
+
def loss(self, x: Tuple[Tensor], rpn_results_list: InstanceList,
|
| 217 |
+
batch_data_samples: List[DetDataSample]) -> dict:
|
| 218 |
+
|
| 219 |
+
def _bbox_forward(self, x: Tuple[Tensor], rois: Tensor) -> dict:
|
| 220 |
+
|
| 221 |
+
def bbox_loss(self, x: Tuple[Tensor],
|
| 222 |
+
sampling_results: List[SamplingResult]) -> dict:
|
| 223 |
+
|
| 224 |
+
def mask_loss(self, x: Tuple[Tensor],
|
| 225 |
+
sampling_results: List[SamplingResult], bbox_feats: Tensor,
|
| 226 |
+
batch_gt_instances: InstanceList) -> dict:
|
| 227 |
+
|
| 228 |
+
def _mask_forward(self,
|
| 229 |
+
x: Tuple[Tensor],
|
| 230 |
+
rois: Tensor = None,
|
| 231 |
+
pos_inds: Optional[Tensor] = None,
|
| 232 |
+
bbox_feats: Optional[Tensor] = None) -> dict:
|
| 233 |
+
|
| 234 |
+
def predict_bbox(self,
|
| 235 |
+
x: Tuple[Tensor],
|
| 236 |
+
batch_img_metas: List[dict],
|
| 237 |
+
rpn_results_list: InstanceList,
|
| 238 |
+
rcnn_test_cfg: ConfigType,
|
| 239 |
+
rescale: bool = False) -> InstanceList:
|
| 240 |
+
|
| 241 |
+
def predict_mask(self,
|
| 242 |
+
x: Tuple[Tensor],
|
| 243 |
+
batch_img_metas: List[dict],
|
| 244 |
+
results_list: InstanceList,
|
| 245 |
+
rescale: bool = False) -> InstanceList:
|
| 246 |
+
|
| 247 |
+
```
|
| 248 |
+
|
| 249 |
+
Double Head's modification is mainly in the `bbox_forward` logic, and it inherits other logics from the `StandardRoIHead`. In the `mmdet/models/roi_heads/double_roi_head.py`, we implement the new RoI Head as the following:
|
| 250 |
+
|
| 251 |
+
```python
|
| 252 |
+
from typing import Tuple
|
| 253 |
+
|
| 254 |
+
from torch import Tensor
|
| 255 |
+
|
| 256 |
+
from mmdet.registry import MODELS
|
| 257 |
+
from .standard_roi_head import StandardRoIHead
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
@MODELS.register_module()
|
| 261 |
+
class DoubleHeadRoIHead(StandardRoIHead):
|
| 262 |
+
"""RoI head for `Double Head RCNN <https://arxiv.org/abs/1904.06493>`_.
|
| 263 |
+
|
| 264 |
+
Args:
|
| 265 |
+
reg_roi_scale_factor (float): The scale factor to extend the rois
|
| 266 |
+
used to extract the regression features.
|
| 267 |
+
"""
|
| 268 |
+
|
| 269 |
+
def __init__(self, reg_roi_scale_factor: float, **kwargs):
|
| 270 |
+
super().__init__(**kwargs)
|
| 271 |
+
self.reg_roi_scale_factor = reg_roi_scale_factor
|
| 272 |
+
|
| 273 |
+
def _bbox_forward(self, x: Tuple[Tensor], rois: Tensor) -> dict:
|
| 274 |
+
"""Box head forward function used in both training and testing.
|
| 275 |
+
|
| 276 |
+
Args:
|
| 277 |
+
x (tuple[Tensor]): List of multi-level img features.
|
| 278 |
+
rois (Tensor): RoIs with the shape (n, 5) where the first
|
| 279 |
+
column indicates batch id of each RoI.
|
| 280 |
+
|
| 281 |
+
Returns:
|
| 282 |
+
dict[str, Tensor]: Usually returns a dictionary with keys:
|
| 283 |
+
|
| 284 |
+
- `cls_score` (Tensor): Classification scores.
|
| 285 |
+
- `bbox_pred` (Tensor): Box energies / deltas.
|
| 286 |
+
- `bbox_feats` (Tensor): Extract bbox RoI features.
|
| 287 |
+
"""
|
| 288 |
+
bbox_cls_feats = self.bbox_roi_extractor(
|
| 289 |
+
x[:self.bbox_roi_extractor.num_inputs], rois)
|
| 290 |
+
bbox_reg_feats = self.bbox_roi_extractor(
|
| 291 |
+
x[:self.bbox_roi_extractor.num_inputs],
|
| 292 |
+
rois,
|
| 293 |
+
roi_scale_factor=self.reg_roi_scale_factor)
|
| 294 |
+
if self.with_shared_head:
|
| 295 |
+
bbox_cls_feats = self.shared_head(bbox_cls_feats)
|
| 296 |
+
bbox_reg_feats = self.shared_head(bbox_reg_feats)
|
| 297 |
+
cls_score, bbox_pred = self.bbox_head(bbox_cls_feats, bbox_reg_feats)
|
| 298 |
+
|
| 299 |
+
bbox_results = dict(
|
| 300 |
+
cls_score=cls_score,
|
| 301 |
+
bbox_pred=bbox_pred,
|
| 302 |
+
bbox_feats=bbox_cls_feats)
|
| 303 |
+
return bbox_results
|
| 304 |
+
```
|
| 305 |
+
|
| 306 |
+
Last, the users need to add the module in
|
| 307 |
+
`mmdet/models/bbox_heads/__init__.py` and `mmdet/models/roi_heads/__init__.py` thus the corresponding registry could find and load them.
|
| 308 |
+
|
| 309 |
+
Alternatively, the users can add
|
| 310 |
+
|
| 311 |
+
```python
|
| 312 |
+
custom_imports=dict(
|
| 313 |
+
imports=['mmdet.models.roi_heads.double_roi_head', 'mmdet.models.roi_heads.bbox_heads.double_bbox_head'])
|
| 314 |
+
```
|
| 315 |
+
|
| 316 |
+
to the config file and achieve the same goal.
|
| 317 |
+
|
| 318 |
+
The config file of Double Head R-CNN is as the following
|
| 319 |
+
|
| 320 |
+
```python
|
| 321 |
+
_base_ = '../faster_rcnn/faster-rcnn_r50_fpn_1x_coco.py'
|
| 322 |
+
model = dict(
|
| 323 |
+
roi_head=dict(
|
| 324 |
+
type='DoubleHeadRoIHead',
|
| 325 |
+
reg_roi_scale_factor=1.3,
|
| 326 |
+
bbox_head=dict(
|
| 327 |
+
_delete_=True,
|
| 328 |
+
type='DoubleConvFCBBoxHead',
|
| 329 |
+
num_convs=4,
|
| 330 |
+
num_fcs=2,
|
| 331 |
+
in_channels=256,
|
| 332 |
+
conv_out_channels=1024,
|
| 333 |
+
fc_out_channels=1024,
|
| 334 |
+
roi_feat_size=7,
|
| 335 |
+
num_classes=80,
|
| 336 |
+
bbox_coder=dict(
|
| 337 |
+
type='DeltaXYWHBBoxCoder',
|
| 338 |
+
target_means=[0., 0., 0., 0.],
|
| 339 |
+
target_stds=[0.1, 0.1, 0.2, 0.2]),
|
| 340 |
+
reg_class_agnostic=False,
|
| 341 |
+
loss_cls=dict(
|
| 342 |
+
type='CrossEntropyLoss', use_sigmoid=False, loss_weight=2.0),
|
| 343 |
+
loss_bbox=dict(type='SmoothL1Loss', beta=1.0, loss_weight=2.0))))
|
| 344 |
+
|
| 345 |
+
```
|
| 346 |
+
|
| 347 |
+
Since MMDetection 2.0, the config system supports to inherit configs such that the users can focus on the modification.
|
| 348 |
+
The Double Head R-CNN mainly uses a new `DoubleHeadRoIHead` and a new `DoubleConvFCBBoxHead `, the arguments are set according to the `__init__` function of each module.
|
| 349 |
+
|
| 350 |
+
### Add new loss
|
| 351 |
+
|
| 352 |
+
Assume you want to add a new loss as `MyLoss`, for bounding box regression.
|
| 353 |
+
To add a new loss function, the users need implement it in `mmdet/models/losses/my_loss.py`.
|
| 354 |
+
The decorator `weighted_loss` enable the loss to be weighted for each element.
|
| 355 |
+
|
| 356 |
+
```python
|
| 357 |
+
import torch
|
| 358 |
+
import torch.nn as nn
|
| 359 |
+
|
| 360 |
+
from mmdet.registry import MODELS
|
| 361 |
+
from .utils import weighted_loss
|
| 362 |
+
|
| 363 |
+
@weighted_loss
|
| 364 |
+
def my_loss(pred, target):
|
| 365 |
+
assert pred.size() == target.size() and target.numel() > 0
|
| 366 |
+
loss = torch.abs(pred - target)
|
| 367 |
+
return loss
|
| 368 |
+
|
| 369 |
+
@MODELS.register_module()
|
| 370 |
+
class MyLoss(nn.Module):
|
| 371 |
+
|
| 372 |
+
def __init__(self, reduction='mean', loss_weight=1.0):
|
| 373 |
+
super(MyLoss, self).__init__()
|
| 374 |
+
self.reduction = reduction
|
| 375 |
+
self.loss_weight = loss_weight
|
| 376 |
+
|
| 377 |
+
def forward(self,
|
| 378 |
+
pred,
|
| 379 |
+
target,
|
| 380 |
+
weight=None,
|
| 381 |
+
avg_factor=None,
|
| 382 |
+
reduction_override=None):
|
| 383 |
+
assert reduction_override in (None, 'none', 'mean', 'sum')
|
| 384 |
+
reduction = (
|
| 385 |
+
reduction_override if reduction_override else self.reduction)
|
| 386 |
+
loss_bbox = self.loss_weight * my_loss(
|
| 387 |
+
pred, target, weight, reduction=reduction, avg_factor=avg_factor)
|
| 388 |
+
return loss_bbox
|
| 389 |
+
```
|
| 390 |
+
|
| 391 |
+
Then the users need to add it in the `mmdet/models/losses/__init__.py`.
|
| 392 |
+
|
| 393 |
+
```python
|
| 394 |
+
from .my_loss import MyLoss, my_loss
|
| 395 |
+
|
| 396 |
+
```
|
| 397 |
+
|
| 398 |
+
Alternatively, you can add
|
| 399 |
+
|
| 400 |
+
```python
|
| 401 |
+
custom_imports=dict(
|
| 402 |
+
imports=['mmdet.models.losses.my_loss'])
|
| 403 |
+
```
|
| 404 |
+
|
| 405 |
+
to the config file and achieve the same goal.
|
| 406 |
+
|
| 407 |
+
To use it, modify the `loss_xxx` field.
|
| 408 |
+
Since MyLoss is for regression, you need to modify the `loss_bbox` field in the head.
|
| 409 |
+
|
| 410 |
+
```python
|
| 411 |
+
loss_bbox=dict(type='MyLoss', loss_weight=1.0))
|
| 412 |
+
```
|
mmdet_code/SR-TOD/docs/en/advanced_guides/customize_runtime.md
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Customize Runtime Settings
|
| 2 |
+
|
| 3 |
+
## Customize optimization settings
|
| 4 |
+
|
| 5 |
+
Optimization related configuration is now all managed by `optim_wrapper` which usually has three fields: `optimizer`, `paramwise_cfg`, `clip_grad`, refer to [OptimWrapper](https://mmengine.readthedocs.io/en/latest/tutorials/optim_wrapper.md) for more detail. See the example below, where `Adamw` is used as an `optimizer`, the learning rate of the backbone is reduced by a factor of 10, and gradient clipping is added.
|
| 6 |
+
|
| 7 |
+
```python
|
| 8 |
+
optim_wrapper = dict(
|
| 9 |
+
type='OptimWrapper',
|
| 10 |
+
# optimizer
|
| 11 |
+
optimizer=dict(
|
| 12 |
+
type='AdamW',
|
| 13 |
+
lr=0.0001,
|
| 14 |
+
weight_decay=0.05,
|
| 15 |
+
eps=1e-8,
|
| 16 |
+
betas=(0.9, 0.999)),
|
| 17 |
+
|
| 18 |
+
# Parameter-level learning rate and weight decay settings
|
| 19 |
+
paramwise_cfg=dict(
|
| 20 |
+
custom_keys={
|
| 21 |
+
'backbone': dict(lr_mult=0.1, decay_mult=1.0),
|
| 22 |
+
},
|
| 23 |
+
norm_decay_mult=0.0),
|
| 24 |
+
|
| 25 |
+
# gradient clipping
|
| 26 |
+
clip_grad=dict(max_norm=0.01, norm_type=2))
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
### Customize optimizer supported by Pytorch
|
| 30 |
+
|
| 31 |
+
We already support to use all the optimizers implemented by PyTorch, and the only modification is to change the `optimizer` field in `optim_wrapper` field of config files. For example, if you want to use `ADAM` (note that the performance could drop a lot), the modification could be as the following.
|
| 32 |
+
|
| 33 |
+
```python
|
| 34 |
+
optim_wrapper = dict(
|
| 35 |
+
type='OptimWrapper',
|
| 36 |
+
optimizer=dict(type='Adam', lr=0.0003, weight_decay=0.0001))
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
To modify the learning rate of the model, the users only need to modify the `lr` in `optimizer`. The users can directly set arguments following the [API doc](https://pytorch.org/docs/stable/optim.html?highlight=optim#module-torch.optim) of PyTorch.
|
| 40 |
+
|
| 41 |
+
### Customize self-implemented optimizer
|
| 42 |
+
|
| 43 |
+
#### 1. Define a new optimizer
|
| 44 |
+
|
| 45 |
+
A customized optimizer could be defined as following.
|
| 46 |
+
|
| 47 |
+
Assume you want to add a optimizer named `MyOptimizer`, which has arguments `a`, `b`, and `c`.
|
| 48 |
+
You need to create a new directory named `mmdet/engine/optimizers`. And then implement the new optimizer in a file, e.g., in `mmdet/engine/optimizers/my_optimizer.py`:
|
| 49 |
+
|
| 50 |
+
```python
|
| 51 |
+
from mmdet.registry import OPTIMIZERS
|
| 52 |
+
from torch.optim import Optimizer
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
@OPTIMIZERS.register_module()
|
| 56 |
+
class MyOptimizer(Optimizer):
|
| 57 |
+
|
| 58 |
+
def __init__(self, a, b, c)
|
| 59 |
+
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
#### 2. Add the optimizer to registry
|
| 63 |
+
|
| 64 |
+
To find the above module defined above, this module should be imported into the main namespace at first. There are two options to achieve it.
|
| 65 |
+
|
| 66 |
+
- Modify `mmdet/engine/optimizers/__init__.py` to import it.
|
| 67 |
+
|
| 68 |
+
The newly defined module should be imported in `mmdet/engine/optimizers/__init__.py` so that the registry will find the new module and add it:
|
| 69 |
+
|
| 70 |
+
```python
|
| 71 |
+
from .my_optimizer import MyOptimizer
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
- Use `custom_imports` in the config to manually import it
|
| 75 |
+
|
| 76 |
+
```python
|
| 77 |
+
custom_imports = dict(imports=['mmdet.engine.optimizers.my_optimizer'], allow_failed_imports=False)
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
The module `mmdet.engine.optimizers.my_optimizer` will be imported at the beginning of the program and the class `MyOptimizer` is then automatically registered.
|
| 81 |
+
Note that only the package containing the class `MyOptimizer` should be imported.
|
| 82 |
+
`mmdet.engine.optimizers.my_optimizer.MyOptimizer` **cannot** be imported directly.
|
| 83 |
+
|
| 84 |
+
Actually users can use a totally different file directory structure using this importing method, as long as the module root can be located in `PYTHONPATH`.
|
| 85 |
+
|
| 86 |
+
#### 3. Specify the optimizer in the config file
|
| 87 |
+
|
| 88 |
+
Then you can use `MyOptimizer` in `optimizer` field in `optim_wrapper` field of config files. In the configs, the optimizers are defined by the field `optimizer` like the following:
|
| 89 |
+
|
| 90 |
+
```python
|
| 91 |
+
optim_wrapper = dict(
|
| 92 |
+
type='OptimWrapper',
|
| 93 |
+
optimizer=dict(type='SGD', lr=0.02, momentum=0.9, weight_decay=0.0001))
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
To use your own optimizer, the field can be changed to
|
| 97 |
+
|
| 98 |
+
```python
|
| 99 |
+
optim_wrapper = dict(
|
| 100 |
+
type='OptimWrapper',
|
| 101 |
+
optimizer=dict(type='MyOptimizer', a=a_value, b=b_value, c=c_value))
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
### Customize optimizer wrapper constructor
|
| 105 |
+
|
| 106 |
+
Some models may have some parameter-specific settings for optimization, e.g. weight decay for BatchNorm layers.
|
| 107 |
+
The users can do those fine-grained parameter tuning through customizing optimizer wrapper constructor.
|
| 108 |
+
|
| 109 |
+
```python
|
| 110 |
+
from mmengine.optim import DefaultOptiWrapperConstructor
|
| 111 |
+
|
| 112 |
+
from mmdet.registry import OPTIM_WRAPPER_CONSTRUCTORS
|
| 113 |
+
from .my_optimizer import MyOptimizer
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
@OPTIM_WRAPPER_CONSTRUCTORS.register_module()
|
| 117 |
+
class MyOptimizerWrapperConstructor(DefaultOptimWrapperConstructor):
|
| 118 |
+
|
| 119 |
+
def __init__(self,
|
| 120 |
+
optim_wrapper_cfg: dict,
|
| 121 |
+
paramwise_cfg: Optional[dict] = None):
|
| 122 |
+
|
| 123 |
+
def __call__(self, model: nn.Module) -> OptimWrapper:
|
| 124 |
+
|
| 125 |
+
return optim_wrapper
|
| 126 |
+
|
| 127 |
+
```
|
| 128 |
+
|
| 129 |
+
The default optimizer wrapper constructor is implemented [here](https://github.com/open-mmlab/mmengine/blob/main/mmengine/optim/optimizer/default_constructor.py#L18), which could also serve as a template for the new optimizer wrapper constructor.
|
| 130 |
+
|
| 131 |
+
### Additional settings
|
| 132 |
+
|
| 133 |
+
Tricks not implemented by the optimizer should be implemented through optimizer wrapper constructor (e.g., set parameter-wise learning rates) or hooks. We list some common settings that could stabilize the training or accelerate the training. Feel free to create PR, issue for more settings.
|
| 134 |
+
|
| 135 |
+
- __Use gradient clip to stabilize training__:
|
| 136 |
+
Some models need gradient clip to clip the gradients to stabilize the training process. An example is as below:
|
| 137 |
+
|
| 138 |
+
```python
|
| 139 |
+
optim_wrapper = dict(
|
| 140 |
+
_delete_=True, clip_grad=dict(max_norm=35, norm_type=2))
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
If your config inherits the base config which already sets the `optim_wrapper`, you might need `_delete_=True` to override the unnecessary settings. See the [config documentation](../user_guides/config.md) for more details.
|
| 144 |
+
|
| 145 |
+
- __Use momentum schedule to accelerate model convergence__:
|
| 146 |
+
We support momentum scheduler to modify model's momentum according to learning rate, which could make the model converge in a faster way.
|
| 147 |
+
Momentum scheduler is usually used with LR scheduler, for example, the following config is used in [3D detection](https://github.com/open-mmlab/mmdetection3d/blob/dev-1.x/configs/_base_/schedules/cyclic-20e.py) to accelerate convergence.
|
| 148 |
+
For more details, please refer to the implementation of [CosineAnnealingLR](https://github.com/open-mmlab/mmengine/blob/main/mmengine/optim/scheduler/lr_scheduler.py#L43) and [CosineAnnealingMomentum](https://github.com/open-mmlab/mmengine/blob/main/mmengine/optim/scheduler/momentum_scheduler.py#L71).
|
| 149 |
+
|
| 150 |
+
```python
|
| 151 |
+
param_scheduler = [
|
| 152 |
+
# learning rate scheduler
|
| 153 |
+
# During the first 8 epochs, learning rate increases from 0 to lr * 10
|
| 154 |
+
# during the next 12 epochs, learning rate decreases from lr * 10 to lr * 1e-4
|
| 155 |
+
dict(
|
| 156 |
+
type='CosineAnnealingLR',
|
| 157 |
+
T_max=8,
|
| 158 |
+
eta_min=lr * 10,
|
| 159 |
+
begin=0,
|
| 160 |
+
end=8,
|
| 161 |
+
by_epoch=True,
|
| 162 |
+
convert_to_iter_based=True),
|
| 163 |
+
dict(
|
| 164 |
+
type='CosineAnnealingLR',
|
| 165 |
+
T_max=12,
|
| 166 |
+
eta_min=lr * 1e-4,
|
| 167 |
+
begin=8,
|
| 168 |
+
end=20,
|
| 169 |
+
by_epoch=True,
|
| 170 |
+
convert_to_iter_based=True),
|
| 171 |
+
# momentum scheduler
|
| 172 |
+
# During the first 8 epochs, momentum increases from 0 to 0.85 / 0.95
|
| 173 |
+
# during the next 12 epochs, momentum increases from 0.85 / 0.95 to 1
|
| 174 |
+
dict(
|
| 175 |
+
type='CosineAnnealingMomentum',
|
| 176 |
+
T_max=8,
|
| 177 |
+
eta_min=0.85 / 0.95,
|
| 178 |
+
begin=0,
|
| 179 |
+
end=8,
|
| 180 |
+
by_epoch=True,
|
| 181 |
+
convert_to_iter_based=True),
|
| 182 |
+
dict(
|
| 183 |
+
type='CosineAnnealingMomentum',
|
| 184 |
+
T_max=12,
|
| 185 |
+
eta_min=1,
|
| 186 |
+
begin=8,
|
| 187 |
+
end=20,
|
| 188 |
+
by_epoch=True,
|
| 189 |
+
convert_to_iter_based=True)
|
| 190 |
+
]
|
| 191 |
+
```
|
| 192 |
+
|
| 193 |
+
## Customize training schedules
|
| 194 |
+
|
| 195 |
+
By default we use step learning rate with 1x schedule, this calls [MultiStepLR](https://github.com/open-mmlab/mmengine/blob/main/mmengine/optim/scheduler/lr_scheduler.py#L139) in MMEngine.
|
| 196 |
+
We support many other learning rate schedule [here](https://github.com/open-mmlab/mmengine/blob/main/mmengine/optim/scheduler/lr_scheduler.py), such as `CosineAnnealingLR` and `PolyLR` schedule. Here are some examples
|
| 197 |
+
|
| 198 |
+
- Poly schedule:
|
| 199 |
+
|
| 200 |
+
```python
|
| 201 |
+
param_scheduler = [
|
| 202 |
+
dict(
|
| 203 |
+
type='PolyLR',
|
| 204 |
+
power=0.9,
|
| 205 |
+
eta_min=1e-4,
|
| 206 |
+
begin=0,
|
| 207 |
+
end=8,
|
| 208 |
+
by_epoch=True)]
|
| 209 |
+
```
|
| 210 |
+
|
| 211 |
+
- ConsineAnnealing schedule:
|
| 212 |
+
|
| 213 |
+
```python
|
| 214 |
+
param_scheduler = [
|
| 215 |
+
dict(
|
| 216 |
+
type='CosineAnnealingLR',
|
| 217 |
+
T_max=8,
|
| 218 |
+
eta_min=lr * 1e-5,
|
| 219 |
+
begin=0,
|
| 220 |
+
end=8,
|
| 221 |
+
by_epoch=True)]
|
| 222 |
+
|
| 223 |
+
```
|
| 224 |
+
|
| 225 |
+
## Customize train loop
|
| 226 |
+
|
| 227 |
+
By default, `EpochBasedTrainLoop` is used in `train_cfg` and validation is done after every train epoch, as follows.
|
| 228 |
+
|
| 229 |
+
```python
|
| 230 |
+
train_cfg = dict(type='EpochBasedTrainLoop', max_epochs=12, val_begin=1, val_interval=1)
|
| 231 |
+
```
|
| 232 |
+
|
| 233 |
+
Actually, both [`IterBasedTrainLoop`](https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/loops.py#L183%5D) and [`EpochBasedTrainLoop`](https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/loops.py#L18) support dynamical interval, see the following example.
|
| 234 |
+
|
| 235 |
+
```python
|
| 236 |
+
# Before 365001th iteration, we do evaluation every 5000 iterations.
|
| 237 |
+
# After 365000th iteration, we do evaluation every 368750 iterations,
|
| 238 |
+
# which means that we do evaluation at the end of training.
|
| 239 |
+
|
| 240 |
+
interval = 5000
|
| 241 |
+
max_iters = 368750
|
| 242 |
+
dynamic_intervals = [(max_iters // interval * interval + 1, max_iters)]
|
| 243 |
+
train_cfg = dict(
|
| 244 |
+
type='IterBasedTrainLoop',
|
| 245 |
+
max_iters=max_iters,
|
| 246 |
+
val_interval=interval,
|
| 247 |
+
dynamic_intervals=dynamic_intervals)
|
| 248 |
+
```
|
| 249 |
+
|
| 250 |
+
## Customize hooks
|
| 251 |
+
|
| 252 |
+
### Customize self-implemented hooks
|
| 253 |
+
|
| 254 |
+
#### 1. Implement a new hook
|
| 255 |
+
|
| 256 |
+
MMEngine provides many useful [hooks](https://mmengine.readthedocs.io/en/latest/tutorials/hooks.html), but there are some occasions when the users might need to implement a new hook. MMDetection supports customized hooks in training in v3.0 . Thus the users could implement a hook directly in mmdet or their mmdet-based codebases and use the hook by only modifying the config in training.
|
| 257 |
+
Here we give an example of creating a new hook in mmdet and using it in training.
|
| 258 |
+
|
| 259 |
+
```python
|
| 260 |
+
from mmengine.hooks import Hook
|
| 261 |
+
from mmdet.registry import HOOKS
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
@HOOKS.register_module()
|
| 265 |
+
class MyHook(Hook):
|
| 266 |
+
|
| 267 |
+
def __init__(self, a, b):
|
| 268 |
+
|
| 269 |
+
def before_run(self, runner) -> None:
|
| 270 |
+
|
| 271 |
+
def after_run(self, runner) -> None:
|
| 272 |
+
|
| 273 |
+
def before_train(self, runner) -> None:
|
| 274 |
+
|
| 275 |
+
def after_train(self, runner) -> None:
|
| 276 |
+
|
| 277 |
+
def before_train_epoch(self, runner) -> None:
|
| 278 |
+
|
| 279 |
+
def after_train_epoch(self, runner) -> None:
|
| 280 |
+
|
| 281 |
+
def before_train_iter(self,
|
| 282 |
+
runner,
|
| 283 |
+
batch_idx: int,
|
| 284 |
+
data_batch: DATA_BATCH = None) -> None:
|
| 285 |
+
|
| 286 |
+
def after_train_iter(self,
|
| 287 |
+
runner,
|
| 288 |
+
batch_idx: int,
|
| 289 |
+
data_batch: DATA_BATCH = None,
|
| 290 |
+
outputs: Optional[dict] = None) -> None:
|
| 291 |
+
```
|
| 292 |
+
|
| 293 |
+
Depending on the functionality of the hook, the users need to specify what the hook will do at each stage of the training in `before_run`, `after_run`, `before_train`, `after_train` , `before_train_epoch`, `after_train_epoch`, `before_train_iter`, and `after_train_iter`. There are more points where hooks can be inserted, refer to [base hook class](https://github.com/open-mmlab/mmengine/blob/main/mmengine/hooks/hook.py#L9) for more detail.
|
| 294 |
+
|
| 295 |
+
#### 2. Register the new hook
|
| 296 |
+
|
| 297 |
+
Then we need to make `MyHook` imported. Assuming the file is in `mmdet/engine/hooks/my_hook.py` there are two ways to do that:
|
| 298 |
+
|
| 299 |
+
- Modify `mmdet/engine/hooks/__init__.py` to import it.
|
| 300 |
+
|
| 301 |
+
The newly defined module should be imported in `mmdet/engine/hooks/__init__.py` so that the registry will find the new module and add it:
|
| 302 |
+
|
| 303 |
+
```python
|
| 304 |
+
from .my_hook import MyHook
|
| 305 |
+
```
|
| 306 |
+
|
| 307 |
+
- Use `custom_imports` in the config to manually import it
|
| 308 |
+
|
| 309 |
+
```python
|
| 310 |
+
custom_imports = dict(imports=['mmdet.engine.hooks.my_hook'], allow_failed_imports=False)
|
| 311 |
+
```
|
| 312 |
+
|
| 313 |
+
#### 3. Modify the config
|
| 314 |
+
|
| 315 |
+
```python
|
| 316 |
+
custom_hooks = [
|
| 317 |
+
dict(type='MyHook', a=a_value, b=b_value)
|
| 318 |
+
]
|
| 319 |
+
```
|
| 320 |
+
|
| 321 |
+
You can also set the priority of the hook by adding key `priority` to `'NORMAL'` or `'HIGHEST'` as below
|
| 322 |
+
|
| 323 |
+
```python
|
| 324 |
+
custom_hooks = [
|
| 325 |
+
dict(type='MyHook', a=a_value, b=b_value, priority='NORMAL')
|
| 326 |
+
]
|
| 327 |
+
```
|
| 328 |
+
|
| 329 |
+
By default the hook's priority is set as `NORMAL` during registration.
|
| 330 |
+
|
| 331 |
+
### Use hooks implemented in MMDetection
|
| 332 |
+
|
| 333 |
+
If the hook is already implemented in MMDectection, you can directly modify the config to use the hook as below
|
| 334 |
+
|
| 335 |
+
#### Example: `NumClassCheckHook`
|
| 336 |
+
|
| 337 |
+
We implement a customized hook named [NumClassCheckHook](../../../mmdet/engine/hooks/num_class_check_hook.py) to check whether the `num_classes` in head matches the length of `classes` in the metainfo of `dataset`.
|
| 338 |
+
|
| 339 |
+
We set it in [default_runtime.py](../../../configs/_base_/default_runtime.py).
|
| 340 |
+
|
| 341 |
+
```python
|
| 342 |
+
custom_hooks = [dict(type='NumClassCheckHook')]
|
| 343 |
+
```
|
| 344 |
+
|
| 345 |
+
### Modify default runtime hooks
|
| 346 |
+
|
| 347 |
+
There are some common hooks that are registered through `default_hooks`, they are
|
| 348 |
+
|
| 349 |
+
- `IterTimerHook`: A hook that logs 'data_time' for loading data and 'time' for a model train step.
|
| 350 |
+
- `LoggerHook`: A hook that Collect logs from different components of `Runner` and write them to terminal, JSON file, tensorboard and wandb .etc.
|
| 351 |
+
- `ParamSchedulerHook`: A hook to update some hyper-parameters in optimizer, e.g., learning rate and momentum.
|
| 352 |
+
- `CheckpointHook`: A hook that saves checkpoints periodically.
|
| 353 |
+
- `DistSamplerSeedHook`: A hook that sets the seed for sampler and batch_sampler.
|
| 354 |
+
- `DetVisualizationHook`: A hook used to visualize validation and testing process prediction results.
|
| 355 |
+
|
| 356 |
+
`IterTimerHook`, `ParamSchedulerHook` and `DistSamplerSeedHook` are simple and no need to be modified usually, so here we reveals how what we can do with `LoggerHook`, `CheckpointHook` and `DetVisualizationHook`.
|
| 357 |
+
|
| 358 |
+
#### CheckpointHook
|
| 359 |
+
|
| 360 |
+
Except saving checkpoints periodically, [`CheckpointHook`](https://github.com/open-mmlab/mmengine/blob/main/mmengine/hooks/checkpoint_hook.py#L19) provides other options such as `max_keep_ckpts`, `save_optimizer` and etc. The users could set `max_keep_ckpts` to only save small number of checkpoints or decide whether to store state dict of optimizer by `save_optimizer`. More details of the arguments are [here](https://github.com/open-mmlab/mmengine/blob/main/mmengine/hooks/checkpoint_hook.py#L19)
|
| 361 |
+
|
| 362 |
+
```python
|
| 363 |
+
default_hooks = dict(
|
| 364 |
+
checkpoint=dict(
|
| 365 |
+
type='CheckpointHook',
|
| 366 |
+
interval=1,
|
| 367 |
+
max_keep_ckpts=3,
|
| 368 |
+
save_optimizer=True))
|
| 369 |
+
```
|
| 370 |
+
|
| 371 |
+
#### LoggerHook
|
| 372 |
+
|
| 373 |
+
The `LoggerHook` enables to set intervals. And the detail usages can be found in the [docstring](https://github.com/open-mmlab/mmengine/blob/main/mmengine/hooks/logger_hook.py#L18).
|
| 374 |
+
|
| 375 |
+
```python
|
| 376 |
+
default_hooks = dict(logger=dict(type='LoggerHook', interval=50))
|
| 377 |
+
```
|
| 378 |
+
|
| 379 |
+
#### DetVisualizationHook
|
| 380 |
+
|
| 381 |
+
`DetVisualizationHook` use `DetLocalVisualizer` to visualize prediction results, and `DetLocalVisualizer` current supports different backends, e.g., `TensorboardVisBackend` and `WandbVisBackend` (see [docstring](https://github.com/open-mmlab/mmengine/blob/main/mmengine/visualization/vis_backend.py) for more detail). The users could add multi backbends to do visualization, as follows.
|
| 382 |
+
|
| 383 |
+
```python
|
| 384 |
+
default_hooks = dict(
|
| 385 |
+
visualization=dict(type='DetVisualizationHook', draw=True))
|
| 386 |
+
|
| 387 |
+
vis_backends = [dict(type='LocalVisBackend'),
|
| 388 |
+
dict(type='TensorboardVisBackend')]
|
| 389 |
+
visualizer = dict(
|
| 390 |
+
type='DetLocalVisualizer', vis_backends=vis_backends, name='visualizer')
|
| 391 |
+
```
|
mmdet_code/SR-TOD/docs/en/advanced_guides/customize_transforms.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Customize Data Pipelines
|
| 2 |
+
|
| 3 |
+
1. Write a new transform in a file, e.g., in `my_pipeline.py`. It takes a dict as input and returns a dict.
|
| 4 |
+
|
| 5 |
+
```python
|
| 6 |
+
import random
|
| 7 |
+
from mmcv.transforms import BaseTransform
|
| 8 |
+
from mmdet.registry import TRANSFORMS
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@TRANSFORMS.register_module()
|
| 12 |
+
class MyTransform(BaseTransform):
|
| 13 |
+
"""Add your transform
|
| 14 |
+
|
| 15 |
+
Args:
|
| 16 |
+
p (float): Probability of shifts. Default 0.5.
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
def __init__(self, prob=0.5):
|
| 20 |
+
self.prob = prob
|
| 21 |
+
|
| 22 |
+
def transform(self, results):
|
| 23 |
+
if random.random() > self.prob:
|
| 24 |
+
results['dummy'] = True
|
| 25 |
+
return results
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
2. Import and use the pipeline in your config file.
|
| 29 |
+
Make sure the import is relative to where your train script is located.
|
| 30 |
+
|
| 31 |
+
```python
|
| 32 |
+
custom_imports = dict(imports=['path.to.my_pipeline'], allow_failed_imports=False)
|
| 33 |
+
|
| 34 |
+
train_pipeline = [
|
| 35 |
+
dict(type='LoadImageFromFile'),
|
| 36 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
| 37 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
| 38 |
+
dict(type='RandomFlip', prob=0.5),
|
| 39 |
+
dict(type='MyTransform', prob=0.2),
|
| 40 |
+
dict(type='PackDetInputs')
|
| 41 |
+
]
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
3. Visualize the output of your transforms pipeline
|
| 45 |
+
|
| 46 |
+
To visualize the output of your transforms pipeline, `tools/misc/browse_dataset.py`
|
| 47 |
+
can help the user to browse a detection dataset (both images and bounding box annotations)
|
| 48 |
+
visually, or save the image to a designated directory. More details can refer to
|
| 49 |
+
[visualization documentation](../user_guides/visualization.md)
|
mmdet_code/SR-TOD/docs/en/advanced_guides/data_flow.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# Data Flow
|
mmdet_code/SR-TOD/docs/en/advanced_guides/datasets.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# Datasets
|
mmdet_code/SR-TOD/docs/en/advanced_guides/engine.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# Engine
|
mmdet_code/SR-TOD/docs/en/advanced_guides/evaluation.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# Evaluation
|
mmdet_code/SR-TOD/docs/en/advanced_guides/how_to.md
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
This tutorial collects answers to any `How to xxx with MMDetection`. Feel free to update this doc if you meet new questions about `How to` and find the answers!
|
| 2 |
+
|
| 3 |
+
# Use backbone network through MMPretrain
|
| 4 |
+
|
| 5 |
+
The model registry in MMDet, MMPreTrain, MMSeg all inherit from the root registry in MMEngine. This allows these repositories to directly use the modules already implemented by each other. Therefore, users can use backbone networks from MMPretrain in MMDetection without implementing a network that already exists in MMPretrain.
|
| 6 |
+
|
| 7 |
+
## Use backbone network implemented in MMPretrain
|
| 8 |
+
|
| 9 |
+
Suppose you want to use `MobileNetV3-small` as the backbone network of `RetinaNet`, the example config is as the following.
|
| 10 |
+
|
| 11 |
+
```python
|
| 12 |
+
_base_ = [
|
| 13 |
+
'../_base_/models/retinanet_r50_fpn.py',
|
| 14 |
+
'../_base_/datasets/coco_detection.py',
|
| 15 |
+
'../_base_/schedules/schedule_1x.py', '../_base_/default_runtime.py'
|
| 16 |
+
]
|
| 17 |
+
# please install mmpretrain
|
| 18 |
+
# import mmpretrain.models to trigger register_module in mmpretrain
|
| 19 |
+
custom_imports = dict(imports=['mmpretrain.models'], allow_failed_imports=False)
|
| 20 |
+
pretrained = 'https://download.openmmlab.com/mmclassification/v0/mobilenet_v3/convert/mobilenet_v3_small-8427ecf0.pth'
|
| 21 |
+
model = dict(
|
| 22 |
+
backbone=dict(
|
| 23 |
+
_delete_=True, # Delete the backbone field in _base_
|
| 24 |
+
type='mmpretrain.MobileNetV3', # Using MobileNetV3 from mmpretrain
|
| 25 |
+
arch='small',
|
| 26 |
+
out_indices=(3, 8, 11), # Modify out_indices
|
| 27 |
+
init_cfg=dict(
|
| 28 |
+
type='Pretrained',
|
| 29 |
+
checkpoint=pretrained,
|
| 30 |
+
prefix='backbone.')), # The pre-trained weights of backbone network in mmpretrain have prefix='backbone.'. The prefix in the keys will be removed so that these weights can be normally loaded.
|
| 31 |
+
# Modify in_channels
|
| 32 |
+
neck=dict(in_channels=[24, 48, 96], start_level=0))
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
## Use backbone network in TIMM through MMPretrain
|
| 36 |
+
|
| 37 |
+
MMPretrain also provides a wrapper for the PyTorch Image Models (timm) backbone network, users can directly use the backbone network in timm through MMPretrain. Suppose you want to use [EfficientNet-B1](../../../configs/timm_example/retinanet_timm-efficientnet-b1_fpn_1x_coco.py) as the backbone network of RetinaNet, the example config is as the following.
|
| 38 |
+
|
| 39 |
+
```python
|
| 40 |
+
# https://github.com/open-mmlab/mmdetection/blob/main/configs/timm_example/retinanet_timm-efficientnet-b1_fpn_1x_coco.py
|
| 41 |
+
|
| 42 |
+
_base_ = [
|
| 43 |
+
'../_base_/models/retinanet_r50_fpn.py',
|
| 44 |
+
'../_base_/datasets/coco_detection.py',
|
| 45 |
+
'../_base_/schedules/schedule_1x.py', '../_base_/default_runtime.py'
|
| 46 |
+
]
|
| 47 |
+
|
| 48 |
+
# please install mmpretrain
|
| 49 |
+
# import mmpretrain.models to trigger register_module in mmpretrain
|
| 50 |
+
custom_imports = dict(imports=['mmpretrain.models'], allow_failed_imports=False)
|
| 51 |
+
model = dict(
|
| 52 |
+
backbone=dict(
|
| 53 |
+
_delete_=True, # Delete the backbone field in _base_
|
| 54 |
+
type='mmpretrain.TIMMBackbone', # Using timm from mmpretrain
|
| 55 |
+
model_name='efficientnet_b1',
|
| 56 |
+
features_only=True,
|
| 57 |
+
pretrained=True,
|
| 58 |
+
out_indices=(1, 2, 3, 4)), # Modify out_indices
|
| 59 |
+
neck=dict(in_channels=[24, 40, 112, 320])) # Modify in_channels
|
| 60 |
+
|
| 61 |
+
optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0001)
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
`type='mmpretrain.TIMMBackbone'` means use the `TIMMBackbone` class from MMPretrain in MMDetection, and the model used is `EfficientNet-B1`, where `mmpretrain` means the MMPretrain repo and `TIMMBackbone` means the TIMMBackbone wrapper implemented in MMPretrain.
|
| 65 |
+
|
| 66 |
+
For the principle of the Hierarchy Registry, please refer to the [MMEngine document](https://github.com/open-mmlab/mmengine/blob/main/docs/en/tutorials/config.md). For how to use other backbones in MMPretrain, you can refer to the [MMPretrain document](https://mmpretrain.readthedocs.io/en/latest/user_guides/config.html).
|
| 67 |
+
|
| 68 |
+
# Use Mosaic augmentation
|
| 69 |
+
|
| 70 |
+
If you want to use `Mosaic` in training, please make sure that you use `MultiImageMixDataset` at the same time. Taking the 'Faster R-CNN' algorithm as an example, you should modify the values of `train_pipeline` and `train_dataset` in the config as below:
|
| 71 |
+
|
| 72 |
+
```python
|
| 73 |
+
# Open configs/faster_rcnn/faster-rcnn_r50_fpn_1x_coco.py directly and add the following fields
|
| 74 |
+
data_root = 'data/coco/'
|
| 75 |
+
dataset_type = 'CocoDataset'
|
| 76 |
+
img_scale=(1333, 800)
|
| 77 |
+
|
| 78 |
+
train_pipeline = [
|
| 79 |
+
dict(type='Mosaic', img_scale=img_scale, pad_val=114.0),
|
| 80 |
+
dict(
|
| 81 |
+
type='RandomAffine',
|
| 82 |
+
scaling_ratio_range=(0.1, 2),
|
| 83 |
+
border=(-img_scale[0] // 2, -img_scale[1] // 2)), # The image will be enlarged by 4 times after Mosaic processing,so we use affine transformation to restore the image size.
|
| 84 |
+
dict(type='RandomFlip', prob=0.5),
|
| 85 |
+
dict(type='PackDetInputs')
|
| 86 |
+
]
|
| 87 |
+
|
| 88 |
+
train_dataset = dict(
|
| 89 |
+
_delete_ = True, # remove unnecessary Settings
|
| 90 |
+
type='MultiImageMixDataset',
|
| 91 |
+
dataset=dict(
|
| 92 |
+
type=dataset_type,
|
| 93 |
+
ann_file=data_root + 'annotations/instances_train2017.json',
|
| 94 |
+
img_prefix=data_root + 'train2017/',
|
| 95 |
+
pipeline=[
|
| 96 |
+
dict(type='LoadImageFromFile'),
|
| 97 |
+
dict(type='LoadAnnotations', with_bbox=True)
|
| 98 |
+
],
|
| 99 |
+
filter_empty_gt=False,
|
| 100 |
+
),
|
| 101 |
+
pipeline=train_pipeline
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
data = dict(
|
| 105 |
+
train=train_dataset
|
| 106 |
+
)
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
# Unfreeze backbone network after freezing the backbone in the config
|
| 110 |
+
|
| 111 |
+
If you have freezed the backbone network in the config and want to unfreeze it after some epoches, you can write a hook function to do it. Taking the Faster R-CNN with the resnet backbone as an example, you can freeze one stage of the backbone network and add a `custom_hooks` in the config as below:
|
| 112 |
+
|
| 113 |
+
```python
|
| 114 |
+
_base_ = [
|
| 115 |
+
'../_base_/models/faster-rcnn_r50_fpn.py',
|
| 116 |
+
'../_base_/datasets/coco_detection.py',
|
| 117 |
+
'../_base_/schedules/schedule_1x.py', '../_base_/default_runtime.py'
|
| 118 |
+
]
|
| 119 |
+
model = dict(
|
| 120 |
+
# freeze one stage of the backbone network.
|
| 121 |
+
backbone=dict(frozen_stages=1),
|
| 122 |
+
)
|
| 123 |
+
custom_hooks = [dict(type="UnfreezeBackboneEpochBasedHook", unfreeze_epoch=1)]
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
Meanwhile write the hook class `UnfreezeBackboneEpochBasedHook` in `mmdet/core/hook/unfreeze_backbone_epoch_based_hook.py`
|
| 127 |
+
|
| 128 |
+
```python
|
| 129 |
+
from mmengine.model import is_model_wrapper
|
| 130 |
+
from mmengine.hooks import Hook
|
| 131 |
+
from mmdet.registry import HOOKS
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
@HOOKS.register_module()
|
| 135 |
+
class UnfreezeBackboneEpochBasedHook(Hook):
|
| 136 |
+
"""Unfreeze backbone network Hook.
|
| 137 |
+
|
| 138 |
+
Args:
|
| 139 |
+
unfreeze_epoch (int): The epoch unfreezing the backbone network.
|
| 140 |
+
"""
|
| 141 |
+
|
| 142 |
+
def __init__(self, unfreeze_epoch=1):
|
| 143 |
+
self.unfreeze_epoch = unfreeze_epoch
|
| 144 |
+
|
| 145 |
+
def before_train_epoch(self, runner):
|
| 146 |
+
# Unfreeze the backbone network.
|
| 147 |
+
# Only valid for resnet.
|
| 148 |
+
if runner.epoch == self.unfreeze_epoch:
|
| 149 |
+
model = runner.model
|
| 150 |
+
if is_model_wrapper(model):
|
| 151 |
+
model = model.module
|
| 152 |
+
backbone = model.backbone
|
| 153 |
+
if backbone.frozen_stages >= 0:
|
| 154 |
+
if backbone.deep_stem:
|
| 155 |
+
backbone.stem.train()
|
| 156 |
+
for param in backbone.stem.parameters():
|
| 157 |
+
param.requires_grad = True
|
| 158 |
+
else:
|
| 159 |
+
backbone.norm1.train()
|
| 160 |
+
for m in [backbone.conv1, backbone.norm1]:
|
| 161 |
+
for param in m.parameters():
|
| 162 |
+
param.requires_grad = True
|
| 163 |
+
|
| 164 |
+
for i in range(1, backbone.frozen_stages + 1):
|
| 165 |
+
m = getattr(backbone, f'layer{i}')
|
| 166 |
+
m.train()
|
| 167 |
+
for param in m.parameters():
|
| 168 |
+
param.requires_grad = True
|
| 169 |
+
```
|
| 170 |
+
|
| 171 |
+
# Get the channels of a new backbone
|
| 172 |
+
|
| 173 |
+
If you want to get the channels of a new backbone, you can build this backbone alone and input a pseudo image to get each stage output.
|
| 174 |
+
|
| 175 |
+
Take `ResNet` as an example:
|
| 176 |
+
|
| 177 |
+
```python
|
| 178 |
+
from mmdet.models import ResNet
|
| 179 |
+
import torch
|
| 180 |
+
self = ResNet(depth=18)
|
| 181 |
+
self.eval()
|
| 182 |
+
inputs = torch.rand(1, 3, 32, 32)
|
| 183 |
+
level_outputs = self.forward(inputs)
|
| 184 |
+
for level_out in level_outputs:
|
| 185 |
+
print(tuple(level_out.shape))
|
| 186 |
+
|
| 187 |
+
```
|
| 188 |
+
|
| 189 |
+
Output of the above script is as below:
|
| 190 |
+
|
| 191 |
+
```python
|
| 192 |
+
(1, 64, 8, 8)
|
| 193 |
+
(1, 128, 4, 4)
|
| 194 |
+
(1, 256, 2, 2)
|
| 195 |
+
(1, 512, 1, 1)
|
| 196 |
+
```
|
| 197 |
+
|
| 198 |
+
Users can get the channels of the new backbone by Replacing the `ResNet(depth=18)` in this script with their customized backbone.
|
| 199 |
+
|
| 200 |
+
# Use Detectron2 Model in MMDetection
|
| 201 |
+
|
| 202 |
+
Users can use Detectron2Wrapper to run Detectron2's model in MMDetection. We provide examples of [Faster R-CNN](../../../configs/misc/d2_faster-rcnn_r50-caffe_fpn_ms-90k_coco.py),
|
| 203 |
+
[Mask R-CNN](../../../configs/misc/d2_mask-rcnn_r50-caffe_fpn_ms-90k_coco.py), and [RetinaNet](../../../configs/misc/d2_retinanet_r50-caffe_fpn_ms-90k_coco.py) in MMDetection.
|
| 204 |
+
|
| 205 |
+
The algorithm components in config file should be the same as those of in Detectron2. During setup, we will first initialize the default settings, which can be found in [Detectron2](https://github.com/facebookresearch/detectron2/blob/main/detectron2/config/defaults.py).
|
| 206 |
+
Then, the settings in config file will overwrite the default settings and the model will be built with these settings.
|
| 207 |
+
The input data will first convert to Detectron2's type and feed into Detectron2's model.
|
| 208 |
+
During inference the results calculate from Detectron2's model will reconvert back to the MMDetection's type.
|
| 209 |
+
|
| 210 |
+
## Use Detectron2's pre-trained weights
|
| 211 |
+
|
| 212 |
+
The weight initialization in `Detectron2Wrapper` will not use the logic of MMDetection. Users can set `model.d2_detector.weights=xxx` to load pre-trained weights.
|
| 213 |
+
For example, we can use `model.d2_detector.weights='detectron2://ImageNetPretrained/MSRA/R-50.pkl'` to load the pre-trained ResNet-50 or use
|
| 214 |
+
`model.d2_detector.weights='detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x/137260431/model_final_a54504.pkl'` to load the pre-trained Mask R-CNN weights proposed in Detectron2.
|
| 215 |
+
|
| 216 |
+
**Note:** Detectron2's pretrained model cannot be loaded directly by using `load_from`, it should be first converted via `tools/model_converters/detectron2_to_mmdet.py`
|
| 217 |
+
|
| 218 |
+
For inference of released detectron2 checkpoints, users should first use `tools/model_converters/detectron2_to_mmdet.py` to convert Detectron2 checkpoint to MMDetection.
|
| 219 |
+
|
| 220 |
+
```shell
|
| 221 |
+
python tools/model_converters/detectron2_to_mmdet.py ${Detectron2 ckpt path} ${MMDetectron ckpt path}
|
| 222 |
+
```
|
mmdet_code/SR-TOD/docs/en/advanced_guides/index.rst
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Basic Concepts
|
| 2 |
+
***************
|
| 3 |
+
|
| 4 |
+
.. toctree::
|
| 5 |
+
:maxdepth: 1
|
| 6 |
+
|
| 7 |
+
data_flow.md
|
| 8 |
+
structures.md
|
| 9 |
+
models.md
|
| 10 |
+
datasets.md
|
| 11 |
+
transforms.md
|
| 12 |
+
evaluation.md
|
| 13 |
+
engine.md
|
| 14 |
+
conventions.md
|
| 15 |
+
|
| 16 |
+
Component Customization
|
| 17 |
+
************************
|
| 18 |
+
|
| 19 |
+
.. toctree::
|
| 20 |
+
:maxdepth: 1
|
| 21 |
+
|
| 22 |
+
customize_models.md
|
| 23 |
+
customize_losses.md
|
| 24 |
+
customize_dataset.md
|
| 25 |
+
customize_transforms.md
|
| 26 |
+
customize_runtime.md
|
| 27 |
+
|
| 28 |
+
How to
|
| 29 |
+
************************
|
| 30 |
+
|
| 31 |
+
.. toctree::
|
| 32 |
+
:maxdepth: 1
|
| 33 |
+
|
| 34 |
+
how_to.md
|
mmdet_code/SR-TOD/docs/en/advanced_guides/models.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# Models
|
mmdet_code/SR-TOD/docs/en/advanced_guides/structures.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# Structures
|
mmdet_code/SR-TOD/docs/en/advanced_guides/transforms.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Data Transforms (Need to update)
|
| 2 |
+
|
| 3 |
+
## Design of Data transforms pipeline
|
| 4 |
+
|
| 5 |
+
Following typical conventions, we use `Dataset` and `DataLoader` for data loading
|
| 6 |
+
with multiple workers. `Dataset` returns a dict of data items corresponding
|
| 7 |
+
the arguments of models' forward method.
|
| 8 |
+
|
| 9 |
+
The data transforms pipeline and the dataset is decomposed. Usually a dataset
|
| 10 |
+
defines how to process the annotations and a data transforms pipeline defines all the steps to prepare a data dict.
|
| 11 |
+
A pipeline consists of a sequence of data transforms. Each operation takes a dict as input and also output a dict for the next transform.
|
| 12 |
+
|
| 13 |
+
We present a classical pipeline in the following figure. The blue blocks are pipeline operations. With the pipeline going on, each operator can add new keys (marked as green) to the result dict or update the existing keys (marked as orange).
|
| 14 |
+

|
| 15 |
+
|
| 16 |
+
Here is a pipeline example for Faster R-CNN.
|
| 17 |
+
|
| 18 |
+
```python
|
| 19 |
+
train_pipeline = [ # Training data processing pipeline
|
| 20 |
+
dict(type='LoadImageFromFile', backend_args=backend_args), # First pipeline to load images from file path
|
| 21 |
+
dict(
|
| 22 |
+
type='LoadAnnotations', # Second pipeline to load annotations for current image
|
| 23 |
+
with_bbox=True), # Whether to use bounding box, True for detection
|
| 24 |
+
dict(
|
| 25 |
+
type='Resize', # Pipeline that resize the images and their annotations
|
| 26 |
+
scale=(1333, 800), # The largest scale of image
|
| 27 |
+
keep_ratio=True # Whether to keep the ratio between height and width
|
| 28 |
+
),
|
| 29 |
+
dict(
|
| 30 |
+
type='RandomFlip', # Augmentation pipeline that flip the images and their annotations
|
| 31 |
+
prob=0.5), # The probability to flip
|
| 32 |
+
dict(type='PackDetInputs') # Pipeline that formats the annotation data and decides which keys in the data should be packed into data_samples
|
| 33 |
+
]
|
| 34 |
+
test_pipeline = [ # Testing data processing pipeline
|
| 35 |
+
dict(type='LoadImageFromFile', backend_args=backend_args), # First pipeline to load images from file path
|
| 36 |
+
dict(type='Resize', scale=(1333, 800), keep_ratio=True), # Pipeline that resize the images
|
| 37 |
+
dict(
|
| 38 |
+
type='PackDetInputs', # Pipeline that formats the annotation data and decides which keys in the data should be packed into data_samples
|
| 39 |
+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
| 40 |
+
'scale_factor'))
|
| 41 |
+
]
|
| 42 |
+
```
|