Skip to content

Commit e33ecfe

Browse files
authored
Rename imgs_per_gpu to samples_per_gpu (open-mmlab#2404)
* rename api * Refactor (APIs): rename imgs_per_gpu to samples_per_gpu * Clean files * Refactor (infos): rename self.infos to self.data_infos
1 parent 913e099 commit e33ecfe

31 files changed

+70
-67
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,4 @@ work_dirs/
117117
# Pytorch
118118
*.pth
119119
*.py~
120+
*.sh~

configs/_base_/datasets/cityscapes_detection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
])
3030
]
3131
data = dict(
32-
imgs_per_gpu=1,
32+
samples_per_gpu=1,
3333
workers_per_gpu=2,
3434
train=dict(
3535
type='RepeatDataset',

configs/_base_/datasets/coco_detection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
])
2929
]
3030
data = dict(
31-
imgs_per_gpu=2,
31+
samples_per_gpu=2,
3232
workers_per_gpu=2,
3333
train=dict(
3434
type=dataset_type,

configs/_base_/datasets/voc0712.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
])
3030
]
3131
data = dict(
32-
imgs_per_gpu=2,
32+
samples_per_gpu=2,
3333
workers_per_gpu=2,
3434
train=dict(
3535
type='RepeatDataset',

configs/_base_/datasets/wider_face.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
])
4141
]
4242
data = dict(
43-
imgs_per_gpu=60,
43+
samples_per_gpu=60,
4444
workers_per_gpu=2,
4545
train=dict(
4646
type='RepeatDataset',

configs/fast_rcnn/fast_rcnn_r50_fpn_1x_coco.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
])
4040
]
4141
data = dict(
42-
imgs_per_gpu=2,
42+
samples_per_gpu=2,
4343
workers_per_gpu=2,
4444
train=dict(
4545
proposal_file=data_root + 'proposals/rpn_r50_fpn_1x_train2017.pkl',

configs/fcos/fcos_r101_caffe_fpn_gn-head_mstrain_640-800_4x4_2x_coco.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
])
3434
]
3535
data = dict(
36-
imgs_per_gpu=4,
36+
samples_per_gpu=4,
3737
workers_per_gpu=4,
3838
train=dict(pipeline=train_pipeline),
3939
val=dict(pipeline=test_pipeline),

configs/fcos/fcos_r50_caffe_fpn_gn-head_4x4_1x_coco.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
])
8686
]
8787
data = dict(
88-
imgs_per_gpu=4,
88+
samples_per_gpu=4,
8989
workers_per_gpu=4,
9090
train=dict(pipeline=train_pipeline),
9191
val=dict(pipeline=test_pipeline),

configs/fcos/fcos_x101_64x4d_fpn_gn-head_mstrain_640-800_4x2_2x_coco.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
])
4545
]
4646
data = dict(
47-
imgs_per_gpu=2,
47+
samples_per_gpu=2,
4848
workers_per_gpu=2,
4949
train=dict(pipeline=train_pipeline),
5050
val=dict(pipeline=test_pipeline),

configs/foveabox/fovea_r50_fpn_4x4_1x_coco.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@
4747
score_thr=0.05,
4848
nms=dict(type='nms', iou_thr=0.5),
4949
max_per_img=100)
50-
data = dict(imgs_per_gpu=4, workers_per_gpu=4)
50+
data = dict(samples_per_gpu=4, workers_per_gpu=4)
5151
# optimizer
5252
optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0001)

configs/htc/htc_x101_32x4d_fpn_16x1_20e_coco.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
norm_cfg=dict(type='BN', requires_grad=True),
1313
norm_eval=True,
1414
style='pytorch'))
15-
data = dict(imgs_per_gpu=1, workers_per_gpu=1)
15+
data = dict(samples_per_gpu=1, workers_per_gpu=1)
1616
# learning policy
1717
lr_config = dict(step=[16, 19])
1818
total_epochs = 20

configs/htc/htc_x101_64x4d_fpn_16x1_20e_coco.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
norm_cfg=dict(type='BN', requires_grad=True),
1313
norm_eval=True,
1414
style='pytorch'))
15-
data = dict(imgs_per_gpu=1, workers_per_gpu=1)
15+
data = dict(samples_per_gpu=1, workers_per_gpu=1)
1616
# learning policy
1717
lr_config = dict(step=[16, 19])
1818
total_epochs = 20

