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

Deprecate tight_box_rotation parameters in COCODetectionDataset #1786

Merged
merged 9 commits into from
Feb 6, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ train_dataset_params:
- DetectionTargetsFormatTransform:
input_dim: ${dataset_params.train_dataset_params.input_dim}
output_format: LABEL_CXCYWH
tight_box_rotation: False
class_inclusion_list:
max_num_samples:
with_crowd: False
Expand Down Expand Up @@ -65,7 +64,6 @@ val_dataset_params:
- DetectionTargetsFormatTransform:
input_dim: ${dataset_params.val_dataset_params.input_dim}
output_format: LABEL_CXCYWH
tight_box_rotation: False
class_inclusion_list:
max_num_samples:
with_crowd: True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ train_dataset_params:
- DetectionTargetsFormatTransform:
output_format: LABEL_CXCYWH

tight_box_rotation: False
class_inclusion_list:
max_num_samples:
with_crowd: False
Expand Down Expand Up @@ -78,7 +77,6 @@ val_dataset_params:
std: [ 58.395, 57.12, 57.375 ]
- DetectionTargetsFormatTransform:
output_format: LABEL_CXCYWH
tight_box_rotation: False
class_inclusion_list:
max_num_samples:
with_crowd: True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ train_dataset_params:
input_dim: ${dataset_params.train_dataset_params.input_dim}
output_format: LABEL_NORMALIZED_CXCYWH

tight_box_rotation: False
class_inclusion_list:
max_num_samples:
with_crowd: False
Expand Down Expand Up @@ -61,7 +60,6 @@ val_dataset_params:
- DetectionTargetsFormatTransform:
input_dim: ${dataset_params.val_dataset_params.input_dim}
output_format: LABEL_NORMALIZED_CXCYWH
tight_box_rotation: False
class_inclusion_list:
max_num_samples:
with_crowd: True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ train_dataset_params:
- DetectionTargetsFormatTransform:
output_format: LABEL_CXCYWH

tight_box_rotation: False
class_inclusion_list:
max_num_samples:
with_crowd: False
Expand Down Expand Up @@ -153,7 +152,6 @@ val_dataset_params:
- DetectionTargetsFormatTransform:
input_dim: [640, 640]
output_format: LABEL_CXCYWH
tight_box_rotation: False
class_inclusion_list:
max_num_samples:
with_crowd: True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ train_dataset_params:
- DetectionTargetsFormatTransform:
input_dim: ${dataset_params.train_dataset_params.input_dim}
output_format: LABEL_CXCYWH
tight_box_rotation: False
class_inclusion_list:
max_num_samples:
with_crowd: False
Expand Down Expand Up @@ -77,7 +76,6 @@ val_dataset_params:
- DetectionTargetsFormatTransform:
input_dim: ${dataset_params.val_dataset_params.input_dim}
output_format: LABEL_CXCYWH
tight_box_rotation: False
class_inclusion_list:
max_num_samples:
with_crowd: True
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import copy
import os

import cv2
import numpy as np
from pycocotools.coco import COCO
from typing import List, Optional
Expand All @@ -28,24 +27,26 @@ def __init__(
data_dir: str,
json_annotation_file: str,
images_dir: str,
tight_box_rotation: bool = False,
with_crowd: bool = True,
class_ids_to_ignore: Optional[List[int]] = None,
tight_box_rotation=None,
*args,
**kwargs,
):
"""
:param data_dir: Where the data is stored.
:param json_annotation_file: Name of the coco json file. Path relative to data_dir.
:param images_dir: Name of the directory that includes all the images. Path relative to data_dir.
:param tight_box_rotation: bool, whether to use of segmentation maps convex hull as target_seg
(check get_sample docs).
:param with_crowd: Add the crowd groundtruths to __getitem__
:param class_ids_to_ignore: List of class ids to ignore in the dataset. By default, doesnt ignore any class.
:param tight_box_rotation: This parameter is deprecated and will be removed in a SuperGradients 3.8.
"""
if tight_box_rotation is not None:
BloodAxe marked this conversation as resolved.
Show resolved Hide resolved
logger.warning(
"Parameter `tight_box_rotation` is deprecated and will be removed in a SuperGradients 3.8." "Please remove this parameter from your code."
)
self.images_dir = images_dir
self.json_annotation_file = json_annotation_file
self.tight_box_rotation = tight_box_rotation
self.with_crowd = with_crowd
self.class_ids_to_ignore = class_ids_to_ignore or []

Expand Down Expand Up @@ -95,7 +96,7 @@ def _init_coco(self) -> COCO:
else:
coco = COCO(annotation_file_path)

remove_useless_info(coco, self.tight_box_rotation)
remove_useless_info(coco, False)
return coco

def _load_annotation(self, sample_id: int) -> dict:
Expand Down Expand Up @@ -133,21 +134,11 @@ def _load_annotation(self, sample_id: int) -> dict:
non_crowd_annotations = [annotation for annotation in cleaned_annotations if annotation["iscrowd"] == 0]

target = np.zeros((len(non_crowd_annotations), 5))
num_seg_values = 98 if self.tight_box_rotation else 0
target_segmentation = np.ones((len(non_crowd_annotations), num_seg_values))
target_segmentation.fill(np.nan)

for ix, annotation in enumerate(non_crowd_annotations):
cls = self.class_ids.index(annotation["category_id"])
target[ix, 0:4] = annotation["clean_bbox"]
target[ix, 4] = cls
if self.tight_box_rotation:
seg_points = [j for i in annotation.get("segmentation", []) for j in i]
if seg_points:
seg_points_c = np.array(seg_points).reshape((-1, 2)).astype(np.int32)
seg_points_convex = cv2.convexHull(seg_points_c).ravel()
else:
seg_points_convex = []
target_segmentation[ix, : len(seg_points_convex)] = seg_points_convex

crowd_annotations = [annotation for annotation in cleaned_annotations if annotation["iscrowd"] == 1]

Expand All @@ -163,7 +154,6 @@ def _load_annotation(self, sample_id: int) -> dict:
r = min(self.input_dim[0] / height, self.input_dim[1] / width)
target[:, :4] *= r
crowd_target[:, :4] *= r
target_segmentation *= r
resized_img_shape = (int(height * r), int(width * r))
else:
resized_img_shape = initial_img_shape
Expand All @@ -175,7 +165,6 @@ def _load_annotation(self, sample_id: int) -> dict:
annotation = {
"target": target,
"crowd_target": crowd_target,
"target_segmentation": target_segmentation,
"initial_img_shape": initial_img_shape,
"resized_img_shape": resized_img_shape,
"img_path": img_path,
Expand Down