Python object_detection.utils.ops.padded_one_hot_encoding() Examples
The following are 30
code examples of object_detection.utils.ops.padded_one_hot_encoding().
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.utils.ops
, or try the search function
.
Example #1
Source File: ops_test.py From HereIsWally with MIT License | 5 votes |
def test_correct_one_hot_tensor_with_no_pad(self): indices = tf.constant([1, 2, 3, 5]) one_hot_tensor = ops.padded_one_hot_encoding(indices, depth=6, left_pad=0) expected_tensor = np.array([[0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 1]], np.float32) with self.test_session() as sess: out_one_hot_tensor = sess.run(one_hot_tensor) self.assertAllClose(out_one_hot_tensor, expected_tensor, rtol=1e-10, atol=1e-10)
Example #2
Source File: ops_test.py From HereIsWally with MIT License | 5 votes |
def test_raise_value_error_on_float_pad(self): indices = tf.constant(1.0, shape=(2, 3)) with self.assertRaises(ValueError): ops.padded_one_hot_encoding(indices, depth=6, left_pad=0.1)
Example #3
Source File: ops_test.py From yolo_v2 with Apache License 2.0 | 5 votes |
def test_raise_value_error_on_float_pad(self): indices = tf.constant(1.0, shape=(2, 3)) with self.assertRaises(ValueError): ops.padded_one_hot_encoding(indices, depth=6, left_pad=0.1)
Example #4
Source File: ops_test.py From yolo_v2 with Apache License 2.0 | 5 votes |
def test_raise_value_error_on_float_depth(self): indices = tf.constant(1.0, shape=(2, 3)) with self.assertRaises(ValueError): ops.padded_one_hot_encoding(indices, depth=0.1, left_pad=2)
Example #5
Source File: ops_test.py From Traffic-Rule-Violation-Detection-System with MIT License | 5 votes |
def test_correct_one_hot_tensor_with_no_pad(self): indices = tf.constant([1, 2, 3, 5]) one_hot_tensor = ops.padded_one_hot_encoding(indices, depth=6, left_pad=0) expected_tensor = np.array([[0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 1]], np.float32) with self.test_session() as sess: out_one_hot_tensor = sess.run(one_hot_tensor) self.assertAllClose(out_one_hot_tensor, expected_tensor, rtol=1e-10, atol=1e-10)
Example #6
Source File: ops_test.py From Traffic-Rule-Violation-Detection-System with MIT License | 5 votes |
def test_correct_one_hot_tensor_with_pad_one(self): indices = tf.constant([1, 2, 3, 5]) one_hot_tensor = ops.padded_one_hot_encoding(indices, depth=6, left_pad=1) expected_tensor = np.array([[0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 1]], np.float32) with self.test_session() as sess: out_one_hot_tensor = sess.run(one_hot_tensor) self.assertAllClose(out_one_hot_tensor, expected_tensor, rtol=1e-10, atol=1e-10)
Example #7
Source File: ops_test.py From Traffic-Rule-Violation-Detection-System with MIT License | 5 votes |
def test_correct_one_hot_tensor_with_pad_three(self): indices = tf.constant([1, 2, 3, 5]) one_hot_tensor = ops.padded_one_hot_encoding(indices, depth=6, left_pad=3) expected_tensor = np.array([[0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1]], np.float32) with self.test_session() as sess: out_one_hot_tensor = sess.run(one_hot_tensor) self.assertAllClose(out_one_hot_tensor, expected_tensor, rtol=1e-10, atol=1e-10)
Example #8
Source File: ops_test.py From Traffic-Rule-Violation-Detection-System with MIT License | 5 votes |
def test_correct_padded_one_hot_tensor_with_empty_indices(self): depth = 6 pad = 2 indices = tf.constant([]) one_hot_tensor = ops.padded_one_hot_encoding( indices, depth=depth, left_pad=pad) expected_tensor = np.zeros((0, depth + pad)) with self.test_session() as sess: out_one_hot_tensor = sess.run(one_hot_tensor) self.assertAllClose(out_one_hot_tensor, expected_tensor, rtol=1e-10, atol=1e-10)
Example #9
Source File: ops_test.py From Traffic-Rule-Violation-Detection-System with MIT License | 5 votes |
def test_raise_value_error_on_rank_two_input(self): indices = tf.constant(1.0, shape=(2, 3)) with self.assertRaises(ValueError): ops.padded_one_hot_encoding(indices, depth=6, left_pad=2)
Example #10
Source File: ops_test.py From Traffic-Rule-Violation-Detection-System with MIT License | 5 votes |
def test_raise_value_error_on_negative_pad(self): indices = tf.constant(1.0, shape=(2, 3)) with self.assertRaises(ValueError): ops.padded_one_hot_encoding(indices, depth=6, left_pad=-1)
Example #11
Source File: ops_test.py From Traffic-Rule-Violation-Detection-System with MIT License | 5 votes |
def test_raise_value_error_on_float_pad(self): indices = tf.constant(1.0, shape=(2, 3)) with self.assertRaises(ValueError): ops.padded_one_hot_encoding(indices, depth=6, left_pad=0.1)
Example #12
Source File: ops_test.py From yolo_v2 with Apache License 2.0 | 5 votes |
def test_raise_value_error_on_negative_pad(self): indices = tf.constant(1.0, shape=(2, 3)) with self.assertRaises(ValueError): ops.padded_one_hot_encoding(indices, depth=6, left_pad=-1)
Example #13
Source File: ops_test.py From HereIsWally with MIT License | 5 votes |
def test_correct_padded_one_hot_tensor_with_empty_indices(self): depth = 6 pad = 2 indices = tf.constant([]) one_hot_tensor = ops.padded_one_hot_encoding( indices, depth=depth, left_pad=pad) expected_tensor = np.zeros((0, depth + pad)) with self.test_session() as sess: out_one_hot_tensor = sess.run(one_hot_tensor) self.assertAllClose(out_one_hot_tensor, expected_tensor, rtol=1e-10, atol=1e-10)
Example #14
Source File: ops_test.py From HereIsWally with MIT License | 5 votes |
def test_correct_one_hot_tensor_with_pad_three(self): indices = tf.constant([1, 2, 3, 5]) one_hot_tensor = ops.padded_one_hot_encoding(indices, depth=6, left_pad=3) expected_tensor = np.array([[0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1]], np.float32) with self.test_session() as sess: out_one_hot_tensor = sess.run(one_hot_tensor) self.assertAllClose(out_one_hot_tensor, expected_tensor, rtol=1e-10, atol=1e-10)
Example #15
Source File: ops_test.py From HereIsWally with MIT License | 5 votes |
def test_correct_one_hot_tensor_with_pad_one(self): indices = tf.constant([1, 2, 3, 5]) one_hot_tensor = ops.padded_one_hot_encoding(indices, depth=6, left_pad=1) expected_tensor = np.array([[0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 1]], np.float32) with self.test_session() as sess: out_one_hot_tensor = sess.run(one_hot_tensor) self.assertAllClose(out_one_hot_tensor, expected_tensor, rtol=1e-10, atol=1e-10)
Example #16
Source File: ops_test.py From HereIsWally with MIT License | 5 votes |
def test_raise_value_error_on_rank_two_input(self): indices = tf.constant(1.0, shape=(2, 3)) with self.assertRaises(ValueError): ops.padded_one_hot_encoding(indices, depth=6, left_pad=2)
Example #17
Source File: trainer.py From HereIsWally with MIT License | 5 votes |
def _get_inputs(input_queue, num_classes): """Dequeue batch and construct inputs to object detection model. Args: input_queue: BatchQueue object holding enqueued tensor_dicts. num_classes: Number of classes. Returns: images: a list of 3-D float tensor of images. locations_list: a list of tensors of shape [num_boxes, 4] containing the corners of the groundtruth boxes. classes_list: a list of padded one-hot tensors containing target classes. masks_list: a list of 3-D float tensors of shape [num_boxes, image_height, image_width] containing instance masks for objects if present in the input_queue. Else returns None. """ read_data_list = input_queue.dequeue() label_id_offset = 1 def extract_images_and_targets(read_data): image = read_data[fields.InputDataFields.image] location_gt = read_data[fields.InputDataFields.groundtruth_boxes] classes_gt = tf.cast(read_data[fields.InputDataFields.groundtruth_classes], tf.int32) classes_gt -= label_id_offset classes_gt = util_ops.padded_one_hot_encoding(indices=classes_gt, depth=num_classes, left_pad=0) masks_gt = read_data.get(fields.InputDataFields.groundtruth_instance_masks) return image, location_gt, classes_gt, masks_gt return zip(*map(extract_images_and_targets, read_data_list))
Example #18
Source File: ops_test.py From garbage-object-detection-tensorflow with MIT License | 5 votes |
def test_raise_value_error_on_float_depth(self): indices = tf.constant(1.0, shape=(2, 3)) with self.assertRaises(ValueError): ops.padded_one_hot_encoding(indices, depth=0.1, left_pad=2)
Example #19
Source File: ops_test.py From garbage-object-detection-tensorflow with MIT License | 5 votes |
def test_raise_value_error_on_float_pad(self): indices = tf.constant(1.0, shape=(2, 3)) with self.assertRaises(ValueError): ops.padded_one_hot_encoding(indices, depth=6, left_pad=0.1)
Example #20
Source File: ops_test.py From garbage-object-detection-tensorflow with MIT License | 5 votes |
def test_raise_value_error_on_negative_pad(self): indices = tf.constant(1.0, shape=(2, 3)) with self.assertRaises(ValueError): ops.padded_one_hot_encoding(indices, depth=6, left_pad=-1)
Example #21
Source File: ops_test.py From garbage-object-detection-tensorflow with MIT License | 5 votes |
def test_raise_value_error_on_rank_two_input(self): indices = tf.constant(1.0, shape=(2, 3)) with self.assertRaises(ValueError): ops.padded_one_hot_encoding(indices, depth=6, left_pad=2)
Example #22
Source File: ops_test.py From garbage-object-detection-tensorflow with MIT License | 5 votes |
def test_correct_padded_one_hot_tensor_with_empty_indices(self): depth = 6 pad = 2 indices = tf.constant([]) one_hot_tensor = ops.padded_one_hot_encoding( indices, depth=depth, left_pad=pad) expected_tensor = np.zeros((0, depth + pad)) with self.test_session() as sess: out_one_hot_tensor = sess.run(one_hot_tensor) self.assertAllClose(out_one_hot_tensor, expected_tensor, rtol=1e-10, atol=1e-10)
Example #23
Source File: ops_test.py From garbage-object-detection-tensorflow with MIT License | 5 votes |
def test_correct_one_hot_tensor_with_pad_three(self): indices = tf.constant([1, 2, 3, 5]) one_hot_tensor = ops.padded_one_hot_encoding(indices, depth=6, left_pad=3) expected_tensor = np.array([[0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1]], np.float32) with self.test_session() as sess: out_one_hot_tensor = sess.run(one_hot_tensor) self.assertAllClose(out_one_hot_tensor, expected_tensor, rtol=1e-10, atol=1e-10)
Example #24
Source File: ops_test.py From garbage-object-detection-tensorflow with MIT License | 5 votes |
def test_correct_one_hot_tensor_with_pad_one(self): indices = tf.constant([1, 2, 3, 5]) one_hot_tensor = ops.padded_one_hot_encoding(indices, depth=6, left_pad=1) expected_tensor = np.array([[0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 1]], np.float32) with self.test_session() as sess: out_one_hot_tensor = sess.run(one_hot_tensor) self.assertAllClose(out_one_hot_tensor, expected_tensor, rtol=1e-10, atol=1e-10)
Example #25
Source File: ops_test.py From garbage-object-detection-tensorflow with MIT License | 5 votes |
def test_correct_one_hot_tensor_with_no_pad(self): indices = tf.constant([1, 2, 3, 5]) one_hot_tensor = ops.padded_one_hot_encoding(indices, depth=6, left_pad=0) expected_tensor = np.array([[0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 1]], np.float32) with self.test_session() as sess: out_one_hot_tensor = sess.run(one_hot_tensor) self.assertAllClose(out_one_hot_tensor, expected_tensor, rtol=1e-10, atol=1e-10)
Example #26
Source File: trainer.py From garbage-object-detection-tensorflow with MIT License | 5 votes |
def _get_inputs(input_queue, num_classes): """Dequeue batch and construct inputs to object detection model. Args: input_queue: BatchQueue object holding enqueued tensor_dicts. num_classes: Number of classes. Returns: images: a list of 3-D float tensor of images. locations_list: a list of tensors of shape [num_boxes, 4] containing the corners of the groundtruth boxes. classes_list: a list of padded one-hot tensors containing target classes. masks_list: a list of 3-D float tensors of shape [num_boxes, image_height, image_width] containing instance masks for objects if present in the input_queue. Else returns None. """ read_data_list = input_queue.dequeue() label_id_offset = 1 def extract_images_and_targets(read_data): image = read_data[fields.InputDataFields.image] location_gt = read_data[fields.InputDataFields.groundtruth_boxes] classes_gt = tf.cast(read_data[fields.InputDataFields.groundtruth_classes], tf.int32) classes_gt -= label_id_offset classes_gt = util_ops.padded_one_hot_encoding(indices=classes_gt, depth=num_classes, left_pad=0) masks_gt = read_data.get(fields.InputDataFields.groundtruth_instance_masks) return image, location_gt, classes_gt, masks_gt return zip(*map(extract_images_and_targets, read_data_list))
Example #27
Source File: ops_test.py From Person-Detection-and-Tracking with MIT License | 5 votes |
def test_raise_value_error_on_float_depth(self): indices = tf.constant(1.0, shape=(2, 3)) with self.assertRaises(ValueError): ops.padded_one_hot_encoding(indices, depth=0.1, left_pad=2)
Example #28
Source File: ops_test.py From Person-Detection-and-Tracking with MIT License | 5 votes |
def test_raise_value_error_on_float_pad(self): indices = tf.constant(1.0, shape=(2, 3)) with self.assertRaises(ValueError): ops.padded_one_hot_encoding(indices, depth=6, left_pad=0.1)
Example #29
Source File: trainer.py From DOTA_models with Apache License 2.0 | 5 votes |
def _get_inputs(input_queue, num_classes): """Dequeue batch and construct inputs to object detection model. Args: input_queue: BatchQueue object holding enqueued tensor_dicts. num_classes: Number of classes. Returns: images: a list of 3-D float tensor of images. locations_list: a list of tensors of shape [num_boxes, 4] containing the corners of the groundtruth boxes. classes_list: a list of padded one-hot tensors containing target classes. masks_list: a list of 3-D float tensors of shape [num_boxes, image_height, image_width] containing instance masks for objects if present in the input_queue. Else returns None. """ read_data_list = input_queue.dequeue() label_id_offset = 1 def extract_images_and_targets(read_data): image = read_data[fields.InputDataFields.image] location_gt = read_data[fields.InputDataFields.groundtruth_boxes] classes_gt = tf.cast(read_data[fields.InputDataFields.groundtruth_classes], tf.int32) classes_gt -= label_id_offset classes_gt = util_ops.padded_one_hot_encoding(indices=classes_gt, depth=num_classes, left_pad=0) masks_gt = read_data.get(fields.InputDataFields.groundtruth_instance_masks) return image, location_gt, classes_gt, masks_gt return zip(*map(extract_images_and_targets, read_data_list))
Example #30
Source File: ops_test.py From Person-Detection-and-Tracking with MIT License | 5 votes |
def test_return_none_on_zero_depth(self): indices = tf.constant([1, 2, 3, 4, 5]) one_hot_tensor = ops.padded_one_hot_encoding(indices, depth=0, left_pad=2) self.assertEqual(one_hot_tensor, None)