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

Move OBB boxes #1350

Merged
merged 14 commits into from
Jul 18, 2024
Merged

Move OBB boxes #1350

merged 14 commits into from
Jul 18, 2024

Conversation

eric220
Copy link
Contributor

@eric220 eric220 commented Jul 12, 2024

Description

Issue: draw wrong OrientedBoxAnnotator with InferenceSlicer #1339
Resolution: create function *utils:move_obb_boxes (as suggested by LinasKo), with a call inside *tools/inference_slicer:move_detections

List any dependencies that are required for this change.
No new dependencies required

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

How has this change been tested, please provide a testcase or example of how you tested the change?

created detection-like object (single and multiple detections) based on the submitted issue, passed to the function and verified results

Docs

I did not change any documentation

@CLAassistant
Copy link

CLAassistant commented Jul 12, 2024

CLA assistant check
All committers have signed the CLA.

@LinasKo
Copy link
Contributor

LinasKo commented Jul 12, 2024

Hi @eric220 👋

Thank you for submitting the PR! We need all contributors to sign the CLA before it can be reviewed.
(Note that there's been issues with CLA since a few minutes ago. If you signed it already, it could be a system fault / new update we're unfamiliar with.)

Also, as the issue was assigned to @Bhavay-2001, if he opens a PR in a week from now, his code will have priority.
Otherwise, this looks pretty good, except that we don't want xyxyxyxy as the key - there's a specific enum value we're using.

@Bhavay-2001
Copy link
Contributor

Hi @LinasKo, let @eric220 work with this one and you can assign me some other issue. I would be happy to help.
Thanks

@LinasKo
Copy link
Contributor

LinasKo commented Jul 12, 2024

Cool. @eric220, please have a look at the CLA. I assume you used 2 different emails in your commits, but let me know if something doesn't work.

@eric220
Copy link
Contributor Author

eric220 commented Jul 12, 2024 via email

@LinasKo
Copy link
Contributor

LinasKo commented Jul 12, 2024

Hi @eric220!

@onuralpszr will give some tips in terms of commit management 😉

I'll do a quick code review in a sec

@LinasKo
Copy link
Contributor

LinasKo commented Jul 12, 2024

The enum you're looking for is ORIENTED_BOX_COORDINATES.

Note: Please share a Google Colab with minimal code to test the new feature. We know it's additional work, but it will speed up the review process. The reviewer must test each change. Setting up a local environment to do this is time-consuming. Please ensure that Google Colab can be accessed without any issues (make it public). Thank you! 🙏🏻

Here's some models that might be helpful.

@eric220
Copy link
Contributor Author

eric220 commented Jul 13, 2024 via email

Copy link
Contributor

@LinasKo LinasKo left a comment

Choose a reason for hiding this comment

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

@onuralpszr, when you have the time, could you please help us out with a clean way to handle the commit issues?

@eric220, I've made some comments of the code. When you're ready, please post the Colab link here so we can test it too 😉

@@ -28,6 +28,10 @@ def move_detections(
(sv.Detections) repositioned Detections object.
"""
detections.xyxy = move_boxes(xyxy=detections.xyxy, offset=offset)
if "ORIENTED_BOX_COORDINATES" in detections.data:
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than a string, this needs to be imported from supervision.config.

@@ -28,6 +28,10 @@ def move_detections(
(sv.Detections) repositioned Detections object.
"""
detections.xyxy = move_boxes(xyxy=detections.xyxy, offset=offset)
if "ORIENTED_BOX_COORDINATES" in detections.data:
detections.data["ORIENTED_BOX_COORDINATES"] = move_obb_boxes(
xyss=detections.data["ORIENTED_BOX_COORDINATES"], offset=offset
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's change the variable name from xyss to xyxyxyxy.

@eric220
Copy link
Contributor Author

eric220 commented Jul 15, 2024 via email

@onuralpszr
Copy link
Collaborator

onuralpszr commented Jul 15, 2024

For commit I will give you fix, I have some stuff to finish ;) wait a little bit

@onuralpszr
Copy link
Collaborator

onuralpszr commented Jul 15, 2024

Hlelo @LinasKo @eric220

I looked that commits and did a test run in clone of this branch and this should re-write history of problematic commit author. Before push here please also try in clone of your branch and push and check it. If you find issue let me know (on my test it was fine but please re-do so)

That "commit sha" at the end also I used from your branch commit sha when I executed it should only change 7 out 9 commits and you will see it.

git filter-branch --env-filter '
OLD_EMAIL="ericcriteser@Erics-MBP.attlocal.net"
CORRECT_NAME="Eric Criteser"
CORRECT_EMAIL="criteser2@gmail.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$CORRECT_NAME"
    export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$CORRECT_NAME"
    export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags "d7bac3dc87484a3362473b5a81031b5a47b9101e^.."

@eric220
Copy link
Contributor Author

eric220 commented Jul 15, 2024 via email

@onuralpszr
Copy link
Collaborator

onuralpszr commented Jul 16, 2024

@eric220 did you just duplicate commits ?

@@ -9,6 +9,7 @@
from supervision.detection.utils import move_boxes, move_masks, move_obb_boxes
from supervision.utils.image import crop_image
from supervision.utils.internal import SupervisionWarnings
from supervision import config
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's only import ORIENTED_BOX_COORDINATES, rather than the whole config. This matches the pattern in the rest of the repo.

@eric220
Copy link
Contributor Author

eric220 commented Jul 16, 2024 via email

@eric220
Copy link
Contributor Author

eric220 commented Jul 16, 2024 via email

@LinasKo
Copy link
Contributor

LinasKo commented Jul 16, 2024

@onuralpszr, if it's not a trivial fix, let's do a clean submission in a new PR. Beyond a certain point it won't be worth trying to fix it 'correctly' :)

@onuralpszr
Copy link
Collaborator

@onuralpszr, if it's not a trivial fix, let's do a clean submission in a new PR. Beyond a certain point it won't be worth trying to fix it 'correctly' :)

All fixed.

@onuralpszr
Copy link
Collaborator

onuralpszr commented Jul 16, 2024

@eric220 please check your .gitconfig and git settings carefully and you need re-pull or just do "re-clone" fork of your repo again. I made sure all of them is your correct registered github e-mail and name you used in commits. But one advice If you wanted to, please check github document and how to use gpg with github and enable your gpg-sign and sign off mode as well. (vigilant mode in github) It will gives you more security and control over your github/commits as well.

Docs : https://docs.github.com/en/authentication/managing-commit-signature-verification/displaying-verification-statuses-for-all-of-your-commits
Docs2: https://docs.github.com/en/authentication/managing-commit-signature-verification/adding-a-gpg-key-to-your-github-account

@eric220
Copy link
Contributor Author

eric220 commented Jul 16, 2024 via email

@onuralpszr
Copy link
Collaborator

@eric220 you are very welcome, no need to make new pr we can continue all good. :)

