Update xmisc
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#####################################################
|
||||
# Copyright (c) Xuanyi Dong [GitHub D-X-Y], 2021.06 #
|
||||
#####################################################
|
||||
"""The module and yaml related functions."""
|
||||
from .module_utils import call_by_dict
|
||||
from .module_utils import call_by_yaml
|
||||
from .module_utils import nested_call_by_dict
|
||||
@@ -11,10 +12,13 @@ from .torch_utils import count_parameters
|
||||
|
||||
from .logger_utils import Logger
|
||||
|
||||
# sampler
|
||||
"""The data sampler related classes."""
|
||||
from .sampler_utils import BatchSampler
|
||||
|
||||
# scheduler related
|
||||
"""The meter related classes."""
|
||||
from .meter_utils import AverageMeter
|
||||
|
||||
"""The scheduler related classes."""
|
||||
from .scheduler_utils import CosineParamScheduler, WarmupParamScheduler, LRMultiplier
|
||||
|
||||
|
||||
|
22
xautodl/xmisc/meter_utils.py
Normal file
22
xautodl/xmisc/meter_utils.py
Normal file
@@ -0,0 +1,22 @@
|
||||
class AverageMeter:
|
||||
"""Computes and stores the average and current value"""
|
||||
|
||||
def __init__(self):
|
||||
self.reset()
|
||||
|
||||
def reset(self):
|
||||
self.val = 0.0
|
||||
self.avg = 0.0
|
||||
self.sum = 0.0
|
||||
self.count = 0.0
|
||||
|
||||
def update(self, val, n=1):
|
||||
self.val = val
|
||||
self.sum += val * n
|
||||
self.count += n
|
||||
self.avg = self.sum / self.count
|
||||
|
||||
def __repr__(self):
|
||||
return "{name}(val={val}, avg={avg}, count={count})".format(
|
||||
name=self.__class__.__name__, **self.__dict__
|
||||
)
|
Reference in New Issue
Block a user