what.models.detection.frcnn.meter.averagevalue_meter API documentation

# what.models.detection.frcnn.meter.averagevalue_meter

View Source

     1from . import meter
     2import numpy as np
     3
     4
     5class AverageValueMeter(meter.Meter):
     6    def __init__(self):
     7        super(AverageValueMeter, self).__init__()
     8        self.reset()
     9        self.val = 0
    10
    11    def add(self, value, n=1):
    12        self.val = value
    13        self.sum += value * n
    14        if n <= 0:
    15            raise ValueError("Cannot use a non-positive weight for the running stat.")
    16        elif self.n == 0:
    17            self.mean = 0.0 + value  # This is to force a copy in torch/numpy
    18            self.std = np.inf
    19            self.mean_old = self.mean
    20            self.m_s = 0.0
    21        else:
    22            self.mean = self.mean_old + n * (value - self.mean_old) / float(self.n + n)
    23            self.m_s += n * (value - self.mean_old) * (value - self.mean)
    24            self.mean_old = self.mean
    25            self.std = np.sqrt(self.m_s / (self.n + n - 1.0))
    26        self.var = self.std ** 2
    27
    28        self.n += n
    29
    30    def value(self):
    31        return self.mean, self.std
    32
    33    def reset(self):
    34        self.n = 0
    35        self.sum = 0.0
    36        self.var = 0.0
    37        self.val = 0.0
    38        self.mean = np.nan
    39        self.mean_old = 0.0
    40        self.m_s = 0.0
    41        self.std = np.nan

class AverageValueMeter(what.models.detection.frcnn.meter.meter.Meter): View Source

     6class AverageValueMeter(meter.Meter):
     7    def __init__(self):
     8        super(AverageValueMeter, self).__init__()
     9        self.reset()
    10        self.val = 0
    11
    12    def add(self, value, n=1):
    13        self.val = value
    14        self.sum += value * n
    15        if n <= 0:
    16            raise ValueError("Cannot use a non-positive weight for the running stat.")
    17        elif self.n == 0:
    18            self.mean = 0.0 + value  # This is to force a copy in torch/numpy
    19            self.std = np.inf
    20            self.mean_old = self.mean
    21            self.m_s = 0.0
    22        else:
    23            self.mean = self.mean_old + n * (value - self.mean_old) / float(self.n + n)
    24            self.m_s += n * (value - self.mean_old) * (value - self.mean)
    25            self.mean_old = self.mean
    26            self.std = np.sqrt(self.m_s / (self.n + n - 1.0))
    27        self.var = self.std ** 2
    28
    29        self.n += n
    30
    31    def value(self):
    32        return self.mean, self.std
    33
    34    def reset(self):
    35        self.n = 0
    36        self.sum = 0.0
    37        self.var = 0.0
    38        self.val = 0.0
    39        self.mean = np.nan
    40        self.mean_old = 0.0
    41        self.m_s = 0.0
    42        self.std = np.nan

Meters provide a way to keep track of important statistics in an online manner.

This class is abstract, but provides a standard interface for all meters to follow.

def add(self, value, n=1): View Source

    12    def add(self, value, n=1):
    13        self.val = value
    14        self.sum += value * n
    15        if n <= 0:
    16            raise ValueError("Cannot use a non-positive weight for the running stat.")
    17        elif self.n == 0:
    18            self.mean = 0.0 + value  # This is to force a copy in torch/numpy
    19            self.std = np.inf
    20            self.mean_old = self.mean
    21            self.m_s = 0.0
    22        else:
    23            self.mean = self.mean_old + n * (value - self.mean_old) / float(self.n + n)
    24            self.m_s += n * (value - self.mean_old) * (value - self.mean)
    25            self.mean_old = self.mean
    26            self.std = np.sqrt(self.m_s / (self.n + n - 1.0))
    27        self.var = self.std ** 2
    28
    29        self.n += n

Log a new value to the meter

Args: value: Next restult to include.

def value(self): View Source

    31    def value(self):
    32        return self.mean, self.std

Get the value of the meter in the current state.

def reset(self): View Source

    34    def reset(self):
    35        self.n = 0
    36        self.sum = 0.0
    37        self.var = 0.0
    38        self.val = 0.0
    39        self.mean = np.nan
    40        self.mean_old = 0.0
    41        self.m_s = 0.0
    42        self.std = np.nan

Resets the meter to default settings.