WZMIAOMIAO/deep-learning-for-image-processing · error · Exception
Please run accumulate() first
Error message
Please run accumulate() first
What it means
The COCO-style evaluator's summarize() requires that accumulate() has run first, because self.eval is only populated by accumulate(). If self.eval is None/empty, summarize raises Exception('Please run accumulate() first'). It enforces the correct call order: evaluate() -> accumulate() -> summarize().
Source
Thrown at pytorch_object_detection/yolov3_spp/validation.py:80
stats, print_list = [0] * 12, [""] * 12
stats[0], print_list[0] = _summarize(1)
stats[1], print_list[1] = _summarize(1, iouThr=.5, maxDets=self.params.maxDets[2])
stats[2], print_list[2] = _summarize(1, iouThr=.75, maxDets=self.params.maxDets[2])
stats[3], print_list[3] = _summarize(1, areaRng='small', maxDets=self.params.maxDets[2])
stats[4], print_list[4] = _summarize(1, areaRng='medium', maxDets=self.params.maxDets[2])
stats[5], print_list[5] = _summarize(1, areaRng='large', maxDets=self.params.maxDets[2])
stats[6], print_list[6] = _summarize(0, maxDets=self.params.maxDets[0])
stats[7], print_list[7] = _summarize(0, maxDets=self.params.maxDets[1])
stats[8], print_list[8] = _summarize(0, maxDets=self.params.maxDets[2])
stats[9], print_list[9] = _summarize(0, areaRng='small', maxDets=self.params.maxDets[2])
stats[10], print_list[10] = _summarize(0, areaRng='medium', maxDets=self.params.maxDets[2])
stats[11], print_list[11] = _summarize(0, areaRng='large', maxDets=self.params.maxDets[2])
print_info = "\n".join(print_list)
if not self.eval:
raise Exception('Please run accumulate() first')
return stats, print_info
def main(parser_data):
device = torch.device(parser_data.device if torch.cuda.is_available() else "cpu")
print("Using {} device training.".format(device.type))
# read class_indict
label_json_path = './data/pascal_voc_classes.json'
assert os.path.exists(label_json_path), "json file {} dose not exist.".format(label_json_path)
with open(label_json_path, 'r') as f:
class_dict = json.load(f)
category_index = {v: k for k, v in class_dict.items()}
data_dict = parse_data_cfg(parser_data.data)
test_path = data_dict["valid"]View on GitHub (pinned to 1ec3fe6f37)
Solutions
- Ensure the loop calls evaluator.accumulate() after evaluate() and before summarize().
- Check that accumulate() is not skipped by a conditional/early return when predictions exist.
- If self.eval can legitimately be empty, guard with `if evaluator.eval: evaluator.summarize()`.
Example fix
// before
for images, targets in val_loader:
evaluator.update(predictions)
evaluator.summarize()
// after
for images, targets in val_loader:
evaluator.update(predictions)
evaluator.accumulate()
evaluator.summarize() Defensive patterns
Strategy: validation
Validate before calling
if evaluator.eval is None:
evaluator.accumulate()
evaluator.summarize() Type guard
def can_summarize(evaluator) -> bool:
return getattr(evaluator, 'eval', None) is not None Try / catch
try:
stats, info = evaluator.summarize()
except Exception as e:
if 'accumulate' in str(e):
evaluator.accumulate(); stats, info = evaluator.summarize()
else:
raise Prevention
- Always follow the evaluate -> accumulate -> summarize order
- Avoid early returns between accumulate and summarize
- Wrap the three calls in one helper function
When it happens
Trigger: Calling evaluator.summarize() (from validation.py main) without having called evaluator.accumulate() beforehand, or accumulate() being skipped on an error/no-data path.
Common situations: Writing custom validation loops that call summarize directly; early-exit code paths that skip accumulation when the dataloader is empty; refactoring that reordered accumulate/summarize calls.
Related errors
- sampler should be an instance of torch.utils.data.Sampler, b
- VOCdevkit dose not in path:'{}'.
- return_layers are not present in model
- Expected target boxes to be a tensorof shape [N, 4], got {:}
- Expected target boxes to be of type Tensor, got {:}.
AI-assisted analysis of WZMIAOMIAO/deep-learning-for-image-processing@1ec3fe6f37 (2026-08-30).
Data as JSON: /api/errors/9bcffe5af06337a7.
Report an issue: GitHub.