Python object_detection.data_decoders.tf_example_decoder.BackupHandler() Examples
The following are 5
code examples of object_detection.data_decoders.tf_example_decoder.BackupHandler().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
object_detection.data_decoders.tf_example_decoder
, or try the search function
.
Example #1
Source File: tf_example_decoder_test.py From ros_people_object_detection_tensorflow with Apache License 2.0 | 4 votes |
def testDecodeExampleWithBranchedBackupHandler(self): example1 = example_pb2.Example( features=feature_pb2.Features( feature={ 'image/object/class/text': self._BytesFeatureFromList( np.array(['cat', 'dog', 'guinea pig'])), 'image/object/class/label': self._Int64FeatureFromList(np.array([42, 10, 900])) })) example2 = example_pb2.Example( features=feature_pb2.Features( feature={ 'image/object/class/text': self._BytesFeatureFromList( np.array(['cat', 'dog', 'guinea pig'])), })) example3 = example_pb2.Example( features=feature_pb2.Features( feature={ 'image/object/class/label': self._Int64FeatureFromList(np.array([42, 10, 901])) })) # 'dog' -> 0, 'guinea pig' -> 1, 'cat' -> 2 table = lookup_ops.index_table_from_tensor( constant_op.constant(['dog', 'guinea pig', 'cat'])) keys_to_features = { 'image/object/class/text': parsing_ops.VarLenFeature(dtypes.string), 'image/object/class/label': parsing_ops.VarLenFeature(dtypes.int64), } backup_handler = tf_example_decoder.BackupHandler( handler=slim_example_decoder.Tensor('image/object/class/label'), backup=tf_example_decoder.LookupTensor('image/object/class/text', table)) items_to_handlers = { 'labels': backup_handler, } decoder = slim_example_decoder.TFExampleDecoder(keys_to_features, items_to_handlers) obtained_class_ids_each_example = [] with self.test_session() as sess: sess.run(lookup_ops.tables_initializer()) for example in [example1, example2, example3]: serialized_example = array_ops.reshape( example.SerializeToString(), shape=[]) obtained_class_ids_each_example.append( decoder.decode(serialized_example)[0].eval()) self.assertAllClose([42, 10, 900], obtained_class_ids_each_example[0]) self.assertAllClose([2, 0, 1], obtained_class_ids_each_example[1]) self.assertAllClose([42, 10, 901], obtained_class_ids_each_example[2])
Example #2
Source File: tf_example_decoder_test.py From Person-Detection-and-Tracking with MIT License | 4 votes |
def testDecodeExampleWithBranchedBackupHandler(self): example1 = example_pb2.Example( features=feature_pb2.Features( feature={ 'image/object/class/text': self._BytesFeatureFromList( np.array(['cat', 'dog', 'guinea pig'])), 'image/object/class/label': self._Int64FeatureFromList(np.array([42, 10, 900])) })) example2 = example_pb2.Example( features=feature_pb2.Features( feature={ 'image/object/class/text': self._BytesFeatureFromList( np.array(['cat', 'dog', 'guinea pig'])), })) example3 = example_pb2.Example( features=feature_pb2.Features( feature={ 'image/object/class/label': self._Int64FeatureFromList(np.array([42, 10, 901])) })) # 'dog' -> 0, 'guinea pig' -> 1, 'cat' -> 2 table = lookup_ops.index_table_from_tensor( constant_op.constant(['dog', 'guinea pig', 'cat'])) keys_to_features = { 'image/object/class/text': parsing_ops.VarLenFeature(dtypes.string), 'image/object/class/label': parsing_ops.VarLenFeature(dtypes.int64), } backup_handler = tf_example_decoder.BackupHandler( handler=slim_example_decoder.Tensor('image/object/class/label'), backup=tf_example_decoder.LookupTensor('image/object/class/text', table)) items_to_handlers = { 'labels': backup_handler, } decoder = slim_example_decoder.TFExampleDecoder(keys_to_features, items_to_handlers) obtained_class_ids_each_example = [] with self.test_session() as sess: sess.run(lookup_ops.tables_initializer()) for example in [example1, example2, example3]: serialized_example = array_ops.reshape( example.SerializeToString(), shape=[]) obtained_class_ids_each_example.append( decoder.decode(serialized_example)[0].eval()) self.assertAllClose([42, 10, 900], obtained_class_ids_each_example[0]) self.assertAllClose([2, 0, 1], obtained_class_ids_each_example[1]) self.assertAllClose([42, 10, 901], obtained_class_ids_each_example[2])
Example #3
Source File: tf_example_decoder_test.py From Gun-Detector with Apache License 2.0 | 4 votes |
def testDecodeExampleWithBranchedBackupHandler(self): example1 = example_pb2.Example( features=feature_pb2.Features( feature={ 'image/object/class/text': self._BytesFeatureFromList( np.array(['cat', 'dog', 'guinea pig'])), 'image/object/class/label': self._Int64FeatureFromList(np.array([42, 10, 900])) })) example2 = example_pb2.Example( features=feature_pb2.Features( feature={ 'image/object/class/text': self._BytesFeatureFromList( np.array(['cat', 'dog', 'guinea pig'])), })) example3 = example_pb2.Example( features=feature_pb2.Features( feature={ 'image/object/class/label': self._Int64FeatureFromList(np.array([42, 10, 901])) })) # 'dog' -> 0, 'guinea pig' -> 1, 'cat' -> 2 table = lookup_ops.index_table_from_tensor( constant_op.constant(['dog', 'guinea pig', 'cat'])) keys_to_features = { 'image/object/class/text': parsing_ops.VarLenFeature(dtypes.string), 'image/object/class/label': parsing_ops.VarLenFeature(dtypes.int64), } backup_handler = tf_example_decoder.BackupHandler( handler=slim_example_decoder.Tensor('image/object/class/label'), backup=tf_example_decoder.LookupTensor('image/object/class/text', table)) items_to_handlers = { 'labels': backup_handler, } decoder = slim_example_decoder.TFExampleDecoder(keys_to_features, items_to_handlers) obtained_class_ids_each_example = [] with self.test_session() as sess: sess.run(lookup_ops.tables_initializer()) for example in [example1, example2, example3]: serialized_example = array_ops.reshape( example.SerializeToString(), shape=[]) obtained_class_ids_each_example.append( decoder.decode(serialized_example)[0].eval()) self.assertAllClose([42, 10, 900], obtained_class_ids_each_example[0]) self.assertAllClose([2, 0, 1], obtained_class_ids_each_example[1]) self.assertAllClose([42, 10, 901], obtained_class_ids_each_example[2])
Example #4
Source File: tf_example_decoder_test.py From ros_tensorflow with Apache License 2.0 | 4 votes |
def testDecodeExampleWithBranchedBackupHandler(self): example1 = example_pb2.Example( features=feature_pb2.Features( feature={ 'image/object/class/text': self._BytesFeatureFromList( np.array(['cat', 'dog', 'guinea pig'])), 'image/object/class/label': self._Int64FeatureFromList(np.array([42, 10, 900])) })) example2 = example_pb2.Example( features=feature_pb2.Features( feature={ 'image/object/class/text': self._BytesFeatureFromList( np.array(['cat', 'dog', 'guinea pig'])), })) example3 = example_pb2.Example( features=feature_pb2.Features( feature={ 'image/object/class/label': self._Int64FeatureFromList(np.array([42, 10, 901])) })) # 'dog' -> 0, 'guinea pig' -> 1, 'cat' -> 2 table = lookup_ops.index_table_from_tensor( constant_op.constant(['dog', 'guinea pig', 'cat'])) keys_to_features = { 'image/object/class/text': parsing_ops.VarLenFeature(dtypes.string), 'image/object/class/label': parsing_ops.VarLenFeature(dtypes.int64), } backup_handler = tf_example_decoder.BackupHandler( handler=slim_example_decoder.Tensor('image/object/class/label'), backup=tf_example_decoder.LookupTensor('image/object/class/text', table)) items_to_handlers = { 'labels': backup_handler, } decoder = slim_example_decoder.TFExampleDecoder(keys_to_features, items_to_handlers) obtained_class_ids_each_example = [] with self.test_session() as sess: sess.run(lookup_ops.tables_initializer()) for example in [example1, example2, example3]: serialized_example = array_ops.reshape( example.SerializeToString(), shape=[]) obtained_class_ids_each_example.append( decoder.decode(serialized_example)[0].eval()) self.assertAllClose([42, 10, 900], obtained_class_ids_each_example[0]) self.assertAllClose([2, 0, 1], obtained_class_ids_each_example[1]) self.assertAllClose([42, 10, 901], obtained_class_ids_each_example[2])
Example #5
Source File: tf_example_decoder_test.py From BMW-TensorFlow-Training-GUI with Apache License 2.0 | 4 votes |
def testDecodeExampleWithBranchedBackupHandler(self): example1 = example_pb2.Example( features=feature_pb2.Features( feature={ 'image/object/class/text': self._BytesFeatureFromList( np.array(['cat', 'dog', 'guinea pig'])), 'image/object/class/label': self._Int64FeatureFromList(np.array([42, 10, 900])) })) example2 = example_pb2.Example( features=feature_pb2.Features( feature={ 'image/object/class/text': self._BytesFeatureFromList( np.array(['cat', 'dog', 'guinea pig'])), })) example3 = example_pb2.Example( features=feature_pb2.Features( feature={ 'image/object/class/label': self._Int64FeatureFromList(np.array([42, 10, 901])) })) # 'dog' -> 0, 'guinea pig' -> 1, 'cat' -> 2 table = lookup_ops.index_table_from_tensor( constant_op.constant(['dog', 'guinea pig', 'cat'])) keys_to_features = { 'image/object/class/text': parsing_ops.VarLenFeature(dtypes.string), 'image/object/class/label': parsing_ops.VarLenFeature(dtypes.int64), } backup_handler = tf_example_decoder.BackupHandler( handler=slim_example_decoder.Tensor('image/object/class/label'), backup=tf_example_decoder.LookupTensor('image/object/class/text', table)) items_to_handlers = { 'labels': backup_handler, } decoder = slim_example_decoder.TFExampleDecoder(keys_to_features, items_to_handlers) obtained_class_ids_each_example = [] with self.test_session() as sess: sess.run(lookup_ops.tables_initializer()) for example in [example1, example2, example3]: serialized_example = array_ops.reshape( example.SerializeToString(), shape=[]) obtained_class_ids_each_example.append( decoder.decode(serialized_example)[0].eval()) self.assertAllClose([42, 10, 900], obtained_class_ids_each_example[0]) self.assertAllClose([2, 0, 1], obtained_class_ids_each_example[1]) self.assertAllClose([42, 10, 901], obtained_class_ids_each_example[2])