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 os.path as osp
import warnings
import mmcv import mmcv
import numpy as np import numpy as np
...@@ -55,6 +56,7 @@ class CustomDataset(Dataset): ...@@ -55,6 +56,7 @@ class CustomDataset(Dataset):
seg_scale_factor=1, seg_scale_factor=1,
extra_aug=None, extra_aug=None,
resize_keep_ratio=True, resize_keep_ratio=True,
skip_img_without_anno=True,
test_mode=False): test_mode=False):
# prefix of images path # prefix of images path
self.img_prefix = img_prefix self.img_prefix = img_prefix
...@@ -127,6 +129,7 @@ class CustomDataset(Dataset): ...@@ -127,6 +129,7 @@ class CustomDataset(Dataset):
# image rescale if keep ratio # image rescale if keep ratio
self.resize_keep_ratio = resize_keep_ratio self.resize_keep_ratio = resize_keep_ratio
self.skip_img_without_anno = skip_img_without_anno
def __len__(self): def __len__(self):
return len(self.img_infos) return len(self.img_infos)
...@@ -203,7 +206,9 @@ class CustomDataset(Dataset): ...@@ -203,7 +206,9 @@ class CustomDataset(Dataset):
gt_bboxes_ignore = ann['bboxes_ignore'] gt_bboxes_ignore = ann['bboxes_ignore']
# skip the image if there is no valid gt bbox # 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 return None
# extra augmentation # extra augmentation
...@@ -220,8 +225,8 @@ class CustomDataset(Dataset): ...@@ -220,8 +225,8 @@ class CustomDataset(Dataset):
img = img.copy() img = img.copy()
if self.with_seg: if self.with_seg:
gt_seg = mmcv.imread( gt_seg = mmcv.imread(
osp.join(self.seg_prefix, img_info['file_name'].replace( osp.join(self.seg_prefix,
'jpg', 'png')), img_info['file_name'].replace('jpg', 'png')),
flag='unchanged') flag='unchanged')
gt_seg = self.seg_transform(gt_seg.squeeze(), img_scale, flip) gt_seg = self.seg_transform(gt_seg.squeeze(), img_scale, flip)
gt_seg = mmcv.imrescale( gt_seg = mmcv.imrescale(
...@@ -230,8 +235,8 @@ class CustomDataset(Dataset): ...@@ -230,8 +235,8 @@ class CustomDataset(Dataset):
if self.proposals is not None: if self.proposals is not None:
proposals = self.bbox_transform(proposals, img_shape, scale_factor, proposals = self.bbox_transform(proposals, img_shape, scale_factor,
flip) flip)
proposals = np.hstack( proposals = np.hstack([proposals, scores
[proposals, scores]) if scores is not None else proposals ]) if scores is not None else proposals
gt_bboxes = self.bbox_transform(gt_bboxes, img_shape, scale_factor, gt_bboxes = self.bbox_transform(gt_bboxes, img_shape, scale_factor,
flip) flip)
if self.with_crowd: if self.with_crowd:
...@@ -296,8 +301,8 @@ class CustomDataset(Dataset): ...@@ -296,8 +301,8 @@ class CustomDataset(Dataset):
score = None score = None
_proposal = self.bbox_transform(proposal, img_shape, _proposal = self.bbox_transform(proposal, img_shape,
scale_factor, flip) scale_factor, flip)
_proposal = np.hstack( _proposal = np.hstack([_proposal, score
[_proposal, score]) if score is not None else _proposal ]) if score is not None else _proposal
_proposal = to_tensor(_proposal) _proposal = to_tensor(_proposal)
else: else:
_proposal = None _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