Evaluation does not support per category metrics
System information
- What is the top-level directory of the model you are using: research/object_detection
- Have I written custom code: no
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 16.04
- TensorFlow installed from (source or binary): binary
- TensorFlow version (use command below): 1.8.0 (tensorflow-gpu 1.3.0)
- Bazel version (if compiling from source):
- CUDA/cuDNN version: 8.0/7.1
- GPU model and memory:[GeForce GT 740]
- Exact command to reproduce: using the object_detection/model_main.py with include_metrics_per_category set true in the config file
Hi, Although the parameter 'include_metrics_per_category' for the training pipeline config file theoretically exists, it does not actually work. Setting it to true leads to an error message ('ValueError: Category stats do not exist'). object_detection/metrics/coco_tools.py throws this error. It uses pycocotool's 'COCOeval' to calculate evaluation metrics and in case the include_metrics_per_category parameter is true it looks for a dictionary called 'category_stats' but this actually never gets calculated in pycocotools cocoeval.py.
This feature would be very useful and i would appreciate if it was added or alternatively any guidance in how i could implement it myself.
Thank you in advance.
Adding reference to the issue in #4778 (also with all_metrics_per_category).
I'm experiencing the same problems as well and need this capability.
Same issue, is a fix planned? Thank you
Hi There, We are checking to see if you still need help on this, as this seems to be considerably old issue. Please update this issue with the latest information, code snippet to reproduce your issue and error you are seeing. If we don't hear from you in the next 7 days, this issue will be closed automatically. If you don't need help on this issue any more, please consider closing this.
Still facing the same issue. We might need to implement suggestion mentioned here https://github.com/cocodataset/cocoapi/issues/276
@tispratik Where you able to solev this?
Yes, following are the changes I did:
diff --git a/python/utils/modeling/_pipeline_template.config b/python/utils/modeling/_pipeline_template.config
index 83057d95..5ab97bbc 100644
--- a/python/utils/modeling/_pipeline_template.config
+++ b/python/utils/modeling/_pipeline_template.config
@@ -166,6 +166,8 @@ eval_config: {
# Note: The below line limits the evaluation process to 10 evaluations.
# Remove the below line to evaluate indefinitely.
max_evals: 3000
+ include_metrics_per_category: true
}
diff --git a/python/object_detection/metrics/coco_tools.py b/python/object_detection/metrics/coco_tools.py
index 71b747bc..83e6c5fd 100644
--- a/python/object_detection/metrics/coco_tools.py
+++ b/python/object_detection/metrics/coco_tools.py
@@ -237,6 +237,11 @@ class COCOEvalWrapper(cocoeval.COCOeval):
self.accumulate()
self.summarize()
+ # add for metrics per catergory from here
+ if include_metrics_per_category is True:
+ self.summarize_per_category()
+ # add for metrics per category end here
diff --git a/python/tensorflow_docker_requirements.txt b/python/tensorflow_docker_requirements.txt
index 74ce448c..51c4fce1 100644
--- a/python/tensorflow_docker_requirements.txt
+++ b/python/tensorflow_docker_requirements.txt
@@ -3,7 +3,7 @@ PyYAML
boto3
lxml
-git+https://github.com/waleedka/coco.git#subdirectory=PythonAPI
+git+https://github.com/philippschw/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI
awscli
@tispratik Thanks Prathik! Did you also make the changes to get Recall for every class?
Good catch. Here's more diff:
diff --git a/python/object_detection/metrics/coco_evaluation.py b/python/object_detection/metrics/coco_evaluation.py
index 08ab1ae2..9b437eca 100644
--- a/python/object_detection/metrics/coco_evaluation.py
+++ b/python/object_detection/metrics/coco_evaluation.py
@@ -327,9 +327,8 @@ class CocoDetectionEvaluator(object_detection_evaluation.ObjectDetectionEvaluato
for category_dict in self._categories:
metric_names.append('DetectionBoxes_PerformanceByCategory/mAP/' +
category_dict['name'])
- # for category_dict in self._categories:
- # metric_names.append('DetectionBoxes_PerformanceByCategory/AR/' +
- # category_dict['name'])
+ metric_names.append('DetectionBoxes_PerformanceByCategory/AR/' +
+ category_dict['name'])
diff --git a/python/object_detection/metrics/coco_tools.py b/python/object_detection/metrics/coco_tools.py
index 83e6c5fd..10a8db06 100644
--- a/python/object_detection/metrics/coco_tools.py
+++ b/python/object_detection/metrics/coco_tools.py
@@ -268,6 +268,8 @@ class COCOEvalWrapper(cocoeval.COCOeval):
# Kept for backward compatilbility
per_category_ap['PerformanceByCategory/mAP/{}'.format(
category)] = self.category_stats[0][category_index]
+ per_category_ap['PerformanceByCategory/AR/{}'.format(
+ category)] = self.category_stats[6][category_index]
if all_metrics_per_category:
per_category_ap['Precision mAP ByCategory/{}'.format(
category)] = self.category_stats[0][category_index]
@tispratik, could please guide how to display metrics per category? I have tried this https://github.com/tensorflow/models/issues/4778#issuecomment-430262110. But, unfortunately, I'm not able to get it and moreover,
I got an error.
could please help me.
@pkulzc Hi, could you please let us know how to print out metric per category in the tensorboard in the current tf2 version?
@IamExperimenting sounds like you are using tf2 version... my diff above is for non tf2. You have to figure out similar way, I am sorry I am not uptodate with the latest code base.
@IamExperimenting Did you solve this problem? I got the same error too on my Mask R-CNN evaluation.

Hello did anyone solve this issue. I am training MaskRCNN on custom objects and face similar issues
INFO:tensorflow:DONE (t=0.00s) I0518 16:16:53.172545 10464 coco_tools.py:138] DONE (t=0.00s) creating index... index created! Running per image evaluation... Evaluate annotation type bbox DONE (t=0.10s). Accumulating evaluation results... DONE (t=0.02s). Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.000 Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.003 Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.000 Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = -1.000 Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.000 Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.001 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.000 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.007 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.048 Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = -1.000 Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.000 Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.050 Traceback (most recent call last): File "C:\User_Data\notebook_projects\TFODCourse\Tensorflow\models\research\object_detection\model_main_tf2.py", line 114, in
tf.compat.v1.app.run() File "C:\User_Data\notebook_projects\notebook_venv\lib\site-packages\tensorflow\python\platform\app.py", line 36, in run _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "C:\User_Data\notebook_projects\notebook_venv\lib\site-packages\absl\app.py", line 312, in run _run_main(main, args) File "C:\User_Data\notebook_projects\notebook_venv\lib\site-packages\absl\app.py", line 258, in _run_main sys.exit(main(argv)) File "C:\User_Data\notebook_projects\TFODCourse\Tensorflow\models\research\object_detection\model_main_tf2.py", line 81, in main model_lib_v2.eval_continuously( File "C:\User_Data\notebook_projects\notebook_venv\lib\site-packages\object_detection\model_lib_v2.py", line 1159, in eval_continuously eager_eval_loop( File "C:\User_Data\notebook_projects\notebook_venv\lib\site-packages\object_detection\model_lib_v2.py", line 1010, in eager_eval_loop eval_metrics.update(evaluator.evaluate()) File "C:\User_Data\notebook_projects\notebook_venv\lib\site-packages\object_detection\metrics\coco_evaluation.py", line 304, in evaluate box_metrics, box_per_category_ap = box_evaluator.ComputeMetrics( File "C:\User_Data\notebook_projects\notebook_venv\lib\site-packages\object_detection\metrics\coco_tools.py", line 305, in ComputeMetrics raise ValueError('Category stats do not exist') ValueError: Category stats do not exist
@Nilesh-Hampiholi I solved by following https://github.com/tensorflow/models/issues/4778#issuecomment-430262110