-
Notifications
You must be signed in to change notification settings - Fork 330
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
feat: Add minimum_box_area_ratio
to filter out poor, partial boxes
#2484
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,7 @@ def _relative_area(boxes, bounding_box_format): | |
|
||
@keras_cv_export("keras_cv.bounding_box.clip_to_image") | ||
def clip_to_image( | ||
bounding_boxes, bounding_box_format, images=None, image_shape=None | ||
bounding_boxes, bounding_box_format, images=None, image_shape=None, minimum_box_area_ratio=0.0 | ||
): | ||
"""clips bounding boxes to image boundaries. | ||
|
||
|
@@ -92,6 +92,7 @@ class ID set to -1, indicating that there is no object present in them. | |
images=images, | ||
image_shape=image_shape, | ||
) | ||
original_areas = _relative_area(boxes, bounding_box_format="rel_xyxy") | ||
boxes, classes, images, squeeze = _format_inputs(boxes, classes, images) | ||
x1, y1, x2, y2 = ops.split(boxes, 4, axis=-1) | ||
clipped_bounding_boxes = ops.concatenate( | ||
|
@@ -106,17 +107,19 @@ class ID set to -1, indicating that there is no object present in them. | |
areas = _relative_area( | ||
clipped_bounding_boxes, bounding_box_format="rel_xyxy" | ||
) | ||
area_ratios = ops.divide(areas, original_areas) | ||
clipped_bounding_boxes = bounding_box.convert_format( | ||
clipped_bounding_boxes, | ||
source="rel_xyxy", | ||
target=bounding_box_format, | ||
images=images, | ||
image_shape=image_shape, | ||
) | ||
passed = ops.logical_and(areas > 0.0, area_ratios > minimum_box_area_ratio) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we rename passed to something more meaningful - |
||
clipped_bounding_boxes = ops.where( | ||
ops.expand_dims(areas > 0.0, axis=-1), clipped_bounding_boxes, -1.0 | ||
ops.expand_dims(passed, axis=-1), clipped_bounding_boxes, -1.0 | ||
) | ||
classes = ops.where(areas > 0.0, classes, -1) | ||
classes = ops.where(passed, classes, -1) | ||
nan_indices = ops.any(ops.isnan(clipped_bounding_boxes), axis=-1) | ||
classes = ops.where(nan_indices, -1, classes) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,7 @@ def __init__( | |
crop_size=None, | ||
bounding_box_format=None, | ||
interpolation="bilinear", | ||
minimum_box_area_ratio=0.0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let us remove this from the augmentation layers. We need to keep this consistent with the other layers. Let us not touch this. |
||
seed=None, | ||
**kwargs, | ||
): | ||
|
@@ -130,6 +131,8 @@ def __init__( | |
self.seed = seed | ||
|
||
self.force_output_dense_images = True | ||
|
||
self.minimum_box_area_ratio = minimum_box_area_ratio | ||
|
||
def compute_ragged_image_signature(self, images): | ||
ragged_spec = tf.RaggedTensorSpec( | ||
|
@@ -252,6 +255,7 @@ def augment_bounding_boxes( | |
result, | ||
image_shape=self.target_size + (3,), | ||
bounding_box_format="yxyx", | ||
minimum_box_area_ratio=self.minimum_box_area_ratio | ||
) | ||
result = bounding_box.convert_format( | ||
result, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this as well. Maybe add a doc string to
clip_to_image
, explain the args and add an example there