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

Metrics - Fixed Missing Reset #25

Merged
merged 6 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions luxonis_train/attached_modules/metrics/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

import torchmetrics
from torch import Tensor

from .base_metric import BaseMetric

Expand Down Expand Up @@ -47,14 +48,17 @@ def __init__(self, **kwargs):

self.metric = self.Metric(**kwargs)

def update(self, preds, target, *args, **kwargs):
def update(self, preds, target, *args, **kwargs) -> None:
if self.task in ["multiclass"]:
target = target.argmax(dim=1)
self.metric.update(preds, target, *args, **kwargs)

def compute(self):
def compute(self) -> Tensor:
return self.metric.compute()

def reset(self) -> None:
self.metric.reset()


class Accuracy(TorchMetricWrapper):
Metric = torchmetrics.Accuracy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .base_metric import BaseMetric


class MeanAveragePrecision(BaseMetric, detection.MeanAveragePrecision):
class MeanAveragePrecision(BaseMetric):
"""Compute the Mean-Average-Precision (mAP) and Mean-Average-Recall (mAR) for object
detection predictions.

Expand Down Expand Up @@ -62,6 +62,9 @@ def prepare(

return output_list, label_list

def reset(self) -> None:
self.metric.reset()

def compute(self) -> tuple[Tensor, dict[str, Tensor]]:
metric_dict = self.metric.compute()

Expand Down
Loading