Computes and stores the average and current value
| 458 | |
| 459 | |
| 460 | class AverageMeter: |
| 461 | """Computes and stores the average and current value""" |
| 462 | val: float |
| 463 | avg: float |
| 464 | sum: float |
| 465 | count: int |
| 466 | |
| 467 | def __init__(self): |
| 468 | self.reset() |
| 469 | |
| 470 | def reset(self): |
| 471 | self.val = 0 |
| 472 | self.avg = 0 |
| 473 | self.sum = 0 |
| 474 | self.count = 0 |
| 475 | |
| 476 | def update(self, val: float, n: int = 1): |
| 477 | self.val = val |
| 478 | self.sum += val * n |
| 479 | self.count += n |
| 480 | self.avg = self.sum / self.count |
| 481 | |
| 482 | |
| 483 | def accuracy(output, target, topk=(1,)): |
no outgoing calls
no test coverage detected