Python object_detection.utils.test_utils.first_rows_close_as_set() Examples
The following are 16
code examples of object_detection.utils.test_utils.first_rows_close_as_set().
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.test_utils
, or try the search function
.
Example #1
Source File: test_utils_test.py From vehicle_counting_tensorflow with MIT License | 5 votes |
def test_first_rows_close_as_set(self): a = [1, 2, 3, 0, 0] b = [3, 2, 1, 0, 0] k = 3 self.assertTrue(test_utils.first_rows_close_as_set(a, b, k)) a = [[1, 2], [1, 4], [0, 0]] b = [[1, 4 + 1e-9], [1, 2], [0, 0]] k = 2 self.assertTrue(test_utils.first_rows_close_as_set(a, b, k)) a = [[1, 2], [1, 4], [0, 0]] b = [[1, 4 + 1e-9], [2, 2], [0, 0]] k = 2 self.assertFalse(test_utils.first_rows_close_as_set(a, b, k))
Example #2
Source File: test_utils_test.py From Person-Detection-and-Tracking with MIT License | 5 votes |
def test_first_rows_close_as_set(self): a = [1, 2, 3, 0, 0] b = [3, 2, 1, 0, 0] k = 3 self.assertTrue(test_utils.first_rows_close_as_set(a, b, k)) a = [[1, 2], [1, 4], [0, 0]] b = [[1, 4 + 1e-9], [1, 2], [0, 0]] k = 2 self.assertTrue(test_utils.first_rows_close_as_set(a, b, k)) a = [[1, 2], [1, 4], [0, 0]] b = [[1, 4 + 1e-9], [2, 2], [0, 0]] k = 2 self.assertFalse(test_utils.first_rows_close_as_set(a, b, k))
Example #3
Source File: test_utils_test.py From BMW-TensorFlow-Training-GUI with Apache License 2.0 | 5 votes |
def test_first_rows_close_as_set(self): a = [1, 2, 3, 0, 0] b = [3, 2, 1, 0, 0] k = 3 self.assertTrue(test_utils.first_rows_close_as_set(a, b, k)) a = [[1, 2], [1, 4], [0, 0]] b = [[1, 4 + 1e-9], [1, 2], [0, 0]] k = 2 self.assertTrue(test_utils.first_rows_close_as_set(a, b, k)) a = [[1, 2], [1, 4], [0, 0]] b = [[1, 4 + 1e-9], [2, 2], [0, 0]] k = 2 self.assertFalse(test_utils.first_rows_close_as_set(a, b, k))
Example #4
Source File: test_utils_test.py From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 | 5 votes |
def test_first_rows_close_as_set(self): a = [1, 2, 3, 0, 0] b = [3, 2, 1, 0, 0] k = 3 self.assertTrue(test_utils.first_rows_close_as_set(a, b, k)) a = [[1, 2], [1, 4], [0, 0]] b = [[1, 4 + 1e-9], [1, 2], [0, 0]] k = 2 self.assertTrue(test_utils.first_rows_close_as_set(a, b, k)) a = [[1, 2], [1, 4], [0, 0]] b = [[1, 4 + 1e-9], [2, 2], [0, 0]] k = 2 self.assertFalse(test_utils.first_rows_close_as_set(a, b, k))
Example #5
Source File: test_utils_test.py From MAX-Object-Detector with Apache License 2.0 | 5 votes |
def test_first_rows_close_as_set(self): a = [1, 2, 3, 0, 0] b = [3, 2, 1, 0, 0] k = 3 self.assertTrue(test_utils.first_rows_close_as_set(a, b, k)) a = [[1, 2], [1, 4], [0, 0]] b = [[1, 4 + 1e-9], [1, 2], [0, 0]] k = 2 self.assertTrue(test_utils.first_rows_close_as_set(a, b, k)) a = [[1, 2], [1, 4], [0, 0]] b = [[1, 4 + 1e-9], [2, 2], [0, 0]] k = 2 self.assertFalse(test_utils.first_rows_close_as_set(a, b, k))
Example #6
Source File: test_utils_test.py From open-solution-googleai-object-detection with MIT License | 5 votes |
def test_first_rows_close_as_set(self): a = [1, 2, 3, 0, 0] b = [3, 2, 1, 0, 0] k = 3 self.assertTrue(test_utils.first_rows_close_as_set(a, b, k)) a = [[1, 2], [1, 4], [0, 0]] b = [[1, 4 + 1e-9], [1, 2], [0, 0]] k = 2 self.assertTrue(test_utils.first_rows_close_as_set(a, b, k)) a = [[1, 2], [1, 4], [0, 0]] b = [[1, 4 + 1e-9], [2, 2], [0, 0]] k = 2 self.assertFalse(test_utils.first_rows_close_as_set(a, b, k))
Example #7
Source File: test_utils_test.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def test_first_rows_close_as_set(self): a = [1, 2, 3, 0, 0] b = [3, 2, 1, 0, 0] k = 3 self.assertTrue(test_utils.first_rows_close_as_set(a, b, k)) a = [[1, 2], [1, 4], [0, 0]] b = [[1, 4 + 1e-9], [1, 2], [0, 0]] k = 2 self.assertTrue(test_utils.first_rows_close_as_set(a, b, k)) a = [[1, 2], [1, 4], [0, 0]] b = [[1, 4 + 1e-9], [2, 2], [0, 0]] k = 2 self.assertFalse(test_utils.first_rows_close_as_set(a, b, k))
Example #8
Source File: test_utils_test.py From models with Apache License 2.0 | 5 votes |
def test_first_rows_close_as_set(self): a = [1, 2, 3, 0, 0] b = [3, 2, 1, 0, 0] k = 3 self.assertTrue(test_utils.first_rows_close_as_set(a, b, k)) a = [[1, 2], [1, 4], [0, 0]] b = [[1, 4 + 1e-9], [1, 2], [0, 0]] k = 2 self.assertTrue(test_utils.first_rows_close_as_set(a, b, k)) a = [[1, 2], [1, 4], [0, 0]] b = [[1, 4 + 1e-9], [2, 2], [0, 0]] k = 2 self.assertFalse(test_utils.first_rows_close_as_set(a, b, k))
Example #9
Source File: test_utils_test.py From multilabel-image-classification-tensorflow with MIT License | 5 votes |
def test_first_rows_close_as_set(self): a = [1, 2, 3, 0, 0] b = [3, 2, 1, 0, 0] k = 3 self.assertTrue(test_utils.first_rows_close_as_set(a, b, k)) a = [[1, 2], [1, 4], [0, 0]] b = [[1, 4 + 1e-9], [1, 2], [0, 0]] k = 2 self.assertTrue(test_utils.first_rows_close_as_set(a, b, k)) a = [[1, 2], [1, 4], [0, 0]] b = [[1, 4 + 1e-9], [2, 2], [0, 0]] k = 2 self.assertFalse(test_utils.first_rows_close_as_set(a, b, k))
Example #10
Source File: ssd_meta_arch_test.py From vehicle_counting_tensorflow with MIT License | 4 votes |
def test_postprocess_results_are_correct(self, use_keras): batch_size = 2 image_size = 2 input_shapes = [(batch_size, image_size, image_size, 3), (None, image_size, image_size, 3), (batch_size, None, None, 3), (None, None, None, 3)] expected_boxes = [ [ [0, 0, .5, .5], [0, .5, .5, 1], [.5, 0, 1, .5], [0, 0, 0, 0], # pruned prediction [0, 0, 0, 0] ], # padding [ [0, 0, .5, .5], [0, .5, .5, 1], [.5, 0, 1, .5], [0, 0, 0, 0], # pruned prediction [0, 0, 0, 0] ] ] # padding expected_scores = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] expected_classes = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] expected_num_detections = np.array([3, 3]) for input_shape in input_shapes: tf_graph = tf.Graph() with tf_graph.as_default(): model, _, _, _ = self._create_model(use_keras=use_keras) input_placeholder = tf.placeholder(tf.float32, shape=input_shape) preprocessed_inputs, true_image_shapes = model.preprocess( input_placeholder) prediction_dict = model.predict(preprocessed_inputs, true_image_shapes) detections = model.postprocess(prediction_dict, true_image_shapes) self.assertIn('detection_boxes', detections) self.assertIn('detection_scores', detections) self.assertIn('detection_classes', detections) self.assertIn('num_detections', detections) init_op = tf.global_variables_initializer() with self.test_session(graph=tf_graph) as sess: sess.run(init_op) detections_out = sess.run(detections, feed_dict={ input_placeholder: np.random.uniform( size=(batch_size, 2, 2, 3))}) for image_idx in range(batch_size): self.assertTrue( test_utils.first_rows_close_as_set( detections_out['detection_boxes'][image_idx].tolist(), expected_boxes[image_idx])) self.assertAllClose(detections_out['detection_scores'], expected_scores) self.assertAllClose(detections_out['detection_classes'], expected_classes) self.assertAllClose(detections_out['num_detections'], expected_num_detections)
Example #11
Source File: ssd_meta_arch_test.py From Person-Detection-and-Tracking with MIT License | 4 votes |
def test_postprocess_results_are_correct(self): batch_size = 2 image_size = 2 input_shapes = [(batch_size, image_size, image_size, 3), (None, image_size, image_size, 3), (batch_size, None, None, 3), (None, None, None, 3)] expected_boxes = [ [ [0, 0, .5, .5], [0, .5, .5, 1], [.5, 0, 1, .5], [0, 0, 0, 0], # pruned prediction [0, 0, 0, 0] ], # padding [ [0, 0, .5, .5], [0, .5, .5, 1], [.5, 0, 1, .5], [0, 0, 0, 0], # pruned prediction [0, 0, 0, 0] ] ] # padding expected_scores = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] expected_classes = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] expected_num_detections = np.array([3, 3]) for input_shape in input_shapes: tf_graph = tf.Graph() with tf_graph.as_default(): model, _, _, _ = self._create_model() input_placeholder = tf.placeholder(tf.float32, shape=input_shape) preprocessed_inputs, true_image_shapes = model.preprocess( input_placeholder) prediction_dict = model.predict(preprocessed_inputs, true_image_shapes) detections = model.postprocess(prediction_dict, true_image_shapes) self.assertTrue('detection_boxes' in detections) self.assertTrue('detection_scores' in detections) self.assertTrue('detection_classes' in detections) self.assertTrue('num_detections' in detections) init_op = tf.global_variables_initializer() with self.test_session(graph=tf_graph) as sess: sess.run(init_op) detections_out = sess.run(detections, feed_dict={ input_placeholder: np.random.uniform( size=(batch_size, 2, 2, 3))}) for image_idx in range(batch_size): self.assertTrue( test_utils.first_rows_close_as_set( detections_out['detection_boxes'][image_idx].tolist(), expected_boxes[image_idx])) self.assertAllClose(detections_out['detection_scores'], expected_scores) self.assertAllClose(detections_out['detection_classes'], expected_classes) self.assertAllClose(detections_out['num_detections'], expected_num_detections)
Example #12
Source File: ssd_meta_arch_test.py From BMW-TensorFlow-Training-GUI with Apache License 2.0 | 4 votes |
def test_postprocess_results_are_correct(self, use_keras): batch_size = 2 image_size = 2 input_shapes = [(batch_size, image_size, image_size, 3), (None, image_size, image_size, 3), (batch_size, None, None, 3), (None, None, None, 3)] expected_boxes = [ [ [0, 0, .5, .5], [0, .5, .5, 1], [.5, 0, 1, .5], [0, 0, 0, 0], # pruned prediction [0, 0, 0, 0] ], # padding [ [0, 0, .5, .5], [0, .5, .5, 1], [.5, 0, 1, .5], [0, 0, 0, 0], # pruned prediction [0, 0, 0, 0] ] ] # padding expected_scores = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] expected_classes = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] expected_num_detections = np.array([3, 3]) for input_shape in input_shapes: tf_graph = tf.Graph() with tf_graph.as_default(): model, _, _, _ = self._create_model(use_keras=use_keras) input_placeholder = tf.placeholder(tf.float32, shape=input_shape) preprocessed_inputs, true_image_shapes = model.preprocess( input_placeholder) prediction_dict = model.predict(preprocessed_inputs, true_image_shapes) detections = model.postprocess(prediction_dict, true_image_shapes) self.assertIn('detection_boxes', detections) self.assertIn('detection_scores', detections) self.assertIn('detection_classes', detections) self.assertIn('num_detections', detections) init_op = tf.global_variables_initializer() with self.test_session(graph=tf_graph) as sess: sess.run(init_op) detections_out = sess.run(detections, feed_dict={ input_placeholder: np.random.uniform( size=(batch_size, 2, 2, 3))}) for image_idx in range(batch_size): self.assertTrue( test_utils.first_rows_close_as_set( detections_out['detection_boxes'][image_idx].tolist(), expected_boxes[image_idx])) self.assertAllClose(detections_out['detection_scores'], expected_scores) self.assertAllClose(detections_out['detection_classes'], expected_classes) self.assertAllClose(detections_out['num_detections'], expected_num_detections)
Example #13
Source File: ssd_meta_arch_test.py From MAX-Object-Detector with Apache License 2.0 | 4 votes |
def test_postprocess_results_are_correct(self, use_keras): batch_size = 2 image_size = 2 input_shapes = [(batch_size, image_size, image_size, 3), (None, image_size, image_size, 3), (batch_size, None, None, 3), (None, None, None, 3)] expected_boxes = [ [ [0, 0, .5, .5], [0, .5, .5, 1], [.5, 0, 1, .5], [0, 0, 0, 0], # pruned prediction [0, 0, 0, 0] ], # padding [ [0, 0, .5, .5], [0, .5, .5, 1], [.5, 0, 1, .5], [0, 0, 0, 0], # pruned prediction [0, 0, 0, 0] ] ] # padding expected_scores = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] expected_classes = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] expected_num_detections = np.array([3, 3]) for input_shape in input_shapes: tf_graph = tf.Graph() with tf_graph.as_default(): model, _, _, _ = self._create_model(use_keras=use_keras) input_placeholder = tf.placeholder(tf.float32, shape=input_shape) preprocessed_inputs, true_image_shapes = model.preprocess( input_placeholder) prediction_dict = model.predict(preprocessed_inputs, true_image_shapes) detections = model.postprocess(prediction_dict, true_image_shapes) self.assertIn('detection_boxes', detections) self.assertIn('detection_scores', detections) self.assertIn('detection_classes', detections) self.assertIn('num_detections', detections) init_op = tf.global_variables_initializer() with self.test_session(graph=tf_graph) as sess: sess.run(init_op) detections_out = sess.run(detections, feed_dict={ input_placeholder: np.random.uniform( size=(batch_size, 2, 2, 3))}) for image_idx in range(batch_size): self.assertTrue( test_utils.first_rows_close_as_set( detections_out['detection_boxes'][image_idx].tolist(), expected_boxes[image_idx])) self.assertAllClose(detections_out['detection_scores'], expected_scores) self.assertAllClose(detections_out['detection_classes'], expected_classes) self.assertAllClose(detections_out['num_detections'], expected_num_detections)
Example #14
Source File: ssd_meta_arch_test.py From g-tensorflow-models with Apache License 2.0 | 4 votes |
def test_postprocess_results_are_correct(self, use_keras): batch_size = 2 image_size = 2 input_shapes = [(batch_size, image_size, image_size, 3), (None, image_size, image_size, 3), (batch_size, None, None, 3), (None, None, None, 3)] expected_boxes = [ [ [0, 0, .5, .5], [0, .5, .5, 1], [.5, 0, 1, .5], [0, 0, 0, 0], # pruned prediction [0, 0, 0, 0] ], # padding [ [0, 0, .5, .5], [0, .5, .5, 1], [.5, 0, 1, .5], [0, 0, 0, 0], # pruned prediction [0, 0, 0, 0] ] ] # padding expected_scores = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] expected_classes = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] expected_num_detections = np.array([3, 3]) for input_shape in input_shapes: tf_graph = tf.Graph() with tf_graph.as_default(): model, _, _, _ = self._create_model(use_keras=use_keras) input_placeholder = tf.placeholder(tf.float32, shape=input_shape) preprocessed_inputs, true_image_shapes = model.preprocess( input_placeholder) prediction_dict = model.predict(preprocessed_inputs, true_image_shapes) detections = model.postprocess(prediction_dict, true_image_shapes) self.assertIn('detection_boxes', detections) self.assertIn('detection_scores', detections) self.assertIn('detection_classes', detections) self.assertIn('num_detections', detections) init_op = tf.global_variables_initializer() with self.test_session(graph=tf_graph) as sess: sess.run(init_op) detections_out = sess.run(detections, feed_dict={ input_placeholder: np.random.uniform( size=(batch_size, 2, 2, 3))}) for image_idx in range(batch_size): self.assertTrue( test_utils.first_rows_close_as_set( detections_out['detection_boxes'][image_idx].tolist(), expected_boxes[image_idx])) self.assertAllClose(detections_out['detection_scores'], expected_scores) self.assertAllClose(detections_out['detection_classes'], expected_classes) self.assertAllClose(detections_out['num_detections'], expected_num_detections)
Example #15
Source File: ssd_meta_arch_test.py From models with Apache License 2.0 | 4 votes |
def test_postprocess_results_are_correct_static(self): with test_utils.GraphContextOrNone() as g: model, _, _, _ = self._create_model(use_static_shapes=True, nms_max_size_per_class=4) def graph_fn(input_image): preprocessed_inputs, true_image_shapes = model.preprocess(input_image) prediction_dict = model.predict(preprocessed_inputs, true_image_shapes) detections = model.postprocess(prediction_dict, true_image_shapes) return (detections['detection_boxes'], detections['detection_scores'], detections['detection_classes'], detections['num_detections'], detections['detection_multiclass_scores']) expected_boxes = [ [ [0, 0, .5, .5], [0, .5, .5, 1], [.5, 0, 1, .5], [0, 0, 0, 0] ], # padding [ [0, 0, .5, .5], [0, .5, .5, 1], [.5, 0, 1, .5], [0, 0, 0, 0] ] ] # padding expected_scores = [[0, 0, 0, 0], [0, 0, 0, 0]] expected_multiclass_scores = [[[0, 0], [0, 0], [0, 0], [0, 0]], [[0, 0], [0, 0], [0, 0], [0, 0]]] expected_classes = [[0, 0, 0, 0], [0, 0, 0, 0]] expected_num_detections = np.array([3, 3]) batch_size = 2 image_size = 2 channels = 3 input_image = np.random.rand(batch_size, image_size, image_size, channels).astype(np.float32) (detection_boxes, detection_scores, detection_classes, num_detections, detection_multiclass_scores) = self.execute(graph_fn, [input_image], graph=g) for image_idx in range(batch_size): self.assertTrue(test_utils.first_rows_close_as_set( detection_boxes[image_idx][ 0:expected_num_detections[image_idx]].tolist(), expected_boxes[image_idx][0:expected_num_detections[image_idx]])) self.assertAllClose( detection_scores[image_idx][0:expected_num_detections[image_idx]], expected_scores[image_idx][0:expected_num_detections[image_idx]]) self.assertAllClose( detection_multiclass_scores[image_idx] [0:expected_num_detections[image_idx]], expected_multiclass_scores[image_idx] [0:expected_num_detections[image_idx]]) self.assertAllClose( detection_classes[image_idx][0:expected_num_detections[image_idx]], expected_classes[image_idx][0:expected_num_detections[image_idx]]) self.assertAllClose(num_detections, expected_num_detections)
Example #16
Source File: ssd_meta_arch_test.py From multilabel-image-classification-tensorflow with MIT License | 4 votes |
def test_postprocess_results_are_correct(self, use_keras): batch_size = 2 image_size = 2 input_shapes = [(batch_size, image_size, image_size, 3), (None, image_size, image_size, 3), (batch_size, None, None, 3), (None, None, None, 3)] expected_boxes = [ [ [0, 0, .5, .5], [0, .5, .5, 1], [.5, 0, 1, .5], [0, 0, 0, 0], # pruned prediction [0, 0, 0, 0] ], # padding [ [0, 0, .5, .5], [0, .5, .5, 1], [.5, 0, 1, .5], [0, 0, 0, 0], # pruned prediction [0, 0, 0, 0] ] ] # padding expected_scores = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] expected_classes = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] expected_num_detections = np.array([3, 3]) for input_shape in input_shapes: tf_graph = tf.Graph() with tf_graph.as_default(): model, _, _, _ = self._create_model(use_keras=use_keras) input_placeholder = tf.placeholder(tf.float32, shape=input_shape) preprocessed_inputs, true_image_shapes = model.preprocess( input_placeholder) prediction_dict = model.predict(preprocessed_inputs, true_image_shapes) detections = model.postprocess(prediction_dict, true_image_shapes) self.assertIn('detection_boxes', detections) self.assertIn('detection_scores', detections) self.assertIn('detection_classes', detections) self.assertIn('num_detections', detections) init_op = tf.global_variables_initializer() with self.test_session(graph=tf_graph) as sess: sess.run(init_op) detections_out = sess.run(detections, feed_dict={ input_placeholder: np.random.uniform( size=(batch_size, 2, 2, 3))}) for image_idx in range(batch_size): self.assertTrue( test_utils.first_rows_close_as_set( detections_out['detection_boxes'][image_idx].tolist(), expected_boxes[image_idx])) self.assertAllClose(detections_out['detection_scores'], expected_scores) self.assertAllClose(detections_out['detection_classes'], expected_classes) self.assertAllClose(detections_out['num_detections'], expected_num_detections)