Commit f7e1b47e authored by Yichao Lu's avatar Yichao Lu Committed by Facebook GitHub Bot
Browse files

Summary:

Pull Request resolved: https://github.com/facebookresearch/d2go/pull/609

In previous code, the valid_bbox function was only designed 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

Reviewed By: debowin

Differential Revision: D48138234

fbshipit-source-id: d09d209afde9843624169af04f2e1692180bca0d
parent 9e40d710
......@@ -150,6 +150,19 @@ 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)
or not (
0.4 * bbox_xywha[2] <= bbox_xywha[0] <= img_w - bbox_xywha[2] * 0.4
) # using 0.4*h and 0.4*w to give some leeway for rotation but still remove huge bboxes for training stability
or not (0.4 * bbox_xywha[3] <= bbox_xywha[1] <= img_h - bbox_xywha[3] * 0.4)
):
return False
return True
def convert_coco_annotations(
anno_dict_list: List[Dict],
record: Dict,
......@@ -201,15 +214,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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment