Commit 3040f522 authored by Yoni Ben-Meshulam's avatar Yoni Ben-Meshulam Committed by TF Object Detection Team
Browse files

Replace ValueError with warning when image_id has a hash conflict

PiperOrigin-RevId: 352873888
parent e02da657
...@@ -254,7 +254,7 @@ class ObjectDetectionEvaluator(DetectionEvaluator): ...@@ -254,7 +254,7 @@ class ObjectDetectionEvaluator(DetectionEvaluator):
""" """
for image_id in image_ids: for image_id in image_ids:
if image_id in self._image_ids: if image_id in self._image_ids:
raise ValueError('Image with id {} already added.'.format(image_id)) logging.warning('Image with id %s already added.', image_id)
self._evaluation.merge_internal_state(state_tuple) self._evaluation.merge_internal_state(state_tuple)
...@@ -321,7 +321,7 @@ class ObjectDetectionEvaluator(DetectionEvaluator): ...@@ -321,7 +321,7 @@ class ObjectDetectionEvaluator(DetectionEvaluator):
raise error if instance masks are not in groundtruth dictionary. raise error if instance masks are not in groundtruth dictionary.
""" """
if image_id in self._image_ids: if image_id in self._image_ids:
raise ValueError('Image with id {} already added.'.format(image_id)) logging.warning('Image with id %s already added.', image_id)
groundtruth_classes = ( groundtruth_classes = (
groundtruth_dict[standard_fields.InputDataFields.groundtruth_classes] - groundtruth_dict[standard_fields.InputDataFields.groundtruth_classes] -
...@@ -729,7 +729,7 @@ class OpenImagesDetectionEvaluator(ObjectDetectionEvaluator): ...@@ -729,7 +729,7 @@ class OpenImagesDetectionEvaluator(ObjectDetectionEvaluator):
ValueError: On adding groundtruth for an image more than once. ValueError: On adding groundtruth for an image more than once.
""" """
if image_id in self._image_ids: if image_id in self._image_ids:
raise ValueError('Image with id {} already added.'.format(image_id)) logging.warning('Image with id %s already added.', image_id)
groundtruth_classes = ( groundtruth_classes = (
groundtruth_dict[standard_fields.InputDataFields.groundtruth_classes] - groundtruth_dict[standard_fields.InputDataFields.groundtruth_classes] -
......
...@@ -524,30 +524,6 @@ class PascalEvaluationTest(tf.test.TestCase): ...@@ -524,30 +524,6 @@ class PascalEvaluationTest(tf.test.TestCase):
pascal_evaluator.clear() pascal_evaluator.clear()
self.assertFalse(pascal_evaluator._image_ids) self.assertFalse(pascal_evaluator._image_ids)
def test_value_error_on_duplicate_images(self):
categories = [{'id': 1, 'name': 'cat'},
{'id': 2, 'name': 'dog'},
{'id': 3, 'name': 'elephant'}]
# Add groundtruth
pascal_evaluator = object_detection_evaluation.PascalDetectionEvaluator(
categories)
image_key1 = 'img1'
groundtruth_boxes1 = np.array([[0, 0, 1, 1], [0, 0, 2, 2], [0, 0, 3, 3]],
dtype=float)
groundtruth_class_labels1 = np.array([1, 3, 1], dtype=int)
pascal_evaluator.add_single_ground_truth_image_info(
image_key1,
{standard_fields.InputDataFields.groundtruth_boxes: groundtruth_boxes1,
standard_fields.InputDataFields.groundtruth_classes:
groundtruth_class_labels1})
with self.assertRaises(ValueError):
pascal_evaluator.add_single_ground_truth_image_info(
image_key1,
{standard_fields.InputDataFields.groundtruth_boxes:
groundtruth_boxes1,
standard_fields.InputDataFields.groundtruth_classes:
groundtruth_class_labels1})
class WeightedPascalEvaluationTest(tf.test.TestCase): class WeightedPascalEvaluationTest(tf.test.TestCase):
...@@ -659,28 +635,6 @@ class WeightedPascalEvaluationTest(tf.test.TestCase): ...@@ -659,28 +635,6 @@ class WeightedPascalEvaluationTest(tf.test.TestCase):
self.wp_eval.clear() self.wp_eval.clear()
self.assertFalse(self.wp_eval._image_ids) self.assertFalse(self.wp_eval._image_ids)
def test_value_error_on_duplicate_images(self):
# Add groundtruth
self.wp_eval = (
object_detection_evaluation.WeightedPascalDetectionEvaluator(
self.categories))
image_key1 = 'img1'
groundtruth_boxes1 = np.array([[0, 0, 1, 1], [0, 0, 2, 2], [0, 0, 3, 3]],
dtype=float)
groundtruth_class_labels1 = np.array([1, 3, 1], dtype=int)
self.wp_eval.add_single_ground_truth_image_info(
image_key1,
{standard_fields.InputDataFields.groundtruth_boxes: groundtruth_boxes1,
standard_fields.InputDataFields.groundtruth_classes:
groundtruth_class_labels1})
with self.assertRaises(ValueError):
self.wp_eval.add_single_ground_truth_image_info(
image_key1,
{standard_fields.InputDataFields.groundtruth_boxes:
groundtruth_boxes1,
standard_fields.InputDataFields.groundtruth_classes:
groundtruth_class_labels1})
class PrecisionAtRecallEvaluationTest(tf.test.TestCase): class PrecisionAtRecallEvaluationTest(tf.test.TestCase):
...@@ -807,31 +761,6 @@ class PrecisionAtRecallEvaluationTest(tf.test.TestCase): ...@@ -807,31 +761,6 @@ class PrecisionAtRecallEvaluationTest(tf.test.TestCase):
self.wp_eval.clear() self.wp_eval.clear()
self.assertFalse(self.wp_eval._image_ids) self.assertFalse(self.wp_eval._image_ids)
def test_value_error_on_duplicate_images(self):
# Add groundtruth
self.wp_eval = (
object_detection_evaluation.PrecisionAtRecallDetectionEvaluator(
self.categories, recall_lower_bound=0.0, recall_upper_bound=0.5))
image_key1 = 'img1'
groundtruth_boxes1 = np.array([[0, 0, 1, 1], [0, 0, 2, 2], [0, 0, 3, 3]],
dtype=float)
groundtruth_class_labels1 = np.array([1, 3, 1], dtype=int)
self.wp_eval.add_single_ground_truth_image_info(
image_key1, {
standard_fields.InputDataFields.groundtruth_boxes:
groundtruth_boxes1,
standard_fields.InputDataFields.groundtruth_classes:
groundtruth_class_labels1
})
with self.assertRaises(ValueError):
self.wp_eval.add_single_ground_truth_image_info(
image_key1, {
standard_fields.InputDataFields.groundtruth_boxes:
groundtruth_boxes1,
standard_fields.InputDataFields.groundtruth_classes:
groundtruth_class_labels1
})
class ObjectDetectionEvaluationTest(tf.test.TestCase): class ObjectDetectionEvaluationTest(tf.test.TestCase):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment