Skip to content
Snippets Groups Projects
Commit f730b408 authored by simon wu's avatar simon wu Committed by Kai Chen
Browse files

Warning when skip image (#1010)

* Require an operation(Save or Show the results) when testing

* using parentheses

* Warning when skip image

* added parameter skip_img_without_anno for dataset

* print filename when warning
parent c829f054
No related branches found
No related tags found
No related merge requests found
import os.path as osp
import warnings
import mmcv
import numpy as np
......@@ -55,6 +56,7 @@ class CustomDataset(Dataset):
seg_scale_factor=1,
extra_aug=None,
resize_keep_ratio=True,
skip_img_without_anno=True,
test_mode=False):
# prefix of images path
self.img_prefix = img_prefix
......@@ -127,6 +129,7 @@ class CustomDataset(Dataset):
# image rescale if keep ratio
self.resize_keep_ratio = resize_keep_ratio
self.skip_img_without_anno = skip_img_without_anno
def __len__(self):
return len(self.img_infos)
......@@ -203,7 +206,9 @@ class CustomDataset(Dataset):
gt_bboxes_ignore = ann['bboxes_ignore']
# skip the image if there is no valid gt bbox
if len(gt_bboxes) == 0:
if len(gt_bboxes) == 0 and self.skip_img_without_anno:
warnings.warn('Skip the image "%s" that has no valid gt bbox' %
osp.join(self.img_prefix, img_info['filename']))
return None
# extra augmentation
......@@ -220,8 +225,8 @@ class CustomDataset(Dataset):
img = img.copy()
if self.with_seg:
gt_seg = mmcv.imread(
osp.join(self.seg_prefix, img_info['file_name'].replace(
'jpg', 'png')),
osp.join(self.seg_prefix,
img_info['file_name'].replace('jpg', 'png')),
flag='unchanged')
gt_seg = self.seg_transform(gt_seg.squeeze(), img_scale, flip)
gt_seg = mmcv.imrescale(
......@@ -230,8 +235,8 @@ class CustomDataset(Dataset):
if self.proposals is not None:
proposals = self.bbox_transform(proposals, img_shape, scale_factor,
flip)
proposals = np.hstack(
[proposals, scores]) if scores is not None else proposals
proposals = np.hstack([proposals, scores
]) if scores is not None else proposals
gt_bboxes = self.bbox_transform(gt_bboxes, img_shape, scale_factor,
flip)
if self.with_crowd:
......@@ -296,8 +301,8 @@ class CustomDataset(Dataset):
score = None
_proposal = self.bbox_transform(proposal, img_shape,
scale_factor, flip)
_proposal = np.hstack(
[_proposal, score]) if score is not None else _proposal
_proposal = np.hstack([_proposal, score
]) if score is not None else _proposal
_proposal = to_tensor(_proposal)
else:
_proposal = None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment