From 765e80c038caafa78816f4955067df96c4fa8e92 Mon Sep 17 00:00:00 2001 From: Kaipeng Deng Date: Wed, 21 Apr 2021 10:12:37 +0800 Subject: [PATCH] fix voc difficult not found & map_res empty (#2714) --- ppdet/data/source/voc.py | 7 ++++++- ppdet/engine/callbacks.py | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ppdet/data/source/voc.py b/ppdet/data/source/voc.py index 562366ae8..56b746c14 100644 --- a/ppdet/data/source/voc.py +++ b/ppdet/data/source/voc.py @@ -117,7 +117,12 @@ class VOCDataSet(DetDataset): difficult = [] for i, obj in enumerate(objs): cname = obj.find('name').text - _difficult = int(obj.find('difficult').text) + + # user dataset may not contain difficult field + _difficult = obj.find('difficult') + _difficult = int( + _difficult.text) if _difficult is not None else 0 + x1 = float(obj.find('bndbox').find('xmin').text) y1 = float(obj.find('bndbox').find('ymin').text) x2 = float(obj.find('bndbox').find('xmax').text) diff --git a/ppdet/engine/callbacks.py b/ppdet/engine/callbacks.py index 410de7744..9d418119f 100644 --- a/ppdet/engine/callbacks.py +++ b/ppdet/engine/callbacks.py @@ -179,6 +179,11 @@ class Checkpointer(Callback): for metric in self.model._metrics: map_res = metric.get_results() key = 'bbox' if 'bbox' in map_res else 'mask' + if key not in map_res: + logger.warn("Evaluation results empty, this may be due to " \ + "training iterations being too few or not " \ + "loading the correct weights.") + return if map_res[key][0] > self.best_ap: self.best_ap = map_res[key][0] save_name = 'best_model' -- GitLab