Shortcuts

HistoryBuffer

class mmengine.logging.HistoryBuffer(log_history=[], count_history=[], max_length=1000000)[源代码]

Unified storage format for different log types.

HistoryBuffer records the history of log for further statistics.

实际案例

>>> history_buffer = HistoryBuffer()
>>> # Update history_buffer.
>>> history_buffer.update(1)
>>> history_buffer.update(2)
>>> history_buffer.min()  # minimum of (1, 2)
1
>>> history_buffer.max()  # maximum of (1, 2)
2
>>> history_buffer.mean()  # mean of (1, 2)
1.5
>>> history_buffer.statistics('mean')  # access method by string.
1.5
参数
  • log_history (Sequence) – History logs. Defaults to [].

  • count_history (Sequence) – Counts of history logs. Defaults to [].

  • max_length (int) – The max length of history logs. Defaults to 1000000.

current()[源代码]

Return the recently updated values in log histories.

返回

Recently updated values in log histories.

返回类型

np.ndarray

property data: Tuple[numpy.ndarray, numpy.ndarray]

Get the _log_history and _count_history.

返回

History logs and the counts of the history logs.

返回类型

Tuple[np.ndarray, np.ndarray]

max(window_size=None)[源代码]

Return the maximum value of the latest window_size values in log histories.

If window_size is None or window_size > len(self._log_history), return the global maximum value of history logs.

参数

window_size (int, optional) – Size of statistics window.

返回

The maximum value within the window.

返回类型

np.ndarray

mean(window_size=None)[源代码]

Return the mean of the latest window_size values in log histories.

If window_size is None or window_size > len(self._log_history), return the global mean value of history logs.

参数

window_size (int, optional) – Size of statistics window.

返回

Mean value within the window.

返回类型

np.ndarray

min(window_size=None)[源代码]

Return the minimum value of the latest window_size values in log histories.

If window_size is None or window_size > len(self._log_history), return the global minimum value of history logs.

参数

window_size (int, optional) – Size of statistics window.

返回

The minimum value within the window.

返回类型

np.ndarray

classmethod register_statistics(method)[源代码]

Register custom statistics method to _statistics_methods.

The registered method can be called by history_buffer.statistics with corresponding method name and arguments.

实际案例

>>> @HistoryBuffer.register_statistics
>>> def weighted_mean(self, window_size, weight):
>>>     assert len(weight) == window_size
>>>     return (self._log_history[-window_size:] *
>>>             np.array(weight)).sum() /             >>>             self._count_history[-window_size:]
>>> log_buffer = HistoryBuffer([1, 2], [1, 1])
>>> log_buffer.statistics('weighted_mean', 2, [2, 1])
2
参数

method (Callable) – Custom statistics method.

返回

Original custom statistics method.

返回类型

Callable

statistics(method_name, *arg, **kwargs)[源代码]

Access statistics method by name.

参数

method_name (str) – Name of method.

返回

Depends on corresponding method.

返回类型

Any

update(log_val, count=1)[源代码]

update the log history.

If the length of the buffer exceeds self._max_length, the oldest element will be removed from the buffer.

参数
  • log_val (int or float) – The value of log.

  • count (int) – The accumulation times of log, defaults to 1.

  • statistics. (count will be used in smooth) –

返回类型

None

Read the Docs v: v0.7.0
Versions
latest
stable
v0.7.0
v0.6.0
v0.5.0
v0.4.0
v0.3.0
v0.2.0
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.