Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions keras/api/_tf_keras/keras/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
since your modifications would be overwritten.
"""

from keras.api.utils import bounding_boxes
from keras.api.utils import legacy
from keras.src.backend.common.global_state import clear_session
from keras.src.backend.common.keras_tensor import is_keras_tensor
Expand Down
21 changes: 21 additions & 0 deletions keras/api/_tf_keras/keras/utils/bounding_boxes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""DO NOT EDIT.

This file was autogenerated. Do not edit it by hand,
since your modifications would be overwritten.
"""

from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters_new import (
affine,
)
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters_new import (
clip_to_images,
)
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters_new import (
convert_format,
)
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters_new import (
crop,
)
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters_new import (
pad,
)
1 change: 1 addition & 0 deletions keras/api/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
since your modifications would be overwritten.
"""

from keras.api.utils import bounding_boxes
from keras.api.utils import legacy
from keras.src.backend.common.global_state import clear_session
from keras.src.backend.common.keras_tensor import is_keras_tensor
Expand Down
21 changes: 21 additions & 0 deletions keras/api/utils/bounding_boxes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""DO NOT EDIT.

This file was autogenerated. Do not edit it by hand,
since your modifications would be overwritten.
"""

from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters_new import (
affine,
)
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters_new import (
clip_to_images,
)
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters_new import (
convert_format,
)
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters_new import (
crop,
)
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters_new import (
pad,
)
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ def transform_labels(self, labels, transformation, training=True):
raise NotImplementedError()

def transform_bounding_boxes(
self, bounding_boxes, transformation, training=True
self,
bounding_boxes,
orig_height,
orig_width,
transformation,
training=True,
):
raise NotImplementedError()

Expand All @@ -88,11 +93,20 @@ def transform_single_label(self, label, transformation, training=True):
return self.backend.numpy.squeeze(outputs, axis=0)

def transform_single_bounding_box(
self, bounding_box, transformation, training=True
self,
bounding_box,
orig_width,
orig_height,
transformation,
training=True,
):
bounding_boxes = self.backend.numpy.expand_dims(bounding_box, axis=0)
outputs = self.transform_bounding_boxes(
bounding_boxes, transformation=transformation, training=training
bounding_boxes,
orig_height,
orig_width,
transformation=transformation,
training=training,
)
return self.backend.numpy.squeeze(outputs, axis=0)

Expand Down Expand Up @@ -144,17 +158,47 @@ def call(self, data, training=True):
"`bounding_box_format='xyxy'`."
)
bounding_boxes = densify_bounding_boxes(
data["bounding_boxes"], backend=self.backend
data["bounding_boxes"],
is_batched=is_batched,
backend=self.backend,
)
if "orig_width" not in data:
raise ValueError(
"'orig_width' key is missing from the input data. "
"Please provide the original image width."
)

if "orig_height" not in data:
raise ValueError(
"'orig_height' key is missing from the input data. "
"Please provide the original image width."
)

if is_batched:
orig_width = self.backend.numpy.expand_dims(
data["orig_width"], axis=-1
)
orig_height = self.backend.numpy.expand_dims(
data["orig_height"], axis=-1
)
data["bounding_boxes"] = self.transform_bounding_boxes(
bounding_boxes,
orig_height,
orig_width,
transformation=transformation,
training=training,
)
else:
orig_width = self.backend.numpy.expand_dims(
[data["orig_width"]], axis=-1
)
orig_height = self.backend.numpy.expand_dims(
[data["orig_height"]], axis=-1
)
data["bounding_boxes"] = self.transform_single_bounding_box(
bounding_boxes,
orig_height,
orig_width,
transformation=transformation,
training=training,
)
Expand Down
Loading
Loading