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

Remove bboxes clipping #1401

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion keras_retinanet/layers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from ._misc import RegressBoxes, UpsampleLike, Anchors, ClipBoxes # noqa: F401
from ._misc import RegressBoxes, UpsampleLike, Anchors # noqa: F401
from .filter_detections import FilterDetections # noqa: F401
23 changes: 0 additions & 23 deletions keras_retinanet/layers/_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,26 +160,3 @@ def get_config(self):
})

return config


class ClipBoxes(keras.layers.Layer):
""" Keras layer to clip box values to lie inside a given shape.
"""
def call(self, inputs, **kwargs):
image, boxes = inputs
shape = keras.backend.cast(keras.backend.shape(image), keras.backend.floatx())
if keras.backend.image_data_format() == 'channels_first':
_, _, height, width = backend.unstack(shape, axis=0)
else:
_, height, width, _ = backend.unstack(shape, axis=0)

x1, y1, x2, y2 = backend.unstack(boxes, axis=-1)
x1 = backend.clip_by_value(x1, 0, width - 1)
y1 = backend.clip_by_value(y1, 0, height - 1)
x2 = backend.clip_by_value(x2, 0, width - 1)
y2 = backend.clip_by_value(y2, 0, height - 1)

return keras.backend.stack([x1, y1, x2, y2], axis=2)

def compute_output_shape(self, input_shape):
return input_shape[1]
1 change: 0 additions & 1 deletion keras_retinanet/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def __init__(self, backbone):
'RegressBoxes' : layers.RegressBoxes,
'FilterDetections' : layers.FilterDetections,
'Anchors' : layers.Anchors,
'ClipBoxes' : layers.ClipBoxes,
'_smooth_l1' : losses.smooth_l1(),
'_focal' : losses.focal(),
}
Expand Down
1 change: 0 additions & 1 deletion keras_retinanet/models/retinanet.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ def retinanet_bbox(

# apply predicted regression to anchors
boxes = layers.RegressBoxes(name='boxes')([anchors, regression])
boxes = layers.ClipBoxes(name='clipped_boxes')([model.inputs[0], boxes])

# filter detections (apply NMS / score threshold / select top-k)
detections = layers.FilterDetections(
Expand Down
6 changes: 1 addition & 5 deletions keras_retinanet/preprocessing/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,7 @@ def filter_annotations(self, image_group, annotations_group, group):
# test x2 < x1 | y2 < y1 | x1 < 0 | y1 < 0 | x2 <= 0 | y2 <= 0 | x2 >= image.shape[1] | y2 >= image.shape[0]
invalid_indices = np.where(
(annotations['bboxes'][:, 2] <= annotations['bboxes'][:, 0]) |
(annotations['bboxes'][:, 3] <= annotations['bboxes'][:, 1]) |
(annotations['bboxes'][:, 0] < 0) |
(annotations['bboxes'][:, 1] < 0) |
(annotations['bboxes'][:, 2] > image.shape[1]) |
(annotations['bboxes'][:, 3] > image.shape[0])
(annotations['bboxes'][:, 3] <= annotations['bboxes'][:, 1])
)[0]

# delete invalid indices
Expand Down