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

Memory Leak in BinarPrecisionRecallCurve #2921

Open
suahelen opened this issue Jan 30, 2025 · 2 comments · May be fixed by #2945
Open

Memory Leak in BinarPrecisionRecallCurve #2921

suahelen opened this issue Jan 30, 2025 · 2 comments · May be fixed by #2945
Assignees
Labels
bug / fix Something isn't working help wanted Extra attention is needed

Comments

@suahelen
Copy link

suahelen commented Jan 30, 2025

Hi Folks,

I stumbled over this issue while playing around with anomlib

🐛 Bug

See this issue in anomalib:
openvinotoolkit/anomalib#2531

To keep it short continuously calling compute on BinaryPrecisionRecallCurve(Metric) grows the self.preds and self.target indefinitely.

This eventually leads to a memory overflow.

the following code resolves the issue by clearing the preds and targets after concatenating them to the state

    def compute(self) -> tuple[Tensor, Tensor, Tensor]:
        """Compute metric."""
        if self.thresholds is None:
            if not self.preds or not self.target:
                return torch.tensor([]), torch.tensor([]), torch.tensor([])
            state = (torch.cat(self.preds), torch.cat(self.target))

            self.preds.clear()
            self.target.clear()
        else:
            state = self.confmat
            self.confmat.zero_()

        precision, recall, thresholds = _binary_precision_recall_curve_compute(state, self.thresholds)
        return precision, recall, thresholds if thresholds is not None else torch.tensor([])

Cheers

@suahelen suahelen added bug / fix Something isn't working help wanted Extra attention is needed labels Jan 30, 2025
Copy link

Hi! thanks for your contribution!, great first issue!

@rittik9
Copy link
Contributor

rittik9 commented Feb 2, 2025

@Borda I would be interested in working on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug / fix Something isn't working help wanted Extra attention is needed
Projects
None yet
2 participants