Commit b658b16d authored by Vivek Rathod's avatar Vivek Rathod Committed by TF Object Detection Team
Browse files

Use BackupHandler from tf_slim instead of OD API's clone.

PiperOrigin-RevId: 323916181
parent bda18166
...@@ -124,40 +124,6 @@ class _ClassTensorHandler(slim_example_decoder.Tensor): ...@@ -124,40 +124,6 @@ class _ClassTensorHandler(slim_example_decoder.Tensor):
self._display_name_to_id_table.lookup(unmapped_tensor)) self._display_name_to_id_table.lookup(unmapped_tensor))
class _BackupHandler(slim_example_decoder.ItemHandler):
"""An ItemHandler that tries two ItemHandlers in order."""
def __init__(self, handler, backup):
"""Initializes the BackupHandler handler.
If the first Handler's tensors_to_item returns a Tensor with no elements,
the second Handler is used.
Args:
handler: The primary ItemHandler.
backup: The backup ItemHandler.
Raises:
ValueError: if either is not an ItemHandler.
"""
if not isinstance(handler, slim_example_decoder.ItemHandler):
raise ValueError('Primary handler is of type %s instead of ItemHandler' %
type(handler))
if not isinstance(backup, slim_example_decoder.ItemHandler):
raise ValueError(
'Backup handler is of type %s instead of ItemHandler' % type(backup))
self._handler = handler
self._backup = backup
super(_BackupHandler, self).__init__(handler.keys + backup.keys)
def tensors_to_item(self, keys_to_tensors):
item = self._handler.tensors_to_item(keys_to_tensors)
return tf.cond(
pred=tf.equal(tf.reduce_prod(tf.shape(item)), 0),
true_fn=lambda: self._backup.tensors_to_item(keys_to_tensors),
false_fn=lambda: item)
class TfExampleDecoder(data_decoder.DataDecoder): class TfExampleDecoder(data_decoder.DataDecoder):
"""Tensorflow Example proto decoder.""" """Tensorflow Example proto decoder."""
...@@ -405,12 +371,12 @@ class TfExampleDecoder(data_decoder.DataDecoder): ...@@ -405,12 +371,12 @@ class TfExampleDecoder(data_decoder.DataDecoder):
if label_map_proto_file: if label_map_proto_file:
# If the label_map_proto is provided, try to use it in conjunction with # If the label_map_proto is provided, try to use it in conjunction with
# the class text, and fall back to a materialized ID. # the class text, and fall back to a materialized ID.
label_handler = _BackupHandler( label_handler = slim_example_decoder.BackupHandler(
_ClassTensorHandler( _ClassTensorHandler(
'image/object/class/text', label_map_proto_file, 'image/object/class/text', label_map_proto_file,
default_value=''), default_value=''),
slim_example_decoder.Tensor('image/object/class/label')) slim_example_decoder.Tensor('image/object/class/label'))
image_label_handler = _BackupHandler( image_label_handler = slim_example_decoder.BackupHandler(
_ClassTensorHandler( _ClassTensorHandler(
fields.TfExampleFields.image_class_text, fields.TfExampleFields.image_class_text,
label_map_proto_file, label_map_proto_file,
......
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