Computes and stores the average and current value
| 116 | |
| 117 | |
| 118 | class AverageMeter(object): |
| 119 | """Computes and stores the average and current value""" |
| 120 | def __init__(self): |
| 121 | self.reset() |
| 122 | |
| 123 | def reset(self): |
| 124 | self.val = 0 |
| 125 | self.avg = 0 |
| 126 | self.sum = 0 |
| 127 | self.count = 0 |
| 128 | |
| 129 | def update(self, val, n=1): |
| 130 | self.val = val |
| 131 | self.sum += val * n |
| 132 | self.count += n |
| 133 | self.avg = self.sum / self.count |
| 134 | |
| 135 | |
| 136 | class Identity(nn.Module): |