configs/htc/htc_x101_64x4d_fpn_dconv_c3-c5_mstrain_400_1400_16x1_20e_coco.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
keys=['img', 'gt_bboxes', 'gt_labels', 'gt_masks', 'gt_semantic_seg']),
3737
]
3838
data = dict(
39-
imgs_per_gpu=1, workers_per_gpu=1, train=dict(pipeline=train_pipeline))
39+
samples_per_gpu=1, workers_per_gpu=1, train=dict(pipeline=train_pipeline))
4040
# learning policy
4141
lr_config = dict(step=[16, 19])
4242
total_epochs = 20

configs/nas_fpn/retinanet_r50_fpn_crop640_50e_coco.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
])
5757
]
5858
data = dict(
59-
imgs_per_gpu=8,
59+
samples_per_gpu=8,
6060
workers_per_gpu=4,
6161
train=dict(pipeline=train_pipeline),
6262
val=dict(pipeline=test_pipeline),

configs/nas_fpn/retinanet_r50_nasfpn_crop640_50e_coco.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
])
5656
]
5757
data = dict(
58-
imgs_per_gpu=8,
58+
samples_per_gpu=8,
5959
workers_per_gpu=4,
6060
train=dict(pipeline=train_pipeline),
6161
val=dict(pipeline=test_pipeline),

configs/pascal_voc/ssd300_voc0712.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
])
4646
]
4747
data = dict(
48-
imgs_per_gpu=8,
48+
samples_per_gpu=8,
4949
workers_per_gpu=3,
5050
train=dict(
5151
type='RepeatDataset', times=10, dataset=dict(pipeline=train_pipeline)),

configs/ssd/ssd300_coco.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
])
4545
]
4646
data = dict(
47-
imgs_per_gpu=8,
47+
samples_per_gpu=8,
4848
workers_per_gpu=3,
4949
train=dict(
5050
_delete_=True,

configs/ssd/ssd512_coco.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
])
5151
]
5252
data = dict(
53-
imgs_per_gpu=8,
53+
samples_per_gpu=8,
5454
workers_per_gpu=3,
5555
train=dict(
5656
_delete_=True,

mmdet/apis/test.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def multi_gpu_test(model, data_loader, tmpdir=None, gpu_collect=False):
5959
results.append(result)
6060

6161
if rank == 0:
62-
batch_size = data['img'][0].size(0)
62+
batch_size = (
63+
len(data['img_meta']._data)
64+
if 'img_meta' in data else data['img'][0].size(0))
6365
for _ in range(batch_size * world_size):
6466
prog_bar.update()
6567

mmdet/apis/train.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def _dist_train(model,
123123
data_loaders = [
124124
build_dataloader(
125125
ds,
126-
cfg.data.imgs_per_gpu,
126+
cfg.data.samples_per_gpu,
127127
cfg.data.workers_per_gpu,
128128
dist=True,
129129
seed=cfg.seed) for ds in dataset
@@ -167,7 +167,7 @@ def _dist_train(model,
167167
val_dataset = build_dataset(cfg.data.val, dict(test_mode=True))
168168
val_dataloader = build_dataloader(
169169
val_dataset,
170-
imgs_per_gpu=1,
170+
samples_per_gpu=1,
171171
workers_per_gpu=cfg.data.workers_per_gpu,
172172
dist=True,
173173
shuffle=False)
@@ -193,7 +193,7 @@ def _non_dist_train(model,
193193
data_loaders = [
194194
build_dataloader(
195195
ds,
196-
cfg.data.imgs_per_gpu,
196+
cfg.data.samples_per_gpu,
197197
cfg.data.workers_per_gpu,
198198
cfg.gpus,
199199
dist=False,
@@ -228,7 +228,7 @@ def _non_dist_train(model,
228228
val_dataset = build_dataset(cfg.data.val, dict(test_mode=True))
229229
val_dataloader = build_dataloader(
230230
val_dataset,
231-
imgs_per_gpu=1,
231+
samples_per_gpu=1,
232232
workers_per_gpu=cfg.data.workers_per_gpu,
233233
dist=False,
234234
shuffle=False)

mmdet/datasets/cityscapes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def _filter_imgs(self, min_size=32):
2525
"""Filter images too small or without ground truths."""
2626
valid_inds = []
2727
ids_with_ann = set(_['image_id'] for _ in self.coco.anns.values())
28-
for i, img_info in enumerate(self.img_infos):
28+
for i, img_info in enumerate(self.data_infos):
2929
img_id = img_info['id']
3030
ann_ids = self.coco.getAnnIds(imgIds=[img_id])
3131
ann_info = self.coco.loadAnns(ann_ids)
@@ -113,7 +113,7 @@ def results2txt(self, results, outfile_prefix):
113113
prog_bar = mmcv.ProgressBar(len(self))
114114
for idx in range(len(self)):
115115
result = results[idx]
116-
filename = self.img_infos[idx]['filename']
116+
filename = self.data_infos[idx]['filename']
117117
basename = osp.splitext(osp.basename(filename))[0]
118118
pred_txt = osp.join(outfile_prefix, basename + '_pred.txt')
119119

mmdet/datasets/coco.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,24 @@ def load_annotations(self, ann_file):
3636
self.cat_ids = self.coco.getCatIds()
3737
self.cat2label = {cat_id: i for i, cat_id in enumerate(self.cat_ids)}
3838
self.img_ids = self.coco.getImgIds()
39-
img_infos = []
39+
data_infos = []
4040
for i in self.img_ids:
4141
info = self.coco.loadImgs([i])[0]
4242
info['filename'] = info['file_name']
43-
img_infos.append(info)
44-
return img_infos
43+
data_infos.append(info)
44+
return data_infos
4545

4646
def get_ann_info(self, idx):
47-
img_id = self.img_infos[idx]['id']
47+
img_id = self.data_infos[idx]['id']
4848
ann_ids = self.coco.getAnnIds(imgIds=[img_id])
4949
ann_info = self.coco.loadAnns(ann_ids)
50-
return self._parse_ann_info(self.img_infos[idx], ann_info)
50+
return self._parse_ann_info(self.data_infos[idx], ann_info)
5151

5252
def _filter_imgs(self, min_size=32):
5353
"""Filter images too small or without ground truths."""
5454
valid_inds = []
5555
ids_with_ann = set(_['image_id'] for _ in self.coco.anns.values())
56-
for i, img_info in enumerate(self.img_infos):
56+
for i, img_info in enumerate(self.data_infos):
5757
if self.filter_empty_gt and self.img_ids[i] not in ids_with_ann:
5858
continue
5959
if min(img_info['width'], img_info['height']) >= min_size:

mmdet/datasets/custom.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ def __init__(self,
6464
self.proposal_file = osp.join(self.data_root,
6565
self.proposal_file)
6666
# load annotations (and proposals)
67-
self.img_infos = self.load_annotations(self.ann_file)
67+
self.data_infos = self.load_annotations(self.ann_file)
6868
if self.proposal_file is not None:
6969
self.proposals = self.load_proposals(self.proposal_file)
7070
else:
7171
self.proposals = None
7272
# filter images too small
7373
if not test_mode:
7474
valid_inds = self._filter_imgs()
75-
self.img_infos = [self.img_infos[i] for i in valid_inds]
75+
self.data_infos = [self.data_infos[i] for i in valid_inds]
7676
if self.proposals is not None:
7777
self.proposals = [self.proposals[i] for i in valid_inds]
7878
# set group flag for the sampler
@@ -82,7 +82,7 @@ def __init__(self,
8282
self.pipeline = Compose(pipeline)
8383

8484
def __len__(self):
85-
return len(self.img_infos)
85+
return len(self.data_infos)
8686

8787
def load_annotations(self, ann_file):
8888
return mmcv.load(ann_file)
@@ -91,7 +91,7 @@ def load_proposals(self, proposal_file):
9191
return mmcv.load(proposal_file)
9292

9393
def get_ann_info(self, idx):
94-
return self.img_infos[idx]['ann']
94+
return self.data_infos[idx]['ann']
9595

9696
def pre_pipeline(self, results):
9797
results['img_prefix'] = self.img_prefix
@@ -104,7 +104,7 @@ def pre_pipeline(self, results):
104104
def _filter_imgs(self, min_size=32):
105105
"""Filter images too small."""
106106
valid_inds = []
107-
for i, img_info in enumerate(self.img_infos):
107+
for i, img_info in enumerate(self.data_infos):
108108
if min(img_info['width'], img_info['height']) >= min_size:
109109
valid_inds.append(i)
110110
return valid_inds
@@ -117,7 +117,7 @@ def _set_group_flag(self):
117117
"""
118118
self.flag = np.zeros(len(self), dtype=np.uint8)
119119
for i in range(len(self)):
120-
img_info = self.img_infos[i]
120+
img_info = self.data_infos[i]
121121
if img_info['width'] / img_info['height'] > 1:
122122
self.flag[i] = 1
123123

@@ -136,7 +136,7 @@ def __getitem__(self, idx):
136136
return data
137137

138138
def prepare_train_img(self, idx):
139-
img_info = self.img_infos[idx]
139+
img_info = self.data_infos[idx]
140140
ann_info = self.get_ann_info(idx)
141141
results = dict(img_info=img_info, ann_info=ann_info)
142142
if self.proposals is not None:
@@ -145,7 +145,7 @@ def prepare_train_img(self, idx):
145145
return self.pipeline(results)
146146

147147
def prepare_test_img(self, idx):
148-
img_info = self.img_infos[idx]
148+
img_info = self.data_infos[idx]
149149
results = dict(img_info=img_info)
150150
if self.proposals is not None:
151151
results['proposals'] = self.proposals[idx]

mmdet/datasets/loader/build_loader.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
def build_dataloader(dataset,
22-
imgs_per_gpu,
22+
samples_per_gpu,
2323
workers_per_gpu,
2424
num_gpus=1,
2525
dist=True,
@@ -33,8 +33,8 @@ def build_dataloader(dataset,
3333
3434
Args:
3535
dataset (Dataset): A PyTorch dataset.
36-
imgs_per_gpu (int): Number of images on each GPU, i.e., batch size of
37-
each GPU.
36+
samples_per_gpu (int): Number of training samples on each GPU, i.e.,
37+
batch size of each GPU.
3838
workers_per_gpu (int): How many subprocesses to use for data loading
3939
for each GPU.
4040
num_gpus (int): Number of GPUs. Only used in non-distributed training.
@@ -51,16 +51,16 @@ def build_dataloader(dataset,
5151
# DistributedGroupSampler will definitely shuffle the data to satisfy
5252
# that images on each GPU are in the same group
5353
if shuffle:
54-
sampler = DistributedGroupSampler(dataset, imgs_per_gpu,
54+
sampler = DistributedGroupSampler(dataset, samples_per_gpu,
5555
world_size, rank)
5656
else:
5757
sampler = DistributedSampler(
5858
dataset, world_size, rank, shuffle=False)
59-
batch_size = imgs_per_gpu
59+
batch_size = samples_per_gpu
6060
num_workers = workers_per_gpu
6161
else:
62-
sampler = GroupSampler(dataset, imgs_per_gpu) if shuffle else None
63-
batch_size = num_gpus * imgs_per_gpu
62+
sampler = GroupSampler(dataset, samples_per_gpu) if shuffle else None
63+
batch_size = num_gpus * samples_per_gpu
6464
num_workers = num_gpus * workers_per_gpu
6565

6666
init_fn = partial(
@@ -72,7 +72,7 @@ def build_dataloader(dataset,
7272
batch_size=batch_size,
7373
sampler=sampler,
7474
num_workers=num_workers,
75-
collate_fn=partial(collate, samples_per_gpu=imgs_per_gpu),
75+
collate_fn=partial(collate, samples_per_gpu=samples_per_gpu),
7676
pin_memory=False,
7777
worker_init_fn=init_fn,
7878
**kwargs)

mmdet/datasets/wider_face.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self, **kwargs):
2020
super(WIDERFaceDataset, self).__init__(**kwargs)
2121

2222
def load_annotations(self, ann_file):
23-
img_infos = []
23+
data_infos = []
2424
img_ids = mmcv.list_from_file(ann_file)
2525
for img_id in img_ids:
2626
filename = '{}.jpg'.format(img_id)
@@ -32,11 +32,11 @@ def load_annotations(self, ann_file):
3232
width = int(size.find('width').text)
3333
height = int(size.find('height').text)
3434
folder = root.find('folder').text
35-
img_infos.append(
35+
data_infos.append(
3636
dict(
3737
id=img_id,
3838
filename=osp.join(folder, filename),
3939
width=width,
4040
height=height))
4141

42-
return img_infos
42+
return data_infos

0 commit comments

Comments
 (0)