AverageMeter¶
danling.metrics.average_meter
¶
AverageMeter
¶
Computes and stores the average and current value.
Attributes:
Name | Type | Description |
---|---|---|
val |
float
|
Results of current batch on current device. |
bat |
Results of current batch on all devices. |
|
avg |
Results of all results on all devices. |
|
sum |
float
|
Sum of values. |
count |
float
|
Number of values. |
See Also
[MetricMeter
]: Average Meter with metric function built-in.
[AverageMeters
]: Manage multiple average meters in one object.
[MultiTaskAverageMeters
]: Manage multiple average meters in one object with multi-task support.
Examples:
>>> meter = AverageMeter()
>>> meter.update(0.7)
>>> meter.val
0.7
>>> meter.avg
0.7
>>> meter.update(0.9)
>>> meter.val
0.9
>>> meter.avg
0.8
>>> meter.sum
1.6
>>> meter.count
2
>>> meter.reset()
>>> meter.val
0
>>> meter.avg
nan
Source code in danling/metrics/average_meter.py
Python | |
---|---|
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
AverageMeters
¶
Bases: MetricsDict
Manages multiple average meters in one object.
See Also
[AverageMeter
]: Computes and stores the average and current value.
[MultiTaskAverageMeters
]: Manage multiple average meters in one object with multi-task support.
[MetricMeters
]: Manage multiple metric meters in one object.
Examples:
>>> meters = AverageMeters()
>>> meters.update({"loss": 0.6, "auroc": 0.7, "r2": 0.8})
>>> f"{meters:.4f}"
'loss: 0.6000 (0.6000)\tauroc: 0.7000 (0.7000)\tr2: 0.8000 (0.8000)'
>>> meters['loss'].update(value=0.9, n=1)
>>> f"{meters:.4f}"
'loss: 0.9000 (0.7500)\tauroc: 0.7000 (0.7000)\tr2: 0.8000 (0.8000)'
>>> meters.sum.dict()
{'loss': 1.5, 'auroc': 0.7, 'r2': 0.8}
>>> meters.count.dict()
{'loss': 2, 'auroc': 1, 'r2': 1}
>>> meters.reset()
>>> f"{meters:.4f}"
'loss: 0.0000 (nan)\tauroc: 0.0000 (nan)\tr2: 0.0000 (nan)'
Source code in danling/metrics/average_meter.py
update
¶
Updates the average and current value in all meters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values |
int | float
|
Dict of values to be added to the average. |
{}
|
n |
Number of values to be added. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the value is not an instance of (int, float). |
Source code in danling/metrics/average_meter.py
MultiTaskAverageMeters
¶
Bases: MultiTaskDict
Manages multiple average meters in one object with multi-task support.
See Also
[AverageMeter
]: Computes and stores the average and current value.
[AverageMeters
]: Manage multiple average meters in one object.
[MetricMeters
]: Manage multiple metric meters in one object.
Examples:
>>> meters = MultiTaskAverageMeters()
>>> meters.update({"loss": 0.6, "dataset1.cls.auroc": 0.7, "dataset1.reg.r2": 0.8, "dataset2.r2": 0.9})
>>> f"{meters:.4f}"
'loss: 0.6000 (0.6000)\ndataset1.cls.auroc: 0.7000 (0.7000)\ndataset1.reg.r2: 0.8000 (0.8000)\ndataset2.r2: 0.9000 (0.9000)'
>>> meters['loss'].update(0.9, n=1)
>>> f"{meters:.4f}"
'loss: 0.9000 (0.7500)\ndataset1.cls.auroc: 0.7000 (0.7000)\ndataset1.reg.r2: 0.8000 (0.8000)\ndataset2.r2: 0.9000 (0.9000)'
>>> meters.sum.dict()
{'loss': 1.5, 'dataset1': {'cls': {'auroc': 0.7}, 'reg': {'r2': 0.8}}, 'dataset2': {'r2': 0.9}}
>>> meters.count.dict()
{'loss': 2, 'dataset1': {'cls': {'auroc': 1}, 'reg': {'r2': 1}}, 'dataset2': {'r2': 1}}
>>> meters.reset()
>>> f"{meters:.4f}"
'loss: 0.0000 (nan)\ndataset1.cls.auroc: 0.0000 (nan)\ndataset1.reg.r2: 0.0000 (nan)\ndataset2.r2: 0.0000 (nan)'
>>> meters = MultiTaskAverageMeters(return_average=True)
>>> meters.update({"loss": 0.6, "dataset1.a.auroc": 0.7, "dataset1.b.auroc": 0.8, "dataset2.auroc": 0.9})
>>> f"{meters:.4f}"
'loss: 0.6000 (0.6000)\ndataset1.a.auroc: 0.7000 (0.7000)\ndataset1.b.auroc: 0.8000 (0.8000)\ndataset2.auroc: 0.9000 (0.9000)'
>>> meters.update({"loss": 0.9, "dataset1.a.auroc": 0.8, "dataset1.b.auroc": 0.9, "dataset2.auroc": 1.0})
>>> f"{meters:.4f}"
'loss: 0.9000 (0.7500)\ndataset1.a.auroc: 0.8000 (0.7500)\ndataset1.b.auroc: 0.9000 (0.8500)\ndataset2.auroc: 1.0000 (0.9500)'
Source code in danling/metrics/average_meter.py
Python | |
---|---|
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
|
update
¶
Updates the average and current value in all meters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values |
float
|
Dict of values to be added to the average. |
{}
|
n |
Number of values to be added. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the value is not an instance of (int, float, Mapping). |