Upload coco_detection.py with huggingface_hub
Browse files- coco_detection.py +95 -0
coco_detection.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),
|
| 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/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',
|
| 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',
|
| 93 |
+
# format_only=True,
|
| 94 |
+
# ann_file=data_root + 'annotations/image_info_test-dev2017.json',
|
| 95 |
+
# outfile_prefix='./work_dirs/coco_detection/test')
|