-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Optimize line zone and add unit tests #1205
base: develop
Are you sure you want to change the base?
Conversation
Hi @tc360950 👋 Looking purely at the numbers, it's a massive improvement. I'll see if I can review it soon. Is this in comparison with the |
Hi @LinasKo |
Am I reading the graph right - is Is that the main reason for transforming to a vertical-line system? |
Exactly, that's why it's easier to transform to coordinates where the line is vertical - then everything can be vectorized. |
@SkalskiP, when you're back - I'd like your input. I think this is a fascinating case where an issue is revealed, and the problem is solved, but with a method that's too complicated for us. Specifically, I see that:
Let's wait for @SkalskiP, but my verdict is that to merge this, I'd need to know it's significantly more efficient than a solution where we use vectorized and possibly precomputed cross products. Meanwhile, @tc360950, if you have some time, would you be able to split the test into a separate PR? I assume they'd apply just as well for the current solution. |
Thanks! To add more freedom, I'd say, implementations of If there's a significantly faster way to line count, we can deprecate them. |
Hi @tc360950 👋🏻 Improving LineZone performance by 10-20x sounds fantastic, but like @LinasKo, I am concerned that the proposed changes significantly increase complexity. I strive to keep the Supervision codebase relatively simple to understand, making maintenance easier and lowering the entry barrier for future contributors. Therefore, I'd like to propose the following course of action:
@tc360950, please let me know your thoughts. |
@SkalskiP I think it's a good idea. I actually have a working draft of vectorization of the original method. I'll open a separate PR soon. |
Hi @tc360950 👋🏻 I just wanted to check in and see how it's going. Do you need any help? |
Description
My experiences with supervision's tracking indicate that (quite surprisingly) in some cases LineZone may be a bottleneck.
Think about edge computing scenarios - where detection model is small and one tracks a lot of objects. In such cases every FPS counts.
The following is a cProfile output for Yolov8m + ByteTrack + LineZone run 10 times on market square video.
As you can see the cost of LineZone is already quite considerable. Now, consider that there are not a lot of objects (average of 35 per frame) and that the easiest, most common approach to improving counting precision is adding more lines and averaging results.
For these reasons, in my usage of supervision, I've had to optimize LineZone.
The new implementation takes only 0.74 seconds on market square example compared to 11.1s seconds of the old implementation. To support this change I've added unit tests for LineZone.
Note that quite unnecessarily internals of LineZone are exposed through two public static methods - calculate_region_of_interest_limits and is_point_in_limits. I can only guess that it's because unit tests were just written for parts (encapsulated in those two methods) of LineZone code. These methods should not be public because they expose specifics of how line counting is implemented, hindering any attempts at changing the method (as is in this case). I've left those two methods unchanged, because I don't want to break peoples' code (even though those two methods were not documented as a part of API), but I've added docstring with warning that they are not a part of the API.
Type of change
Please delete options that are not relevant.
How has this change been tested, please provide a testcase or example of how you tested the change?
New LineZone unit tests.