@@ -63,6 +63,9 @@ def _eval_by_dataset(
63
63
) -> Tuple [float , Dict [str , Dict [str , float ]]]:
64
64
"""Evaluate with computing metric on total samples(default process).
65
65
66
+ NOTE: This is the default evaluation method as general for most cases, but may not
67
+ memory-efficiency for large dataset or large output.
68
+
66
69
Args:
67
70
solver (solver.Solver): Main Solver.
68
71
epoch_id (int): Epoch id.
@@ -159,6 +162,7 @@ def _eval_by_dataset(
159
162
160
163
metric_dict_group : Dict [str , Dict [str , float ]] = misc .PrettyOrderedDict ()
161
164
for metric_name , metric_func in _validator .metric .items ():
165
+ # NOTE: compute metric with entire output and label
162
166
metric_dict = metric_func (all_output , all_label )
163
167
metric_dict_group [metric_name ] = {
164
168
k : float (v ) for k , v in metric_dict .items ()
@@ -189,6 +193,10 @@ def _eval_by_batch(
189
193
) -> Tuple [float , Dict [str , Dict [str , float ]]]:
190
194
"""Evaluate with computing metric by batch, which is memory-efficient.
191
195
196
+ NOTE: This is a evaluation function for large dataset or large output, as is more
197
+ memory-efficiency than evaluating by dataset, but less general because some metric
198
+ is not independent among samples, e.g. L2 relative error.
199
+
192
200
Args:
193
201
solver (solver.Solver): Main Solver.
194
202
epoch_id (int): Epoch id.
@@ -270,7 +278,10 @@ def _eval_by_batch(
270
278
# concatenate all metric and discard metric of padded sample(s)
271
279
for metric_name , metric_dict in metric_dict_group .items ():
272
280
for var_name , metric_value in metric_dict .items ():
281
+ # NOTE: concat all metric(scalars) into metric vector
273
282
metric_value = paddle .concat (metric_value )[:num_samples ]
283
+ # NOTE: compute metric via averaging metric vector,
284
+ # this might be not general for certain evaluation case
274
285
metric_value = float (metric_value .mean ())
275
286
metric_dict_group [metric_name ][var_name ] = metric_value
276
287
metric_str = f"{ _validator .name } /{ metric_name } .{ var_name } "
0 commit comments