Upload utils.py
Browse files
utils.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class AvgMeter:
|
| 2 |
+
def __init__(self, name="Metric"):
|
| 3 |
+
self.name = name
|
| 4 |
+
self.reset()
|
| 5 |
+
|
| 6 |
+
def reset(self):
|
| 7 |
+
self.avg, self.sum, self.count = [0] * 3
|
| 8 |
+
|
| 9 |
+
def update(self, val, count=1):
|
| 10 |
+
self.count += count
|
| 11 |
+
self.sum += val * count
|
| 12 |
+
self.avg = self.sum / self.count
|
| 13 |
+
|
| 14 |
+
def __repr__(self):
|
| 15 |
+
text = f"{self.name}: {self.avg:.4f}"
|
| 16 |
+
return text
|
| 17 |
+
|
| 18 |
+
def get_lr(optimizer):
|
| 19 |
+
for param_group in optimizer.param_groups:
|
| 20 |
+
return param_group["lr"]
|