Skip to content

Commit 3170105

Browse files
zengzhaoyangZhaoyang Zeng
andauthored
add custom dataset example (#187)
Co-authored-by: Zhaoyang Zeng <zengzhaoyang@idea.edu.cn>
1 parent 969c616 commit 3170105

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

configs/common/data/custom.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import itertools
2+
3+
from omegaconf import OmegaConf
4+
5+
import detectron2.data.transforms as T
6+
from detectron2.config import LazyCall as L
7+
from detectron2.data import (
8+
build_detection_test_loader,
9+
build_detection_train_loader,
10+
get_detection_dataset_dicts,
11+
)
12+
from detectron2.data.datasets import register_coco_instances
13+
from detectron2.evaluation import COCOEvaluator
14+
15+
from detrex.data import DetrDatasetMapper
16+
17+
dataloader = OmegaConf.create()
18+
19+
register_coco_instances("my_dataset_train", {}, '/path/to/train.json', '/path/to/train/images')
20+
register_coco_instances("my_dataset_test", {}, '/path/to/test.json', '/path/to/test/images')
21+
22+
dataloader.train = L(build_detection_train_loader)(
23+
dataset=L(get_detection_dataset_dicts)(names="my_dataset_train"),
24+
mapper=L(DetrDatasetMapper)(
25+
augmentation=[
26+
L(T.RandomFlip)(),
27+
L(T.ResizeShortestEdge)(
28+
short_edge_length=(480, 512, 544, 576, 608, 640, 672, 704, 736, 768, 800),
29+
max_size=1333,
30+
sample_style="choice",
31+
),
32+
],
33+
augmentation_with_crop=[
34+
L(T.RandomFlip)(),
35+
L(T.ResizeShortestEdge)(
36+
short_edge_length=(400, 500, 600),
37+
sample_style="choice",
38+
),
39+
L(T.RandomCrop)(
40+
crop_type="absolute_range",
41+
crop_size=(384, 600),
42+
),
43+
L(T.ResizeShortestEdge)(
44+
short_edge_length=(480, 512, 544, 576, 608, 640, 672, 704, 736, 768, 800),
45+
max_size=1333,
46+
sample_style="choice",
47+
),
48+
],
49+
is_train=True,
50+
mask_on=False,
51+
img_format="RGB",
52+
),
53+
total_batch_size=16,
54+
num_workers=4,
55+
)
56+
57+
dataloader.test = L(build_detection_test_loader)(
58+
dataset=L(get_detection_dataset_dicts)(names="my_dataset_test", filter_empty=False),
59+
mapper=L(DetrDatasetMapper)(
60+
augmentation=[
61+
L(T.ResizeShortestEdge)(
62+
short_edge_length=800,
63+
max_size=1333,
64+
),
65+
],
66+
augmentation_with_crop=None,
67+
is_train=False,
68+
mask_on=False,
69+
img_format="RGB",
70+
),
71+
num_workers=4,
72+
)
73+
74+
dataloader.evaluator = L(COCOEvaluator)(
75+
dataset_name="${..test.dataset.names}",
76+
)

0 commit comments

Comments
 (0)