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

[LineZone] - allow per class counting #790

Open
SkalskiP opened this issue Jan 26, 2024 · 5 comments
Open

[LineZone] - allow per class counting #790

SkalskiP opened this issue Jan 26, 2024 · 5 comments
Labels
api: linezone LineZone API enhancement New feature or request good first issue Good for newcomers Q2.2024 Tasks planned for execution in Q2 2024.

Comments

@SkalskiP
Copy link
Collaborator

SkalskiP commented Jan 26, 2024

Description

Currently, sv.LineZone provides only aggregated counts - all classes are thrown into one bucket. In the past, many users have asked us to provide more granular - per class count. This can be achieved by adding class_in_count and class_out_count dictionaries that will store per-class counts.

API

class LineZone:

    def __init__(
        self,
        start: Point,
        end: Point,
        triggering_anchors: Iterable[Position] = (
            Position.TOP_LEFT,
            Position.TOP_RIGHT,
            Position.BOTTOM_LEFT,
            Position.BOTTOM_RIGHT,
        ),
    ):
        # Existing initialization code...

        self.class_in_count: Dict[int, int] = {}
        self.class_out_count: Dict[int, int] = {}

    def trigger(self, detections: Detections) -> Tuple[np.ndarray, np.ndarray]:
        crossed_in = np.full(len(detections), False)
        crossed_out = np.full(len(detections), False)

        # Required logic changes...

Additional

  • Note: Please share a Google Colab with minimal code to test the new feature. We know it's additional work, but it will definitely speed up the review process. Each change must be tested by the reviewer. 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! 🙏🏻
@SkalskiP SkalskiP added enhancement New feature or request api: linezone LineZone API Q1.2024 Tasks planned for execution in Q1 2024. good first issue Good for newcomers labels Jan 26, 2024
@SkalskiP SkalskiP changed the title [LineZone] - allow multi-class counting [LineZone] - allow per class counting Jan 26, 2024
@RaghavvGupta
Copy link
Contributor

Hey @SkalskiP, I was wondering to work on this. I have this logic in mind, pls confirm if this approach is what you guys want?

Dictionaries to keep track of counts for each class

self.class_in_count: Dict[str, int] = {} self.class_out_count: Dict[str, int] = {}

Updating per class-in and class-out count

class_label = detections.class_labels[i]
                if class_label not in self.class_in_count:
                    self.class_in_count[class_label] = 0
                self.class_in_count[class_label] += 1
            else:
                self.out_count += 1
                crossed_out[i] = True

                # Updating per-class out count
                class_label = detections.class_labels[i]
                if class_label not in self.class_out_count:
                    self.class_out_count[class_label] = 0
                self.class_out_count[class_label] += 1

@RaghavvGupta
Copy link
Contributor

Hey @SkalskiP 😀👋
https://colab.research.google.com/drive/1HxRcfzqnS6axAlYPiPpe8WLblfdn6fC_?usp=sharing

This is what I was talking about. Please tell me whether this is what you want.

@SkalskiP
Copy link
Collaborator Author

Hi, @RaghavvGupta, Would that be the implementation of a current count or the total count?

@RaghavvGupta
Copy link
Contributor

I have tried implementing per-class counting. It includes dictionaries class_in_count and class_out_count to store counts for each class separately. The counts within these dictionaries are updated during each call to the trigger method, representing the current count of objects for each class based on their movement across the line.

@SkalskiP
Copy link
Collaborator Author

@RaghavvGupta, submit PR so we can move forward with the review process.

@SkalskiP SkalskiP added Q2.2024 Tasks planned for execution in Q2 2024. and removed Q1.2024 Tasks planned for execution in Q1 2024. labels Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: linezone LineZone API enhancement New feature or request good first issue Good for newcomers Q2.2024 Tasks planned for execution in Q2 2024.
Projects
Development

No branches or pull requests

2 participants