From 8fc71029aecb692ef404dd627dda9b4cc99656e9 Mon Sep 17 00:00:00 2001 From: PeterVennerstrom <36269250+PeterVennerstrom@users.noreply.github.com> Date: Fri, 24 Jul 2020 07:23:35 -0500 Subject: [PATCH 1/4] Update __init__.py --- mmdet/datasets/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mmdet/datasets/__init__.py b/mmdet/datasets/__init__.py index 962f709..0098d7a 100644 --- a/mmdet/datasets/__init__.py +++ b/mmdet/datasets/__init__.py @@ -13,6 +13,7 @@ #xez from .coco_seg import Coco_Seg_Dataset +from .coco_seg_fast import Coco_SegFast_Dataset __all__ = [ @@ -20,5 +21,5 @@ 'CityscapesDataset', 'GroupSampler', 'DistributedGroupSampler', 'build_dataloader', 'to_tensor', 'random_scale', 'show_ann', 'ConcatDataset', 'RepeatDataset', 'ExtraAugmentation', 'WIDERFaceDataset', - 'DATASETS', 'build_dataset', 'Coco_Seg_Dataset' + 'DATASETS', 'build_dataset', 'Coco_Seg_Dataset', 'Coco_SegFast_Dataset' ] From dbd5b699895652b27b2bc42dcc2bee44a08e31ff Mon Sep 17 00:00:00 2001 From: PeterVennerstrom <36269250+PeterVennerstrom@users.noreply.github.com> Date: Fri, 24 Jul 2020 07:34:36 -0500 Subject: [PATCH 2/4] Update coco_seg_fast.py Changed line 272 from tuple to list. The tuple breaks the code when using a single stride: expanded_regress range = -1, -1 not -1, INF. Added a setting to create the annotation using all contours. Set to false by default. Changed get_mask_sample_region and get_sample_region to take self.strides directly. --- mmdet/datasets/coco_seg_fast.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mmdet/datasets/coco_seg_fast.py b/mmdet/datasets/coco_seg_fast.py index c807dd6..d7fff80 100644 --- a/mmdet/datasets/coco_seg_fast.py +++ b/mmdet/datasets/coco_seg_fast.py @@ -266,9 +266,10 @@ def prepare_train_img(self, idx): self.center_sample = True self.use_mask_center = True + self.all_contours = False self.radius = 1.5 self.strides = [8, 16, 32, 64, 128] - self.regress_ranges=((-1, 64), (64, 128), (128, 256), (256, 512),(512, INF)) + self.regress_ranges=[(-1, 64), (64, 128), (128, 256), (256, 512),(512, INF)] featmap_sizes = self.get_featmap_size(pad_shape) self.featmap_sizes = featmap_sizes num_levels = len(self.strides) @@ -370,18 +371,17 @@ def fcos_target_single(self, gt_bboxes, gt_masks, gt_labels, points, regress_ran # condition1: inside a gt bbox #加入center sample if self.center_sample: - strides = [8, 16, 32, 64, 128] if self.use_mask_center: inside_gt_bbox_mask = self.get_mask_sample_region(gt_bboxes, mask_centers, - strides, + self.strides, self.num_points_per_level, xs, ys, radius=self.radius) else: inside_gt_bbox_mask = self.get_sample_region(gt_bboxes, - strides, + self.strides, self.num_points_per_level, xs, ys, @@ -530,7 +530,10 @@ def get_centerpoint(self, lis): def get_single_centerpoint(self, mask): contour, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) - contour.sort(key=lambda x: cv2.contourArea(x), reverse=True) # only save the biggest one + if self.all_contours: + contour = [np.concatenate(contour, axis=0)] # combine all contours yielding largest mask + else: + contour.sort(key=lambda x: cv2.contourArea(x), reverse=True) # only save the biggest contour '''debug IndexError: list index out of range''' count = contour[0][:, 0, :] From 90ce7f2752dabb897f3567681ee01bf7ff101305 Mon Sep 17 00:00:00 2001 From: PeterVennerstrom <36269250+PeterVennerstrom@users.noreply.github.com> Date: Fri, 24 Jul 2020 07:40:13 -0500 Subject: [PATCH 3/4] Update coco_seg.py Changed regress range definition from tuple to list. The tuple breaks the code when using a single stride: expanded_regress range = -1, -1 not -1, INF. Added a setting to create the annotation using all contours. Set to false by default. Changed get_mask_sample_region and get_sample_region to take self.strides directly. --- mmdet/datasets/coco_seg.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mmdet/datasets/coco_seg.py b/mmdet/datasets/coco_seg.py index cdb6497..5031da9 100644 --- a/mmdet/datasets/coco_seg.py +++ b/mmdet/datasets/coco_seg.py @@ -277,9 +277,10 @@ def prepare_train_img(self, idx): self.center_sample = True self.use_mask_center = True + self.all_contours = False self.radius = 1.5 self.strides = [8, 16, 32, 64, 128] - self.regress_ranges=((-1, 64), (64, 128), (128, 256), (256, 512),(512, INF)) + self.regress_ranges=[(-1, 64), (64, 128), (128, 256), (256, 512),(512, INF)] featmap_sizes = self.get_featmap_size(pad_shape) self.featmap_sizes = featmap_sizes num_levels = len(self.strides) @@ -382,18 +383,17 @@ def polar_target_single(self, gt_bboxes, gt_masks, gt_labels, points, regress_ra # condition1: inside a gt bbox #加入center sample if self.center_sample: - strides = [8, 16, 32, 64, 128] if self.use_mask_center: inside_gt_bbox_mask = self.get_mask_sample_region(gt_bboxes, mask_centers, - strides, + self.strides, self.num_points_per_level, xs, ys, radius=self.radius) else: inside_gt_bbox_mask = self.get_sample_region(gt_bboxes, - strides, + self.strides, self.num_points_per_level, xs, ys, @@ -516,7 +516,10 @@ def get_centerpoint(self, lis): def get_single_centerpoint(self, mask): contour, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) - contour.sort(key=lambda x: cv2.contourArea(x), reverse=True) #only save the biggest one + if self.all_contours: + contour = [np.concatenate(contour, axis=0)] # combine all contours yielding largest mask + else: + contour.sort(key=lambda x: cv2.contourArea(x), reverse=True) # only save the biggest contour '''debug IndexError: list index out of range''' count = contour[0][:, 0, :] try: From 244ab016572961479366217d4c182136381318e3 Mon Sep 17 00:00:00 2001 From: PeterVennerstrom <36269250+PeterVennerstrom@users.noreply.github.com> Date: Fri, 24 Jul 2020 07:40:59 -0500 Subject: [PATCH 4/4] Update coco_seg_fast.py --- mmdet/datasets/coco_seg_fast.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mmdet/datasets/coco_seg_fast.py b/mmdet/datasets/coco_seg_fast.py index d7fff80..877fec8 100644 --- a/mmdet/datasets/coco_seg_fast.py +++ b/mmdet/datasets/coco_seg_fast.py @@ -534,7 +534,6 @@ def get_single_centerpoint(self, mask): contour = [np.concatenate(contour, axis=0)] # combine all contours yielding largest mask else: contour.sort(key=lambda x: cv2.contourArea(x), reverse=True) # only save the biggest contour - '''debug IndexError: list index out of range''' count = contour[0][:, 0, :] try: