Python object_detection.utils.ops.merge_boxes_with_multiple_labels() Examples
The following are 30
code examples of object_detection.utils.ops.merge_boxes_with_multiple_labels().
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 Gun-Detector with Apache License 2.0 | 6 votes |
def testMergeBoxesWithMultipleLabels(self): boxes = tf.constant( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75], [0.25, 0.25, 0.75, 0.75]], dtype=tf.float32) class_indices = tf.constant([0, 4, 2], dtype=tf.int32) num_classes = 5 merged_boxes, merged_classes, merged_box_indices = ( ops.merge_boxes_with_multiple_labels(boxes, class_indices, num_classes)) expected_merged_boxes = np.array( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75]], dtype=np.float32) expected_merged_classes = np.array( [[1, 0, 1, 0, 0], [0, 0, 0, 0, 1]], dtype=np.int32) expected_merged_box_indices = np.array([0, 1], dtype=np.int32) with self.test_session() as sess: np_merged_boxes, np_merged_classes, np_merged_box_indices = sess.run( [merged_boxes, merged_classes, merged_box_indices]) if np_merged_classes[0, 0] != 1: expected_merged_boxes = expected_merged_boxes[::-1, :] expected_merged_classes = expected_merged_classes[::-1, :] expected_merged_box_indices = expected_merged_box_indices[::-1, :] self.assertAllClose(np_merged_boxes, expected_merged_boxes) self.assertAllClose(np_merged_classes, expected_merged_classes) self.assertAllClose(np_merged_box_indices, expected_merged_box_indices)
Example #2
Source File: ops_test.py From object_detection_with_tensorflow with MIT License | 6 votes |
def testMergeBoxesWithMultipleLabels(self): boxes = tf.constant( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75], [0.25, 0.25, 0.75, 0.75]], dtype=tf.float32) class_indices = tf.constant([0, 4, 2], dtype=tf.int32) num_classes = 5 merged_boxes, merged_classes, merged_box_indices = ( ops.merge_boxes_with_multiple_labels(boxes, class_indices, num_classes)) expected_merged_boxes = np.array( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75]], dtype=np.float32) expected_merged_classes = np.array( [[1, 0, 1, 0, 0], [0, 0, 0, 0, 1]], dtype=np.int32) expected_merged_box_indices = np.array([0, 1], dtype=np.int32) with self.test_session() as sess: np_merged_boxes, np_merged_classes, np_merged_box_indices = sess.run( [merged_boxes, merged_classes, merged_box_indices]) if np_merged_classes[0, 0] != 1: expected_merged_boxes = expected_merged_boxes[::-1, :] expected_merged_classes = expected_merged_classes[::-1, :] expected_merged_box_indices = expected_merged_box_indices[::-1, :] self.assertAllClose(np_merged_boxes, expected_merged_boxes) self.assertAllClose(np_merged_classes, expected_merged_classes) self.assertAllClose(np_merged_box_indices, expected_merged_box_indices)
Example #3
Source File: ops_test.py From object_detection_with_tensorflow with MIT License | 6 votes |
def testMergeBoxesWithMultipleLabels(self): boxes = tf.constant( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75], [0.25, 0.25, 0.75, 0.75]], dtype=tf.float32) class_indices = tf.constant([0, 4, 2], dtype=tf.int32) num_classes = 5 merged_boxes, merged_classes, merged_box_indices = ( ops.merge_boxes_with_multiple_labels(boxes, class_indices, num_classes)) expected_merged_boxes = np.array( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75]], dtype=np.float32) expected_merged_classes = np.array( [[1, 0, 1, 0, 0], [0, 0, 0, 0, 1]], dtype=np.int32) expected_merged_box_indices = np.array([0, 1], dtype=np.int32) with self.test_session() as sess: np_merged_boxes, np_merged_classes, np_merged_box_indices = sess.run( [merged_boxes, merged_classes, merged_box_indices]) if np_merged_classes[0, 0] != 1: expected_merged_boxes = expected_merged_boxes[::-1, :] expected_merged_classes = expected_merged_classes[::-1, :] expected_merged_box_indices = expected_merged_box_indices[::-1, :] self.assertAllClose(np_merged_boxes, expected_merged_boxes) self.assertAllClose(np_merged_classes, expected_merged_classes) self.assertAllClose(np_merged_box_indices, expected_merged_box_indices)
Example #4
Source File: ops_test.py From monopsr with MIT License | 6 votes |
def testMergeBoxesWithMultipleLabels(self): boxes = tf.constant( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75], [0.25, 0.25, 0.75, 0.75]], dtype=tf.float32) class_indices = tf.constant([0, 4, 2], dtype=tf.int32) num_classes = 5 merged_boxes, merged_classes, merged_box_indices = ( ops.merge_boxes_with_multiple_labels(boxes, class_indices, num_classes)) expected_merged_boxes = np.array( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75]], dtype=np.float32) expected_merged_classes = np.array( [[1, 0, 1, 0, 0], [0, 0, 0, 0, 1]], dtype=np.int32) expected_merged_box_indices = np.array([0, 1], dtype=np.int32) with self.test_session() as sess: np_merged_boxes, np_merged_classes, np_merged_box_indices = sess.run( [merged_boxes, merged_classes, merged_box_indices]) if np_merged_classes[0, 0] != 1: expected_merged_boxes = expected_merged_boxes[::-1, :] expected_merged_classes = expected_merged_classes[::-1, :] expected_merged_box_indices = expected_merged_box_indices[::-1, :] self.assertAllClose(np_merged_boxes, expected_merged_boxes) self.assertAllClose(np_merged_classes, expected_merged_classes) self.assertAllClose(np_merged_box_indices, expected_merged_box_indices)
Example #5
Source File: ops_test.py From Elphas with Apache License 2.0 | 6 votes |
def testMergeBoxesWithMultipleLabels(self): boxes = tf.constant( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75], [0.25, 0.25, 0.75, 0.75]], dtype=tf.float32) class_indices = tf.constant([0, 4, 2], dtype=tf.int32) num_classes = 5 merged_boxes, merged_classes, merged_box_indices = ( ops.merge_boxes_with_multiple_labels(boxes, class_indices, num_classes)) expected_merged_boxes = np.array( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75]], dtype=np.float32) expected_merged_classes = np.array( [[1, 0, 1, 0, 0], [0, 0, 0, 0, 1]], dtype=np.int32) expected_merged_box_indices = np.array([0, 1], dtype=np.int32) with self.test_session() as sess: np_merged_boxes, np_merged_classes, np_merged_box_indices = sess.run( [merged_boxes, merged_classes, merged_box_indices]) if np_merged_classes[0, 0] != 1: expected_merged_boxes = expected_merged_boxes[::-1, :] expected_merged_classes = expected_merged_classes[::-1, :] expected_merged_box_indices = expected_merged_box_indices[::-1, :] self.assertAllClose(np_merged_boxes, expected_merged_boxes) self.assertAllClose(np_merged_classes, expected_merged_classes) self.assertAllClose(np_merged_box_indices, expected_merged_box_indices)
Example #6
Source File: ops_test.py From AniSeg with Apache License 2.0 | 6 votes |
def testMergeBoxesWithMultipleLabels(self): boxes = tf.constant( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75], [0.25, 0.25, 0.75, 0.75]], dtype=tf.float32) class_indices = tf.constant([0, 4, 2], dtype=tf.int32) num_classes = 5 merged_boxes, merged_classes, merged_box_indices = ( ops.merge_boxes_with_multiple_labels(boxes, class_indices, num_classes)) expected_merged_boxes = np.array( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75]], dtype=np.float32) expected_merged_classes = np.array( [[1, 0, 1, 0, 0], [0, 0, 0, 0, 1]], dtype=np.int32) expected_merged_box_indices = np.array([0, 1], dtype=np.int32) with self.test_session() as sess: np_merged_boxes, np_merged_classes, np_merged_box_indices = sess.run( [merged_boxes, merged_classes, merged_box_indices]) if np_merged_classes[0, 0] != 1: expected_merged_boxes = expected_merged_boxes[::-1, :] expected_merged_classes = expected_merged_classes[::-1, :] expected_merged_box_indices = expected_merged_box_indices[::-1, :] self.assertAllClose(np_merged_boxes, expected_merged_boxes) self.assertAllClose(np_merged_classes, expected_merged_classes) self.assertAllClose(np_merged_box_indices, expected_merged_box_indices)
Example #7
Source File: ops_test.py From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 | 6 votes |
def testMergeBoxesWithEmptyInputs(self): boxes = tf.zeros([0, 4], dtype=tf.float32) class_indices = tf.constant([], dtype=tf.int32) class_confidences = tf.constant([], dtype=tf.float32) num_classes = 5 merged_boxes, merged_classes, merged_confidences, merged_box_indices = ( ops.merge_boxes_with_multiple_labels( boxes, class_indices, class_confidences, num_classes)) with self.test_session() as sess: (np_merged_boxes, np_merged_classes, np_merged_confidences, np_merged_box_indices) = sess.run( [merged_boxes, merged_classes, merged_confidences, merged_box_indices]) self.assertAllEqual(np_merged_boxes.shape, [0, 4]) self.assertAllEqual(np_merged_classes.shape, [0, 5]) self.assertAllEqual(np_merged_confidences.shape, [0, 5]) self.assertAllEqual(np_merged_box_indices.shape, [0])
Example #8
Source File: ops_test.py From MAX-Object-Detector with Apache License 2.0 | 6 votes |
def testMergeBoxesWithEmptyInputs(self): boxes = tf.zeros([0, 4], dtype=tf.float32) class_indices = tf.constant([], dtype=tf.int32) class_confidences = tf.constant([], dtype=tf.float32) num_classes = 5 merged_boxes, merged_classes, merged_confidences, merged_box_indices = ( ops.merge_boxes_with_multiple_labels( boxes, class_indices, class_confidences, num_classes)) with self.test_session() as sess: (np_merged_boxes, np_merged_classes, np_merged_confidences, np_merged_box_indices) = sess.run( [merged_boxes, merged_classes, merged_confidences, merged_box_indices]) self.assertAllEqual(np_merged_boxes.shape, [0, 4]) self.assertAllEqual(np_merged_classes.shape, [0, 5]) self.assertAllEqual(np_merged_confidences.shape, [0, 5]) self.assertAllEqual(np_merged_box_indices.shape, [0])
Example #9
Source File: ops_test.py From BMW-TensorFlow-Training-GUI with Apache License 2.0 | 6 votes |
def testMergeBoxesWithMultipleLabels(self): boxes = tf.constant( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75], [0.25, 0.25, 0.75, 0.75]], dtype=tf.float32) class_indices = tf.constant([0, 4, 2], dtype=tf.int32) num_classes = 5 merged_boxes, merged_classes, merged_box_indices = ( ops.merge_boxes_with_multiple_labels(boxes, class_indices, num_classes)) expected_merged_boxes = np.array( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75]], dtype=np.float32) expected_merged_classes = np.array( [[1, 0, 1, 0, 0], [0, 0, 0, 0, 1]], dtype=np.int32) expected_merged_box_indices = np.array([0, 1], dtype=np.int32) with self.test_session() as sess: np_merged_boxes, np_merged_classes, np_merged_box_indices = sess.run( [merged_boxes, merged_classes, merged_box_indices]) if np_merged_classes[0, 0] != 1: expected_merged_boxes = expected_merged_boxes[::-1, :] expected_merged_classes = expected_merged_classes[::-1, :] expected_merged_box_indices = expected_merged_box_indices[::-1, :] self.assertAllClose(np_merged_boxes, expected_merged_boxes) self.assertAllClose(np_merged_classes, expected_merged_classes) self.assertAllClose(np_merged_box_indices, expected_merged_box_indices)
Example #10
Source File: ops_test.py From open-solution-googleai-object-detection with MIT License | 6 votes |
def testMergeBoxesWithMultipleLabels(self): boxes = tf.constant( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75], [0.25, 0.25, 0.75, 0.75]], dtype=tf.float32) class_indices = tf.constant([0, 4, 2], dtype=tf.int32) num_classes = 5 merged_boxes, merged_classes, merged_box_indices = ( ops.merge_boxes_with_multiple_labels(boxes, class_indices, num_classes)) expected_merged_boxes = np.array( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75]], dtype=np.float32) expected_merged_classes = np.array( [[1, 0, 1, 0, 0], [0, 0, 0, 0, 1]], dtype=np.int32) expected_merged_box_indices = np.array([0, 1], dtype=np.int32) with self.test_session() as sess: np_merged_boxes, np_merged_classes, np_merged_box_indices = sess.run( [merged_boxes, merged_classes, merged_box_indices]) if np_merged_classes[0, 0] != 1: expected_merged_boxes = expected_merged_boxes[::-1, :] expected_merged_classes = expected_merged_classes[::-1, :] expected_merged_box_indices = expected_merged_box_indices[::-1, :] self.assertAllClose(np_merged_boxes, expected_merged_boxes) self.assertAllClose(np_merged_classes, expected_merged_classes) self.assertAllClose(np_merged_box_indices, expected_merged_box_indices)
Example #11
Source File: ops_test.py From ros_tensorflow with Apache License 2.0 | 6 votes |
def testMergeBoxesWithMultipleLabels(self): boxes = tf.constant( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75], [0.25, 0.25, 0.75, 0.75]], dtype=tf.float32) class_indices = tf.constant([0, 4, 2], dtype=tf.int32) num_classes = 5 merged_boxes, merged_classes, merged_box_indices = ( ops.merge_boxes_with_multiple_labels(boxes, class_indices, num_classes)) expected_merged_boxes = np.array( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75]], dtype=np.float32) expected_merged_classes = np.array( [[1, 0, 1, 0, 0], [0, 0, 0, 0, 1]], dtype=np.int32) expected_merged_box_indices = np.array([0, 1], dtype=np.int32) with self.test_session() as sess: np_merged_boxes, np_merged_classes, np_merged_box_indices = sess.run( [merged_boxes, merged_classes, merged_box_indices]) if np_merged_classes[0, 0] != 1: expected_merged_boxes = expected_merged_boxes[::-1, :] expected_merged_classes = expected_merged_classes[::-1, :] expected_merged_box_indices = expected_merged_box_indices[::-1, :] self.assertAllClose(np_merged_boxes, expected_merged_boxes) self.assertAllClose(np_merged_classes, expected_merged_classes) self.assertAllClose(np_merged_box_indices, expected_merged_box_indices)
Example #12
Source File: ops_test.py From Traffic-Rule-Violation-Detection-System with MIT License | 6 votes |
def testMergeBoxesWithMultipleLabels(self): boxes = tf.constant( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75], [0.25, 0.25, 0.75, 0.75]], dtype=tf.float32) class_indices = tf.constant([0, 4, 2], dtype=tf.int32) num_classes = 5 merged_boxes, merged_classes, merged_box_indices = ( ops.merge_boxes_with_multiple_labels(boxes, class_indices, num_classes)) expected_merged_boxes = np.array( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75]], dtype=np.float32) expected_merged_classes = np.array( [[1, 0, 1, 0, 0], [0, 0, 0, 0, 1]], dtype=np.int32) expected_merged_box_indices = np.array([0, 1], dtype=np.int32) with self.test_session() as sess: np_merged_boxes, np_merged_classes, np_merged_box_indices = sess.run( [merged_boxes, merged_classes, merged_box_indices]) if np_merged_classes[0, 0] != 1: expected_merged_boxes = expected_merged_boxes[::-1, :] expected_merged_classes = expected_merged_classes[::-1, :] expected_merged_box_indices = expected_merged_box_indices[::-1, :] self.assertAllClose(np_merged_boxes, expected_merged_boxes) self.assertAllClose(np_merged_classes, expected_merged_classes) self.assertAllClose(np_merged_box_indices, expected_merged_box_indices)
Example #13
Source File: ops_test.py From multilabel-image-classification-tensorflow with MIT License | 6 votes |
def testMergeBoxesWithEmptyInputs(self): boxes = tf.zeros([0, 4], dtype=tf.float32) class_indices = tf.constant([], dtype=tf.int32) class_confidences = tf.constant([], dtype=tf.float32) num_classes = 5 merged_boxes, merged_classes, merged_confidences, merged_box_indices = ( ops.merge_boxes_with_multiple_labels( boxes, class_indices, class_confidences, num_classes)) with self.test_session() as sess: (np_merged_boxes, np_merged_classes, np_merged_confidences, np_merged_box_indices) = sess.run( [merged_boxes, merged_classes, merged_confidences, merged_box_indices]) self.assertAllEqual(np_merged_boxes.shape, [0, 4]) self.assertAllEqual(np_merged_classes.shape, [0, 5]) self.assertAllEqual(np_merged_confidences.shape, [0, 5]) self.assertAllEqual(np_merged_box_indices.shape, [0])
Example #14
Source File: ops_test.py From yolo_v2 with Apache License 2.0 | 6 votes |
def testMergeBoxesWithMultipleLabels(self): boxes = tf.constant( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75], [0.25, 0.25, 0.75, 0.75]], dtype=tf.float32) class_indices = tf.constant([0, 4, 2], dtype=tf.int32) num_classes = 5 merged_boxes, merged_classes, merged_box_indices = ( ops.merge_boxes_with_multiple_labels(boxes, class_indices, num_classes)) expected_merged_boxes = np.array( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75]], dtype=np.float32) expected_merged_classes = np.array( [[1, 0, 1, 0, 0], [0, 0, 0, 0, 1]], dtype=np.int32) expected_merged_box_indices = np.array([0, 1], dtype=np.int32) with self.test_session() as sess: np_merged_boxes, np_merged_classes, np_merged_box_indices = sess.run( [merged_boxes, merged_classes, merged_box_indices]) if np_merged_classes[0, 0] != 1: expected_merged_boxes = expected_merged_boxes[::-1, :] expected_merged_classes = expected_merged_classes[::-1, :] expected_merged_box_indices = expected_merged_box_indices[::-1, :] self.assertAllClose(np_merged_boxes, expected_merged_boxes) self.assertAllClose(np_merged_classes, expected_merged_classes) self.assertAllClose(np_merged_box_indices, expected_merged_box_indices)
Example #15
Source File: ops_test.py From vehicle_counting_tensorflow with MIT License | 6 votes |
def testMergeBoxesWithEmptyInputs(self): boxes = tf.zeros([0, 4], dtype=tf.float32) class_indices = tf.constant([], dtype=tf.int32) class_confidences = tf.constant([], dtype=tf.float32) num_classes = 5 merged_boxes, merged_classes, merged_confidences, merged_box_indices = ( ops.merge_boxes_with_multiple_labels( boxes, class_indices, class_confidences, num_classes)) with self.test_session() as sess: (np_merged_boxes, np_merged_classes, np_merged_confidences, np_merged_box_indices) = sess.run( [merged_boxes, merged_classes, merged_confidences, merged_box_indices]) self.assertAllEqual(np_merged_boxes.shape, [0, 4]) self.assertAllEqual(np_merged_classes.shape, [0, 5]) self.assertAllEqual(np_merged_confidences.shape, [0, 5]) self.assertAllEqual(np_merged_box_indices.shape, [0])
Example #16
Source File: ops_test.py From ros_people_object_detection_tensorflow with Apache License 2.0 | 6 votes |
def testMergeBoxesWithMultipleLabels(self): boxes = tf.constant( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75], [0.25, 0.25, 0.75, 0.75]], dtype=tf.float32) class_indices = tf.constant([0, 4, 2], dtype=tf.int32) num_classes = 5 merged_boxes, merged_classes, merged_box_indices = ( ops.merge_boxes_with_multiple_labels(boxes, class_indices, num_classes)) expected_merged_boxes = np.array( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75]], dtype=np.float32) expected_merged_classes = np.array( [[1, 0, 1, 0, 0], [0, 0, 0, 0, 1]], dtype=np.int32) expected_merged_box_indices = np.array([0, 1], dtype=np.int32) with self.test_session() as sess: np_merged_boxes, np_merged_classes, np_merged_box_indices = sess.run( [merged_boxes, merged_classes, merged_box_indices]) if np_merged_classes[0, 0] != 1: expected_merged_boxes = expected_merged_boxes[::-1, :] expected_merged_classes = expected_merged_classes[::-1, :] expected_merged_box_indices = expected_merged_box_indices[::-1, :] self.assertAllClose(np_merged_boxes, expected_merged_boxes) self.assertAllClose(np_merged_classes, expected_merged_classes) self.assertAllClose(np_merged_box_indices, expected_merged_box_indices)
Example #17
Source File: ops_test.py From models with Apache License 2.0 | 6 votes |
def testMergeBoxesWithEmptyInputs(self): def graph_fn(): boxes = tf.zeros([0, 4], dtype=tf.float32) class_indices = tf.constant([], dtype=tf.int32) class_confidences = tf.constant([], dtype=tf.float32) num_classes = 5 merged_boxes, merged_classes, merged_confidences, merged_box_indices = ( ops.merge_boxes_with_multiple_labels( boxes, class_indices, class_confidences, num_classes)) return (merged_boxes, merged_classes, merged_confidences, merged_box_indices) # Running on CPU only as tf.unique is not supported on TPU. (np_merged_boxes, np_merged_classes, np_merged_confidences, np_merged_box_indices) = self.execute_cpu(graph_fn, []) self.assertAllEqual(np_merged_boxes.shape, [0, 4]) self.assertAllEqual(np_merged_classes.shape, [0, 5]) self.assertAllEqual(np_merged_confidences.shape, [0, 5]) self.assertAllEqual(np_merged_box_indices.shape, [0])
Example #18
Source File: ops_test.py From g-tensorflow-models with Apache License 2.0 | 6 votes |
def testMergeBoxesWithEmptyInputs(self): boxes = tf.zeros([0, 4], dtype=tf.float32) class_indices = tf.constant([], dtype=tf.int32) class_confidences = tf.constant([], dtype=tf.float32) num_classes = 5 merged_boxes, merged_classes, merged_confidences, merged_box_indices = ( ops.merge_boxes_with_multiple_labels( boxes, class_indices, class_confidences, num_classes)) with self.test_session() as sess: (np_merged_boxes, np_merged_classes, np_merged_confidences, np_merged_box_indices) = sess.run( [merged_boxes, merged_classes, merged_confidences, merged_box_indices]) self.assertAllEqual(np_merged_boxes.shape, [0, 4]) self.assertAllEqual(np_merged_classes.shape, [0, 5]) self.assertAllEqual(np_merged_confidences.shape, [0, 5]) self.assertAllEqual(np_merged_box_indices.shape, [0])
Example #19
Source File: ops_test.py From Person-Detection-and-Tracking with MIT License | 6 votes |
def testMergeBoxesWithMultipleLabels(self): boxes = tf.constant( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75], [0.25, 0.25, 0.75, 0.75]], dtype=tf.float32) class_indices = tf.constant([0, 4, 2], dtype=tf.int32) num_classes = 5 merged_boxes, merged_classes, merged_box_indices = ( ops.merge_boxes_with_multiple_labels(boxes, class_indices, num_classes)) expected_merged_boxes = np.array( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75]], dtype=np.float32) expected_merged_classes = np.array( [[1, 0, 1, 0, 0], [0, 0, 0, 0, 1]], dtype=np.int32) expected_merged_box_indices = np.array([0, 1], dtype=np.int32) with self.test_session() as sess: np_merged_boxes, np_merged_classes, np_merged_box_indices = sess.run( [merged_boxes, merged_classes, merged_box_indices]) if np_merged_classes[0, 0] != 1: expected_merged_boxes = expected_merged_boxes[::-1, :] expected_merged_classes = expected_merged_classes[::-1, :] expected_merged_box_indices = expected_merged_box_indices[::-1, :] self.assertAllClose(np_merged_boxes, expected_merged_boxes) self.assertAllClose(np_merged_classes, expected_merged_classes) self.assertAllClose(np_merged_box_indices, expected_merged_box_indices)
Example #20
Source File: ops_test.py From MAX-Object-Detector with Apache License 2.0 | 5 votes |
def testMergeBoxesWithMultipleLabelsCornerCase(self): boxes = tf.constant( [[0, 0, 1, 1], [0, 1, 1, 1], [1, 0, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 0, 1, 1], [0, 1, 1, 1], [0, 0, 1, 1]], dtype=tf.float32) class_indices = tf.constant([0, 1, 2, 3, 2, 1, 0, 3], dtype=tf.int32) class_confidences = tf.constant([0.1, 0.9, 0.2, 0.8, 0.3, 0.7, 0.4, 0.6], dtype=tf.float32) num_classes = 4 merged_boxes, merged_classes, merged_confidences, merged_box_indices = ( ops.merge_boxes_with_multiple_labels( boxes, class_indices, class_confidences, num_classes)) expected_merged_boxes = np.array( [[0, 0, 1, 1], [0, 1, 1, 1], [1, 0, 1, 1], [1, 1, 1, 1]], dtype=np.float32) expected_merged_classes = np.array( [[1, 0, 0, 1], [1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 1, 1]], dtype=np.int32) expected_merged_confidences = np.array( [[0.1, 0, 0, 0.6], [0.4, 0.9, 0, 0], [0, 0.7, 0.2, 0], [0, 0, 0.3, 0.8]], dtype=np.float32) expected_merged_box_indices = np.array([0, 1, 2, 3], dtype=np.int32) with self.test_session() as sess: (np_merged_boxes, np_merged_classes, np_merged_confidences, np_merged_box_indices) = sess.run( [merged_boxes, merged_classes, merged_confidences, merged_box_indices]) self.assertAllClose(np_merged_boxes, expected_merged_boxes) self.assertAllClose(np_merged_classes, expected_merged_classes) self.assertAllClose(np_merged_confidences, expected_merged_confidences) self.assertAllClose(np_merged_box_indices, expected_merged_box_indices)
Example #21
Source File: ops_test.py From multilabel-image-classification-tensorflow with MIT License | 5 votes |
def testMergeBoxesWithMultipleLabelsCornerCase(self): boxes = tf.constant( [[0, 0, 1, 1], [0, 1, 1, 1], [1, 0, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 0, 1, 1], [0, 1, 1, 1], [0, 0, 1, 1]], dtype=tf.float32) class_indices = tf.constant([0, 1, 2, 3, 2, 1, 0, 3], dtype=tf.int32) class_confidences = tf.constant([0.1, 0.9, 0.2, 0.8, 0.3, 0.7, 0.4, 0.6], dtype=tf.float32) num_classes = 4 merged_boxes, merged_classes, merged_confidences, merged_box_indices = ( ops.merge_boxes_with_multiple_labels( boxes, class_indices, class_confidences, num_classes)) expected_merged_boxes = np.array( [[0, 0, 1, 1], [0, 1, 1, 1], [1, 0, 1, 1], [1, 1, 1, 1]], dtype=np.float32) expected_merged_classes = np.array( [[1, 0, 0, 1], [1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 1, 1]], dtype=np.int32) expected_merged_confidences = np.array( [[0.1, 0, 0, 0.6], [0.4, 0.9, 0, 0], [0, 0.7, 0.2, 0], [0, 0, 0.3, 0.8]], dtype=np.float32) expected_merged_box_indices = np.array([0, 1, 2, 3], dtype=np.int32) with self.test_session() as sess: (np_merged_boxes, np_merged_classes, np_merged_confidences, np_merged_box_indices) = sess.run( [merged_boxes, merged_classes, merged_confidences, merged_box_indices]) self.assertAllClose(np_merged_boxes, expected_merged_boxes) self.assertAllClose(np_merged_classes, expected_merged_classes) self.assertAllClose(np_merged_confidences, expected_merged_confidences) self.assertAllClose(np_merged_box_indices, expected_merged_box_indices)
Example #22
Source File: ops_test.py From monopsr with MIT License | 5 votes |
def testMergeBoxesWithEmptyInputs(self): boxes = tf.constant([[]]) class_indices = tf.constant([]) num_classes = 5 merged_boxes, merged_classes, merged_box_indices = ( ops.merge_boxes_with_multiple_labels(boxes, class_indices, num_classes)) with self.test_session() as sess: np_merged_boxes, np_merged_classes, np_merged_box_indices = sess.run( [merged_boxes, merged_classes, merged_box_indices]) self.assertAllEqual(np_merged_boxes.shape, [0, 4]) self.assertAllEqual(np_merged_classes.shape, [0, 5]) self.assertAllEqual(np_merged_box_indices.shape, [0])
Example #23
Source File: ops_test.py From multilabel-image-classification-tensorflow with MIT License | 5 votes |
def testMergeBoxesWithMultipleLabels(self): boxes = tf.constant( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75], [0.25, 0.25, 0.75, 0.75]], dtype=tf.float32) class_indices = tf.constant([0, 4, 2], dtype=tf.int32) class_confidences = tf.constant([0.8, 0.2, 0.1], dtype=tf.float32) num_classes = 5 merged_boxes, merged_classes, merged_confidences, merged_box_indices = ( ops.merge_boxes_with_multiple_labels( boxes, class_indices, class_confidences, num_classes)) expected_merged_boxes = np.array( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75]], dtype=np.float32) expected_merged_classes = np.array( [[1, 0, 1, 0, 0], [0, 0, 0, 0, 1]], dtype=np.int32) expected_merged_confidences = np.array( [[0.8, 0, 0.1, 0, 0], [0, 0, 0, 0, 0.2]], dtype=np.float32) expected_merged_box_indices = np.array([0, 1], dtype=np.int32) with self.test_session() as sess: (np_merged_boxes, np_merged_classes, np_merged_confidences, np_merged_box_indices) = sess.run( [merged_boxes, merged_classes, merged_confidences, merged_box_indices]) self.assertAllClose(np_merged_boxes, expected_merged_boxes) self.assertAllClose(np_merged_classes, expected_merged_classes) self.assertAllClose(np_merged_confidences, expected_merged_confidences) self.assertAllClose(np_merged_box_indices, expected_merged_box_indices)
Example #24
Source File: ops_test.py From AniSeg with Apache License 2.0 | 5 votes |
def testMergeBoxesWithEmptyInputs(self): boxes = tf.constant([[]]) class_indices = tf.constant([]) num_classes = 5 merged_boxes, merged_classes, merged_box_indices = ( ops.merge_boxes_with_multiple_labels(boxes, class_indices, num_classes)) with self.test_session() as sess: np_merged_boxes, np_merged_classes, np_merged_box_indices = sess.run( [merged_boxes, merged_classes, merged_box_indices]) self.assertAllEqual(np_merged_boxes.shape, [0, 4]) self.assertAllEqual(np_merged_classes.shape, [0, 5]) self.assertAllEqual(np_merged_box_indices.shape, [0])
Example #25
Source File: ops_test.py From MAX-Object-Detector with Apache License 2.0 | 5 votes |
def testMergeBoxesWithMultipleLabels(self): boxes = tf.constant( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75], [0.25, 0.25, 0.75, 0.75]], dtype=tf.float32) class_indices = tf.constant([0, 4, 2], dtype=tf.int32) class_confidences = tf.constant([0.8, 0.2, 0.1], dtype=tf.float32) num_classes = 5 merged_boxes, merged_classes, merged_confidences, merged_box_indices = ( ops.merge_boxes_with_multiple_labels( boxes, class_indices, class_confidences, num_classes)) expected_merged_boxes = np.array( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75]], dtype=np.float32) expected_merged_classes = np.array( [[1, 0, 1, 0, 0], [0, 0, 0, 0, 1]], dtype=np.int32) expected_merged_confidences = np.array( [[0.8, 0, 0.1, 0, 0], [0, 0, 0, 0, 0.2]], dtype=np.float32) expected_merged_box_indices = np.array([0, 1], dtype=np.int32) with self.test_session() as sess: (np_merged_boxes, np_merged_classes, np_merged_confidences, np_merged_box_indices) = sess.run( [merged_boxes, merged_classes, merged_confidences, merged_box_indices]) self.assertAllClose(np_merged_boxes, expected_merged_boxes) self.assertAllClose(np_merged_classes, expected_merged_classes) self.assertAllClose(np_merged_confidences, expected_merged_confidences) self.assertAllClose(np_merged_box_indices, expected_merged_box_indices)
Example #26
Source File: ops_test.py From models with Apache License 2.0 | 5 votes |
def testMergeBoxesWithMultipleLabelsUsesInt64(self): if self.is_tf2(): self.skipTest('Getting op names is not supported in eager mode.') boxes = tf.constant( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75], [0.25, 0.25, 0.75, 0.75]], dtype=tf.float32) class_indices = tf.constant([0, 4, 2], dtype=tf.int32) class_confidences = tf.constant([0.8, 0.2, 0.1], dtype=tf.float32) num_classes = 5 ops.merge_boxes_with_multiple_labels( boxes, class_indices, class_confidences, num_classes) graph = tf.get_default_graph() def assert_dtype_is_int64(op_name): op = graph.get_operation_by_name(op_name) self.assertEqual(op.get_attr('dtype'), tf.int64) def assert_t_is_int64(op_name): op = graph.get_operation_by_name(op_name) self.assertEqual(op.get_attr('T'), tf.int64) assert_dtype_is_int64('map/TensorArray') assert_dtype_is_int64('map/TensorArray_1') assert_dtype_is_int64('map/while/TensorArrayReadV3') assert_t_is_int64('map/while/TensorArrayWrite/TensorArrayWriteV3') assert_t_is_int64( 'map/TensorArrayUnstack/TensorArrayScatter/TensorArrayScatterV3') assert_dtype_is_int64('map/TensorArrayStack/TensorArrayGatherV3')
Example #27
Source File: ops_test.py From models with Apache License 2.0 | 5 votes |
def testMergeBoxesWithMultipleLabelsCornerCase(self): def graph_fn(): boxes = tf.constant( [[0, 0, 1, 1], [0, 1, 1, 1], [1, 0, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 0, 1, 1], [0, 1, 1, 1], [0, 0, 1, 1]], dtype=tf.float32) class_indices = tf.constant([0, 1, 2, 3, 2, 1, 0, 3], dtype=tf.int32) class_confidences = tf.constant([0.1, 0.9, 0.2, 0.8, 0.3, 0.7, 0.4, 0.6], dtype=tf.float32) num_classes = 4 merged_boxes, merged_classes, merged_confidences, merged_box_indices = ( ops.merge_boxes_with_multiple_labels( boxes, class_indices, class_confidences, num_classes)) return (merged_boxes, merged_classes, merged_confidences, merged_box_indices) expected_merged_boxes = np.array( [[0, 0, 1, 1], [0, 1, 1, 1], [1, 0, 1, 1], [1, 1, 1, 1]], dtype=np.float32) expected_merged_classes = np.array( [[1, 0, 0, 1], [1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 1, 1]], dtype=np.int32) expected_merged_confidences = np.array( [[0.1, 0, 0, 0.6], [0.4, 0.9, 0, 0], [0, 0.7, 0.2, 0], [0, 0, 0.3, 0.8]], dtype=np.float32) expected_merged_box_indices = np.array([0, 1, 2, 3], dtype=np.int32) # Running on CPU only as tf.unique is not supported on TPU. (np_merged_boxes, np_merged_classes, np_merged_confidences, np_merged_box_indices) = self.execute_cpu(graph_fn, []) self.assertAllClose(np_merged_boxes, expected_merged_boxes) self.assertAllClose(np_merged_classes, expected_merged_classes) self.assertAllClose(np_merged_confidences, expected_merged_confidences) self.assertAllClose(np_merged_box_indices, expected_merged_box_indices)
Example #28
Source File: ops_test.py From models with Apache License 2.0 | 5 votes |
def testMergeBoxesWithMultipleLabels(self): def graph_fn(): boxes = tf.constant( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75], [0.25, 0.25, 0.75, 0.75]], dtype=tf.float32) class_indices = tf.constant([0, 4, 2], dtype=tf.int32) class_confidences = tf.constant([0.8, 0.2, 0.1], dtype=tf.float32) num_classes = 5 merged_boxes, merged_classes, merged_confidences, merged_box_indices = ( ops.merge_boxes_with_multiple_labels( boxes, class_indices, class_confidences, num_classes)) return (merged_boxes, merged_classes, merged_confidences, merged_box_indices) expected_merged_boxes = np.array( [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75]], dtype=np.float32) expected_merged_classes = np.array( [[1, 0, 1, 0, 0], [0, 0, 0, 0, 1]], dtype=np.int32) expected_merged_confidences = np.array( [[0.8, 0, 0.1, 0, 0], [0, 0, 0, 0, 0.2]], dtype=np.float32) expected_merged_box_indices = np.array([0, 1], dtype=np.int32) # Running on CPU only as tf.unique is not supported on TPU. (np_merged_boxes, np_merged_classes, np_merged_confidences, np_merged_box_indices) = self.execute_cpu(graph_fn, []) self.assertAllClose(np_merged_boxes, expected_merged_boxes) self.assertAllClose(np_merged_classes, expected_merged_classes) self.assertAllClose(np_merged_confidences, expected_merged_confidences) self.assertAllClose(np_merged_box_indices, expected_merged_box_indices)
Example #29
Source File: ops_test.py From open-solution-googleai-object-detection with MIT License | 5 votes |
def testMergeBoxesWithEmptyInputs(self): boxes = tf.constant([[]]) class_indices = tf.constant([]) num_classes = 5 merged_boxes, merged_classes, merged_box_indices = ( ops.merge_boxes_with_multiple_labels(boxes, class_indices, num_classes)) with self.test_session() as sess: np_merged_boxes, np_merged_classes, np_merged_box_indices = sess.run( [merged_boxes, merged_classes, merged_box_indices]) self.assertAllEqual(np_merged_boxes.shape, [0, 4]) self.assertAllEqual(np_merged_classes.shape, [0, 5]) self.assertAllEqual(np_merged_box_indices.shape, [0])
Example #30
Source File: ops_test.py From vehicle_counting_tensorflow with MIT License | 5 votes |
def testMergeBoxesWithMultipleLabelsCornerCase(self): boxes = tf.constant( [[0, 0, 1, 1], [0, 1, 1, 1], [1, 0, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 0, 1, 1], [0, 1, 1, 1], [0, 0, 1, 1]], dtype=tf.float32) class_indices = tf.constant([0, 1, 2, 3, 2, 1, 0, 3], dtype=tf.int32) class_confidences = tf.constant([0.1, 0.9, 0.2, 0.8, 0.3, 0.7, 0.4, 0.6], dtype=tf.float32) num_classes = 4 merged_boxes, merged_classes, merged_confidences, merged_box_indices = ( ops.merge_boxes_with_multiple_labels( boxes, class_indices, class_confidences, num_classes)) expected_merged_boxes = np.array( [[0, 0, 1, 1], [0, 1, 1, 1], [1, 0, 1, 1], [1, 1, 1, 1]], dtype=np.float32) expected_merged_classes = np.array( [[1, 0, 0, 1], [1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 1, 1]], dtype=np.int32) expected_merged_confidences = np.array( [[0.1, 0, 0, 0.6], [0.4, 0.9, 0, 0], [0, 0.7, 0.2, 0], [0, 0, 0.3, 0.8]], dtype=np.float32) expected_merged_box_indices = np.array([0, 1, 2, 3], dtype=np.int32) with self.test_session() as sess: (np_merged_boxes, np_merged_classes, np_merged_confidences, np_merged_box_indices) = sess.run( [merged_boxes, merged_classes, merged_confidences, merged_box_indices]) self.assertAllClose(np_merged_boxes, expected_merged_boxes) self.assertAllClose(np_merged_classes, expected_merged_classes) self.assertAllClose(np_merged_confidences, expected_merged_confidences) self.assertAllClose(np_merged_box_indices, expected_merged_box_indices)