WZMIAOMIAO/deep-learning-for-image-processing · error · Exception
Please run accumulate() first
Error message
Please run accumulate() first
What it means
COCO's summarize() requires evaluation results accumulated by accumulate() first; the internal self.eval is None until then. Calling summarize() before accumulate() raises a generic Exception telling the user the required prior step was skipped.
Source
Thrown at pytorch_object_detection/train_coco_dataset/validation.py:89
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))
data_transform = {
"val": transforms.Compose([transforms.ToTensor()])
}
# read class_indict
label_json_path = './coco91_indices.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:
category_index = json.load(f)
View on GitHub (pinned to 1ec3fe6f37)
Solutions
- Call evaluator.accumulate() before summarize()
- Ensure evaluate() ran and predictions were loaded (evaluator.update() calls) before accumulate
- If summarizing multiple times, reuse the same evaluator after a single accumulate
Example fix
// before coco_evaluator = COCOeval(coco, iouType='bbox') coco_evaluator.evaluate() stats, print_info = summarize(coco_evaluator) // after coco_evaluator = COCOeval(coco, iouType='bbox') coco_evaluator.evaluate() coco_evaluator.accumulate() stats, print_info = summarize(coco_evaluator)
Defensive patterns
Strategy: validation
Validate before calling
def safe_summarize(evaluator):
if getattr(evaluator, 'eval', None) is None:
evaluator.accumulate()
return evaluator.summarize() Try / catch
try:
stats, print_info = summarize(coco_evaluator)
except Exception as e:
if 'Please run accumulate() first' in str(e):
coco_evaluator.accumulate()
stats, print_info = summarize(coco_evaluator)
else:
raise Prevention
- Always follow the evaluate() -> accumulate() -> summarize() order
- Encapsulate the full COCOeval sequence in one helper function
- Never call summarize() on a freshly constructed evaluator
When it happens
Trigger: Calling coco_evaluator.summarize() immediately after constructing a COCOeval object, without first calling accumulate().
Common situations: Custom evaluation scripts that build COCOeval but forget the accumulate() step; reordering calls after refactoring; catching only some stats and calling summarize twice on a fresh evaluator.
Related errors
- expected stages_repeats as list of 3 positive ints
- expected stages_out_channels as list of 5 positive ints
- image: {} isn't RGB mode.
- not find GPU device for training.
- dataset have {} classes, but input {}
AI-assisted analysis of WZMIAOMIAO/deep-learning-for-image-processing@1ec3fe6f37 (2026-08-30).
Data as JSON: /api/errors/f92c473cc70287a9.
Report an issue: GitHub.