Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #277 from yuyu2172/change-eval-detection
Browse files Browse the repository at this point in the history
Change eval_detection_voc_ap to eval_detection_voc
  • Loading branch information
Hakuyume authored Jun 14, 2017
2 parents 318f11e + cad7027 commit 3ddd53e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 29 deletions.
6 changes: 3 additions & 3 deletions chainercv/evaluations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from chainercv.evaluations.eval_detection_voc_ap import calc_detection_voc_ap # NOQA
from chainercv.evaluations.eval_detection_voc_ap import calc_detection_voc_prec_rec # NOQA
from chainercv.evaluations.eval_detection_voc_ap import eval_detection_voc_ap # NOQA
from chainercv.evaluations.eval_detection_voc import calc_detection_voc_ap # NOQA
from chainercv.evaluations.eval_detection_voc import calc_detection_voc_prec_rec # NOQA
from chainercv.evaluations.eval_detection_voc import eval_detection_voc # NOQA
from chainercv.evaluations.eval_semantic_segmentation_iou import calc_semantic_segmentation_confusion # NOQA
from chainercv.evaluations.eval_semantic_segmentation_iou import calc_semantic_segmentation_iou # NOQA
from chainercv.evaluations.eval_semantic_segmentation_iou import eval_semantic_segmentation_iou # NOQA
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from chainercv.utils.bbox.bbox_iou import bbox_iou


def eval_detection_voc_ap(
def eval_detection_voc(
pred_bboxes, pred_labels, pred_scores, gt_bboxes, gt_labels,
gt_difficults=None,
iou_thresh=0.5, use_07_metric=False):
Expand Down Expand Up @@ -56,12 +56,17 @@ def eval_detection_voc_ap(
:obj:`False`.
Returns:
~numpy.ndarray:
This function returns an array of average precisions.
The :math:`l`-th value corresponds to the average precision
for class :math:`l`. If class :math:`l` does not exist in
either :obj:`pred_labels` or :obj:`gt_labels`, the corresponding
value is set to :obj:`numpy.nan`.
dict:
The keys, value-types and the description of the values are listed
below.
* **ap** (*numpy.ndarray*): An array of average precisions. \
The :math:`l`-th value corresponds to the average precision \
for class :math:`l`. If class :math:`l` does not exist in \
either :obj:`pred_labels` or :obj:`gt_labels`, the corresponding \
value is set to :obj:`numpy.nan`.
* **map** (*float*): The average of Average Precisions over classes.
"""

Expand All @@ -72,7 +77,7 @@ def eval_detection_voc_ap(

ap = calc_detection_voc_ap(prec, rec, use_07_metric=use_07_metric)

return ap
return {'ap': ap, 'map': np.nanmean(ap)}


def calc_detection_voc_prec_rec(
Expand Down
8 changes: 4 additions & 4 deletions chainercv/extensions/detection/detection_voc_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from chainer import reporter
import chainer.training.extensions

from chainercv.evaluations import eval_detection_voc_ap
from chainercv.evaluations import eval_detection_voc
from chainercv.utils import apply_prediction_to_iterator


Expand Down Expand Up @@ -85,17 +85,17 @@ def evaluate(self):
gt_bboxes, gt_labels = gt_values
gt_difficults = None

ap = eval_detection_voc_ap(
result = eval_detection_voc(
pred_bboxes, pred_labels, pred_scores,
gt_bboxes, gt_labels, gt_difficults,
use_07_metric=self.use_07_metric)

report = {'map': np.nanmean(ap)}
report = {'map': result['map']}

if self.label_names is not None:
for l, label_name in enumerate(self.label_names):
try:
report['ap/{:s}'.format(label_name)] = ap[l]
report['ap/{:s}'.format(label_name)] = result['ap'][l]
except IndexError:
report['ap/{:s}'.format(label_name)] = np.nan

Expand Down
6 changes: 3 additions & 3 deletions docs/source/reference/evaluations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Evaluations
Detection VOC
-------------

eval_detection_voc_ap
~~~~~~~~~~~~~~~~~~~~~
.. autofunction:: eval_detection_voc_ap
eval_detection_voc
~~~~~~~~~~~~~~~~~~
.. autofunction:: eval_detection_voc

calc_detection_voc_ap
~~~~~~~~~~~~~~~~~~~~~
Expand Down
12 changes: 5 additions & 7 deletions examples/detection/eval_voc07.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import division

import argparse
import numpy as np
import sys
import time

Expand All @@ -10,7 +9,7 @@

from chainercv.datasets import voc_detection_label_names
from chainercv.datasets import VOCDetectionDataset
from chainercv.evaluations import eval_detection_voc_ap
from chainercv.evaluations import eval_detection_voc
from chainercv.links import FasterRCNNVGG16
from chainercv.links import SSD300
from chainercv.links import SSD512
Expand Down Expand Up @@ -86,17 +85,16 @@ def main():
pred_bboxes, pred_labels, pred_scores = pred_values
gt_bboxes, gt_labels, gt_difficults = gt_values

ap = eval_detection_voc_ap(
result = eval_detection_voc(
pred_bboxes, pred_labels, pred_scores,
gt_bboxes, gt_labels, gt_difficults,
use_07_metric=True)
map_ = np.nanmean(ap)

print()
print('mAP: {:f}'.format(map_))
print('mAP: {:f}'.format(result['map']))
for l, name in enumerate(voc_detection_label_names):
if ap[l]:
print('{:s}: {:f}'.format(name, ap[l]))
if result['ap'][l]:
print('{:s}: {:f}'.format(name, result['ap'][l]))
else:
print('{:s}: -'.format(name))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from chainercv.evaluations import calc_detection_voc_ap
from chainercv.evaluations import calc_detection_voc_prec_rec
from chainercv.evaluations import eval_detection_voc_ap
from chainercv.evaluations import eval_detection_voc


@testing.parameterize(*(
Expand Down Expand Up @@ -190,7 +190,7 @@ def setUpClass(cls):
base_url,
'voc_detection_result_2007_test_truncated_2017_06_06.npz'))[0])

def test_eval_detection_voc_ap(self):
def test_eval_detection_voc(self):
pred_bboxes = self.result['bboxes']
pred_labels = self.result['labels']
pred_scores = self.result['scores']
Expand All @@ -199,7 +199,7 @@ def test_eval_detection_voc_ap(self):
gt_labels = self.dataset['labels']
gt_difficults = self.dataset['difficults']

ap = eval_detection_voc_ap(
result = eval_detection_voc(
pred_bboxes, pred_labels, pred_scores,
gt_bboxes, gt_labels, gt_difficults,
use_07_metric=True)
Expand Down Expand Up @@ -228,4 +228,6 @@ def test_eval_detection_voc_ap(self):
0.654545,
]

np.testing.assert_almost_equal(ap, expected, decimal=5)
np.testing.assert_almost_equal(result['ap'], expected, decimal=5)
np.testing.assert_almost_equal(
result['map'], np.nanmean(expected), decimal=5)

0 comments on commit 3ddd53e

Please sign in to comment.