Skip to content

Commit

Permalink
Summary: In previous code, the valid_bbox function was only designed …
Browse files Browse the repository at this point in the history
…for XYWH horizontal bboxes, this caused XYWHA rotated bboxes being marked invalid when the bboxes are large or close to the right edge of the image. So writing a valid_bbox_rotated for XYWHA format bbox separately

Differential Revision: D48138234

fbshipit-source-id: d00fd4f815f53b93a5ba0ffa5cbbfba1f55fee13
  • Loading branch information
dspgbgjd authored and facebook-github-bot committed Aug 9, 2023
1 parent 9e40d71 commit 75e7873
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions d2go/data/extended_coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ def valid_bbox(bbox_xywh: List[int], img_w: int, img_h: int) -> bool:
return True


def valid_bbox_rotated(bbox_xywha: List[int], img_w: int, img_h: int) -> bool:
if bbox_xywha is None or (bbox_xywha[3] == 0 or bbox_xywha[2] == 0):
return False
return True


def convert_coco_annotations(
anno_dict_list: List[Dict],
record: Dict,
Expand Down Expand Up @@ -201,15 +207,26 @@ def convert_coco_annotations(
obj["bbox_mode"] = (
BoxMode.XYWHA_ABS if len(obj["bbox"]) == 5 else BoxMode.XYWH_ABS
)

if (
filter_invalid_bbox
and record.get("width")
and record.get("height")
and not valid_bbox(bbox_object, record["width"], record["height"])
):
error_report["without_valid_bounding_box"].cnt += 1
continue
if obj["bbox_mode"] != BoxMode.XYWHA_ABS: # for horizontal bboxes
if (
filter_invalid_bbox
and record.get("width")
and record.get("height")
and not valid_bbox(bbox_object, record["width"], record["height"])
):
error_report["without_valid_bounding_box"].cnt += 1
continue
else: # for rotated bboxes in XYWHA format
if (
filter_invalid_bbox
and record.get("width")
and record.get("height")
and not valid_bbox_rotated(
bbox_object, record["width"], record["height"]
)
):
error_report["without_valid_bounding_box"].cnt += 1
continue

# Segmentation: filter and add segmentation
segm = anno.get("segmentation", None)
Expand Down

0 comments on commit 75e7873

Please sign in to comment.