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

[Bounding Boxes] Add Support for Bounding Box Transformations during Image Resizing #20368

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

sineeli
Copy link

@sineeli sineeli commented Oct 17, 2024

This PR covers below cases:

  1. Add bounding box transformations: Here we require orig_height and orig_width for bounding boxes transformation as each image can have separate bounding boxes relative to the original image size. Later we can use the same to transform bounding boxes as per the ratios.
  2. Make convert_format to be compatible in tf.data pipeline regardless of backend.

Just a temporary file without disturbing previous implementation of convert_format

@sineeli
Copy link
Author

sineeli commented Oct 17, 2024

Sample notebook of using convert_format and rezie layer https://colab.research.google.com/gist/sineeli/257e4d546ed89ff64c0550712287b208/-keras3-resizing.ipynb

Copy link
Member

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@codecov-commenter
Copy link

codecov-commenter commented Oct 18, 2024

Codecov Report

Attention: Patch coverage is 20.81081% with 293 lines in your changes missing coverage. Please review.

Project coverage is 73.30%. Comparing base (3d32481) to head (c5457af).
Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
...image_preprocessing/bounding_boxes/bounding_box.py 14.12% 220 Missing and 5 partials ⚠️
...g/image_preprocessing/bounding_boxes/converters.py 34.09% 28 Missing and 1 partial ⚠️
...yers/preprocessing/image_preprocessing/resizing.py 36.66% 16 Missing and 3 partials ⚠️
...g/image_preprocessing/bounding_boxes/validation.py 14.28% 12 Missing ⚠️
...i/_tf_keras/keras/utils/bounding_boxes/__init__.py 0.00% 5 Missing ⚠️
...eprocessing/image_preprocessing/random_rotation.py 33.33% 2 Missing ⚠️
keras/api/_tf_keras/keras/utils/__init__.py 0.00% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (3d32481) and HEAD (c5457af). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (3d32481) HEAD (c5457af)
keras 4 3
keras-torch 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #20368      +/-   ##
==========================================
- Coverage   78.87%   73.30%   -5.58%     
==========================================
  Files         512      516       +4     
  Lines       49266    49563     +297     
  Branches     7953     7962       +9     
==========================================
- Hits        38861    36333    -2528     
- Misses       8546    11420    +2874     
+ Partials     1859     1810      -49     
Flag Coverage Δ
keras 73.24% <20.81%> (-5.51%) ⬇️
keras-jax 62.34% <20.81%> (-0.07%) ⬇️
keras-numpy 57.42% <20.81%> (-0.01%) ⬇️
keras-tensorflow 63.56% <20.81%> (-0.08%) ⬇️
keras-torch ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


```python
boxes = {
"boxes": [TODO],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fill in

Remove input dict args for default orig_height and orig_width
Copy link
Member

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, thanks for the updates! Please add a unit test for Resizing bounding box support.

Copy link
Member

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good to me! Not sure about the max bbox layer.

A side question is whether we need "bbox" in the name of the transformations like affine_transform etc et distinguish them from keras.ops.image.affine_transform and so on. No strong opinion.

@sineeli
Copy link
Author

sineeli commented Oct 22, 2024

@sineeli sineeli requested a review from fchollet October 22, 2024 22:08
@fchollet
Copy link
Member

Can you take a look at the test failures? I think they are likely related to the fact that torch tests are running with data_format="channels_first". https://github.com/keras-team/keras/actions/runs/11469236802/job/31916066253?pr=20368

@sineeli
Copy link
Author

sineeli commented Oct 23, 2024

Can you take a look at the test failures? I think they are likely related to the fact that torch tests are running with data_format="channels_first". https://github.com/keras-team/keras/actions/runs/11469236802/job/31916066253?pr=20368

Oh yes!! thanks I updated the test cases for channels_first case.

Reference:

  1. Bounding Boxes with pad_to_aspect_ratio=True
  2. Bounding Boxes with crop_to_aspect_ratio=True
  3. Normal Resize

@sineeli
Copy link
Author

sineeli commented Oct 23, 2024

The code looks good to me! Not sure about the max bbox layer.

A side question is whether we need "bbox" in the name of the transformations like affine_transform etc et distinguish them from keras.ops.image.affine_transform and so on. No strong opinion.

I guess it should be fine as user will use keras.utils.bounding_boxes.affine_transform and it is explicit that its under bounding_boxes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants