Skip to content

Commit 45a8bfb

Browse files
ppwwyyxxfacebook-github-bot
authored andcommitted
better logging in COCO evaluator
Summary: use logger instead of print Reviewed By: theschnitz Differential Revision: D26186047 fbshipit-source-id: 28b1bd2396cb88676f0f13537e499373ad24f4f7
1 parent d6e8c13 commit 45a8bfb

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

detectron2/evaluation/fast_eval_api.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# Copyright (c) Facebook, Inc. and its affiliates.
22
import copy
3+
import logging
34
import numpy as np
45
import time
56
from pycocotools.cocoeval import COCOeval
67

78
from detectron2 import _C
89

10+
logger = logging.getLogger(__name__)
11+
912

1013
class COCOeval_opt(COCOeval):
1114
"""
@@ -23,20 +26,18 @@ def evaluate(self):
2326
"""
2427
tic = time.time()
2528

26-
print("Running per image evaluation...")
2729
p = self.params
2830
# add backward compatibility if useSegm is specified in params
2931
if p.useSegm is not None:
3032
p.iouType = "segm" if p.useSegm == 1 else "bbox"
31-
print("useSegm (deprecated) is not None. Running {} evaluation".format(p.iouType))
32-
print("Evaluate annotation type *{}*".format(p.iouType))
33+
logger.info("Evaluate annotation type *{}*".format(p.iouType))
3334
p.imgIds = list(np.unique(p.imgIds))
3435
if p.useCats:
3536
p.catIds = list(np.unique(p.catIds))
3637
p.maxDets = sorted(p.maxDets)
3738
self.params = p
3839

39-
self._prepare()
40+
self._prepare() # bottleneck
4041

4142
# loop through images, area range, max detection number
4243
catIds = p.catIds if p.useCats else [-1]
@@ -47,7 +48,7 @@ def evaluate(self):
4748
computeIoU = self.computeOks
4849
self.ious = {
4950
(imgId, catId): computeIoU(imgId, catId) for imgId in p.imgIds for catId in catIds
50-
}
51+
} # bottleneck
5152

5253
maxDet = p.maxDets[-1]
5354

@@ -91,18 +92,19 @@ def convert_instances_to_cpp(instances, is_det=False):
9192

9293
self._paramsEval = copy.deepcopy(self.params)
9394
toc = time.time()
94-
print("COCOeval_opt.evaluate() finished in {:0.2f} seconds.".format(toc - tic))
95+
logger.info("COCOeval_opt.evaluate() finished in {:0.2f} seconds.".format(toc - tic))
9596
# >>>> End of code differences with original COCO API
9697

9798
def accumulate(self):
9899
"""
99100
Accumulate per image evaluation results and store the result in self.eval. Does not
100101
support changing parameter settings from those used by self.evaluate()
101102
"""
102-
print("Accumulating evaluation results...")
103+
logger.info("Accumulating evaluation results...")
103104
tic = time.time()
104-
if not hasattr(self, "_evalImgs_cpp"):
105-
print("Please run evaluate() first")
105+
assert hasattr(
106+
self, "_evalImgs_cpp"
107+
), "evaluate() must be called before accmulate() is called."
106108

107109
self.eval = _C.COCOevalAccumulate(self._paramsEval, self._evalImgs_cpp)
108110

@@ -116,4 +118,4 @@ def accumulate(self):
116118
self.eval["precision"] = np.array(self.eval["precision"]).reshape(self.eval["counts"])
117119
self.eval["scores"] = np.array(self.eval["scores"]).reshape(self.eval["counts"])
118120
toc = time.time()
119-
print("COCOeval_opt.accumulate() finished in {:0.2f} seconds.".format(toc - tic))
121+
logger.info("COCOeval_opt.accumulate() finished in {:0.2f} seconds.".format(toc - tic))

0 commit comments

Comments
 (0)