Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object Detection API: Fix the offline evaluation pipeline #6156

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions research/object_detection/metrics/offline_eval_map_corloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import tensorflow as tf

from object_detection.core import standard_fields
from object_detection.legacy import evaluator
from object_detection import eval_util
from object_detection.metrics import tf_example_parser
from object_detection.utils import config_util
from object_detection.utils import label_map_util
Expand Down Expand Up @@ -94,8 +94,10 @@ def read_data_and_evaluate(input_config, eval_config):
categories = label_map_util.create_categories_from_labelmap(
input_config.label_map_path)

object_detection_evaluators = evaluator.get_evaluators(
eval_config, categories)
evaluator_options = eval_util.evaluator_options_from_eval_config(
eval_config)
object_detection_evaluators = eval_util.get_evaluators(
eval_config, categories, evaluator_options)
# Support a single evaluator
object_detection_evaluator = object_detection_evaluators[0]

Expand Down Expand Up @@ -159,7 +161,7 @@ def main(argv):
eval_config_path=FLAGS.eval_config_path)

eval_config = configs['eval_config']
input_config = configs['eval_input_config']
input_config = configs['eval_input_configs'][0]

metrics = read_data_and_evaluate(input_config, eval_config)

Expand Down
10 changes: 7 additions & 3 deletions research/object_detection/metrics/tf_example_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ def __init__(self, field_name):
self.field_name = field_name

def parse(self, tf_example):
return "".join(tf_example.features.feature[self.field_name]
.bytes_list.value) if tf_example.features.feature[
self.field_name].HasField("bytes_list") else None
if tf_example.features.feature[self.field_name].HasField("bytes_list"):
return "".join(
[element.decode("utf-8") for element in
tf_example.features.feature[self.field_name].bytes_list.value]
)
else:
return None


class Int64Parser(data_parser.DataToNumpyParser):
Expand Down
11 changes: 9 additions & 2 deletions research/object_detection/utils/object_detection_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import collections
import logging
import unicodedata
import sys
import numpy as np
import tensorflow as tf

Expand Down Expand Up @@ -210,7 +211,10 @@ def _build_metric_names(self):
if idx + self._label_id_offset in category_index:
category_name = category_index[idx + self._label_id_offset]['name']
try:
category_name = unicode(category_name, 'utf-8')
if sys.version_info >= (3, 0):
category_name = str(category_name, 'utf-8')
else:
category_name = unicode(category_name, 'utf-8')
except TypeError:
pass
category_name = unicodedata.normalize('NFKD', category_name).encode(
Expand Down Expand Up @@ -348,7 +352,10 @@ def evaluate(self):
if idx + self._label_id_offset in category_index:
category_name = category_index[idx + self._label_id_offset]['name']
try:
category_name = unicode(category_name, 'utf-8')
if sys.version_info >= (3, 0):
category_name = str(category_name, 'utf-8')
else:
category_name = unicode(category_name, 'utf-8')
except TypeError:
pass
category_name = unicodedata.normalize(
Expand Down