@@ -4,9 +4,10 @@

import numpy as np

from supervision.config import ORIENTED_BOX_COORDINATES as o_b_c
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please import from supervision.config import ORIENTED_BOX_COORDINATES and skip as o_b_c. The name is long but descriptive. It is also consistent with the rest of the codebase.

@@ -596,6 +596,44 @@ def move_boxes(
return xyxy + np.hstack([offset, offset])


def move_obb_boxes(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please rename the function to move_oriented_boxes.

#[45., 50.]]]
```
"""
return [
Copy link
Collaborator

Choose a reason for hiding this comment

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

I just wanted to let you know that you don't need to do it like this. Numpy supports broadcasting. Broadcasting allows NumPy to perform element-wise operations on arrays of different shapes by automatically expanding the smaller array to match the shape of the larger one.

You can simply xyxyxyxy + offset.

You can learn more from this colab: https://colab.research.google.com/drive/10FVlOMQaStrg7yUo-_x4l_NEBafHzUqI?usp=sharing

def move_obb_boxes(
xyxyxyxy: npt.NDArray[np.float64], offset: npt.NDArray[np.int32]
) -> npt.NDArray[np.float64]:
"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

To make docsting consistent with rest of the codebase, please replace it with:

"""
Parameters:
    xyxyxyxy (npt.NDArray[np.float64]): An array of shape `(n, 4, 2)` containing the
        oriented bounding boxes coordinates in format `[[x1, y1], [x2, y2], [x3, y3], [x3, y3]]`
    offset (np.array): An array of shape `(2,)` containing offset values in format
        is `[dx, dy]`.

Returns:
    npt.NDArray[np.float64]: Repositioned bounding boxes.

Examples:
    ```python
    import numpy as np
    import supervision as sv

    xyxyxyxy = np.array([
        [
            [20, 10],
            [10, 20],
            [20, 30],
            [30, 20]
        ],
        [
            [30 ,30],
            [20, 40],
            [30, 50],
            [40, 40]
        ]
    ])
    offset = np.array([5, 5])

    sv.move_oriented_boxes(xyxy=xyxy, offset=offset)
    # array([
    #     [
    #         [25, 15],
    #         [15, 25],
    #         [25, 35],
    #         [35, 25]
    #     ],
    #     [
    #         [35, 35],
    #         [25, 45],
    #         [35, 55],
    #         [45, 45]
    #     ]
    # ])
    ```
"""

@SkalskiP
Copy link
Collaborator

Hi @eric220 👋🏻 I'm covering for @LinasKo as he is on vacation. I left a few comments. Let me know if you have any questions.

@eric220
Copy link
Contributor Author

eric220 commented Jul 17, 2024 via email

@SkalskiP
Copy link
Collaborator

Thanks a lot @eric220 🙏🏻 I just asked here #1339 to test this change. @eric220 you can also create a colab testing this change end-to-end (on actual OBB inference).

Once we confirm it works, we can merge! 🔥

@SkalskiP
Copy link
Collaborator

Looks like tests went well: #1339 (comment). Merging!

@SkalskiP SkalskiP merged commit 7ca5b01 into roboflow:develop Jul 18, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants