Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove useless bboxes&labels in CocoDataset #159

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions nanodet/data/dataset/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,29 @@ def get_train_data(self, idx):

meta = self.pipeline(meta, self.input_size)
meta['img'] = torch.from_numpy(meta['img'].transpose(2, 0, 1))

# Remove the bboxes and labels outside the image
if len(meta['gt_bboxes']) > 0 and len(meta['gt_labels']) > 0 :
gt_bboxes = []
gt_labels = []
for gt_bbox, gt_label in zip(meta['gt_bboxes'], meta['gt_labels']):
if (gt_bbox[0] == meta['img'].shape[2]) or (gt_bbox[1] == meta['img'].shape[1]) or (gt_bbox[2] == 0) or (gt_bbox[3] == 0):
continue
gt_bboxes.append(gt_bbox)
gt_labels.append(gt_label)
if len(gt_bboxes):
meta['gt_bboxes'] = np.asarray(gt_bboxes)
else:
meta['gt_bboxes'] = np.zeros([0, 4], dtype=np.float32)
if len(gt_labels):
meta['gt_labels'] = np.asarray(gt_labels)
else:
meta['gt_labels'] = np.zeros([0,], dtype=np.int64)

# Remove image without label&bbox
if self.mode == 'train' and len(meta['gt_bboxes']) == 0:
return None

return meta

def get_val_data(self, idx):
Expand Down