Python object_detection.core.box_list.BoxList() Examples
The following are 30
code examples of object_detection.core.box_list.BoxList().
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.core.box_list
, or try the search function
.
Example #1
Source File: losses.py From DOTA_models with Apache License 2.0 | 6 votes |
def _compute_loss(self, prediction_tensor, target_tensor, weights): """Compute loss function. Args: prediction_tensor: A float tensor of shape [batch_size, num_anchors, 4] representing the decoded predicted boxes target_tensor: A float tensor of shape [batch_size, num_anchors, 4] representing the decoded target boxes weights: a float tensor of shape [batch_size, num_anchors] Returns: loss: a (scalar) tensor representing the value of the loss function """ predicted_boxes = box_list.BoxList(tf.reshape(prediction_tensor, [-1, 4])) target_boxes = box_list.BoxList(tf.reshape(target_tensor, [-1, 4])) per_anchor_iou_loss = 1.0 - box_list_ops.matched_iou(predicted_boxes, target_boxes) return tf.reduce_sum(tf.reshape(weights, [-1]) * per_anchor_iou_loss)
Example #2
Source File: box_list_ops_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_clip_box_list(self): boxlist = box_list.BoxList( tf.constant([[0.1, 0.1, 0.4, 0.4], [0.1, 0.1, 0.5, 0.5], [0.6, 0.6, 0.8, 0.8], [0.2, 0.2, 0.3, 0.3]], tf.float32)) boxlist.add_field('classes', tf.constant([0, 0, 1, 1])) boxlist.add_field('scores', tf.constant([0.75, 0.65, 0.3, 0.2])) num_boxes = 2 clipped_boxlist = box_list_ops.pad_or_clip_box_list(boxlist, num_boxes) expected_boxes = [[0.1, 0.1, 0.4, 0.4], [0.1, 0.1, 0.5, 0.5]] expected_classes = [0, 0] expected_scores = [0.75, 0.65] with self.test_session() as sess: boxes_out, classes_out, scores_out = sess.run( [clipped_boxlist.get(), clipped_boxlist.get_field('classes'), clipped_boxlist.get_field('scores')]) self.assertAllClose(expected_boxes, boxes_out) self.assertAllEqual(expected_classes, classes_out) self.assertAllClose(expected_scores, scores_out)
Example #3
Source File: keypoint_box_coder_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_get_correct_boxes_after_decoding(self): anchors = [[15., 12., 30., 18.], [0.1, 0.0, 0.7, 0.9]] rel_codes = [ [-0.5, -0.416666, -0.405465, -0.182321, -0.5, -0.5, -0.833333, 0.], [-0.083333, -0.222222, -0.693147, -1.098612, 0.166667, -0.166667, -0.333333, -0.055556] ] expected_boxes = [[10., 10., 20., 15.], [0.2, 0.1, 0.5, 0.4]] expected_keypoints = [[[15., 12.], [10., 15.]], [[0.5, 0.3], [0.2, 0.4]]] num_keypoints = len(expected_keypoints[0]) anchors = box_list.BoxList(tf.constant(anchors)) coder = keypoint_box_coder.KeypointBoxCoder(num_keypoints) boxes = coder.decode(rel_codes, anchors) with self.test_session() as sess: boxes_out, keypoints_out = sess.run( [boxes.get(), boxes.get_field(fields.BoxListFields.keypoints)]) self.assertAllClose(boxes_out, expected_boxes) self.assertAllClose(keypoints_out, expected_keypoints)
Example #4
Source File: faster_rcnn_meta_arch.py From DOTA_models with Apache License 2.0 | 6 votes |
def _batch_decode_refined_boxes(self, refined_box_encodings, proposal_boxes): """Decode tensor of refined box encodings. Args: refined_box_encodings: a 3-D tensor with shape [batch_size, max_num_proposals, num_classes, self._box_coder.code_size] representing predicted (final) refined box encodings. proposal_boxes: [batch_size, self.max_num_proposals, 4] representing decoded proposal bounding boxes. Returns: refined_box_predictions: a [batch_size, max_num_proposals, num_classes, 4] float tensor representing (padded) refined bounding box predictions (for each image in batch, proposal and class). """ tiled_proposal_boxes = tf.tile( tf.expand_dims(proposal_boxes, 2), [1, 1, self.num_classes, 1]) tiled_proposals_boxlist = box_list.BoxList( tf.reshape(tiled_proposal_boxes, [-1, 4])) decoded_boxes = self._box_coder.decode( tf.reshape(refined_box_encodings, [-1, self._box_coder.code_size]), tiled_proposals_boxlist) return tf.reshape(decoded_boxes.get(), [-1, self.max_num_proposals, self.num_classes, 4])
Example #5
Source File: box_list_ops_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_ioa(self): corners1 = tf.constant([[4.0, 3.0, 7.0, 5.0], [5.0, 6.0, 10.0, 7.0]]) corners2 = tf.constant([[3.0, 4.0, 6.0, 8.0], [14.0, 14.0, 15.0, 15.0], [0.0, 0.0, 20.0, 20.0]]) exp_output_1 = [[2.0 / 12.0, 0, 6.0 / 400.0], [1.0 / 12.0, 0.0, 5.0 / 400.0]] exp_output_2 = [[2.0 / 6.0, 1.0 / 5.0], [0, 0], [6.0 / 6.0, 5.0 / 5.0]] boxes1 = box_list.BoxList(corners1) boxes2 = box_list.BoxList(corners2) ioa_1 = box_list_ops.ioa(boxes1, boxes2) ioa_2 = box_list_ops.ioa(boxes2, boxes1) with self.test_session() as sess: ioa_output_1, ioa_output_2 = sess.run([ioa_1, ioa_2]) self.assertAllClose(ioa_output_1, exp_output_1) self.assertAllClose(ioa_output_2, exp_output_2)
Example #6
Source File: box_list_ops_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_prune_non_overlapping_boxes(self): corners1 = tf.constant([[4.0, 3.0, 7.0, 5.0], [5.0, 6.0, 10.0, 7.0]]) corners2 = tf.constant([[3.0, 4.0, 6.0, 8.0], [14.0, 14.0, 15.0, 15.0], [0.0, 0.0, 20.0, 20.0]]) boxes1 = box_list.BoxList(corners1) boxes2 = box_list.BoxList(corners2) minoverlap = 0.5 exp_output_1 = boxes1 exp_output_2 = box_list.BoxList(tf.constant(0.0, shape=[0, 4])) output_1, keep_indices_1 = box_list_ops.prune_non_overlapping_boxes( boxes1, boxes2, min_overlap=minoverlap) output_2, keep_indices_2 = box_list_ops.prune_non_overlapping_boxes( boxes2, boxes1, min_overlap=minoverlap) with self.test_session() as sess: (output_1_, keep_indices_1_, output_2_, keep_indices_2_, exp_output_1_, exp_output_2_) = sess.run( [output_1.get(), keep_indices_1, output_2.get(), keep_indices_2, exp_output_1.get(), exp_output_2.get()]) self.assertAllClose(output_1_, exp_output_1_) self.assertAllClose(output_2_, exp_output_2_) self.assertAllEqual(keep_indices_1_, [0, 1]) self.assertAllEqual(keep_indices_2_, [])
Example #7
Source File: box_list_ops_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_pad_box_list(self): boxlist = box_list.BoxList( tf.constant([[0.1, 0.1, 0.4, 0.4], [0.1, 0.1, 0.5, 0.5]], tf.float32)) boxlist.add_field('classes', tf.constant([0, 1])) boxlist.add_field('scores', tf.constant([0.75, 0.2])) num_boxes = 4 padded_boxlist = box_list_ops.pad_or_clip_box_list(boxlist, num_boxes) expected_boxes = [[0.1, 0.1, 0.4, 0.4], [0.1, 0.1, 0.5, 0.5], [0, 0, 0, 0], [0, 0, 0, 0]] expected_classes = [0, 1, 0, 0] expected_scores = [0.75, 0.2, 0, 0] with self.test_session() as sess: boxes_out, classes_out, scores_out = sess.run( [padded_boxlist.get(), padded_boxlist.get_field('classes'), padded_boxlist.get_field('scores')]) self.assertAllClose(expected_boxes, boxes_out) self.assertAllEqual(expected_classes, classes_out) self.assertAllClose(expected_scores, scores_out)
Example #8
Source File: keypoint_box_coder_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_get_correct_relative_codes_after_encoding(self): boxes = [[10., 10., 20., 15.], [0.2, 0.1, 0.5, 0.4]] keypoints = [[[15., 12.], [10., 15.]], [[0.5, 0.3], [0.2, 0.4]]] num_keypoints = len(keypoints[0]) anchors = [[15., 12., 30., 18.], [0.1, 0.0, 0.7, 0.9]] expected_rel_codes = [ [-0.5, -0.416666, -0.405465, -0.182321, -0.5, -0.5, -0.833333, 0.], [-0.083333, -0.222222, -0.693147, -1.098612, 0.166667, -0.166667, -0.333333, -0.055556] ] boxes = box_list.BoxList(tf.constant(boxes)) boxes.add_field(fields.BoxListFields.keypoints, tf.constant(keypoints)) anchors = box_list.BoxList(tf.constant(anchors)) coder = keypoint_box_coder.KeypointBoxCoder(num_keypoints) rel_codes = coder.encode(boxes, anchors) with self.test_session() as sess: rel_codes_out, = sess.run([rel_codes]) self.assertAllClose(rel_codes_out, expected_rel_codes)
Example #9
Source File: keypoint_box_coder_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_get_correct_boxes_after_decoding_with_scaling(self): anchors = [[15., 12., 30., 18.], [0.1, 0.0, 0.7, 0.9]] rel_codes = [ [-1., -1.25, -1.62186, -0.911608, -1.0, -1.5, -1.666667, 0.], [-0.166667, -0.666667, -2.772588, -5.493062, 0.333333, -0.5, -0.666667, -0.166667] ] scale_factors = [2, 3, 4, 5] expected_boxes = [[10., 10., 20., 15.], [0.2, 0.1, 0.5, 0.4]] expected_keypoints = [[[15., 12.], [10., 15.]], [[0.5, 0.3], [0.2, 0.4]]] num_keypoints = len(expected_keypoints[0]) anchors = box_list.BoxList(tf.constant(anchors)) coder = keypoint_box_coder.KeypointBoxCoder( num_keypoints, scale_factors=scale_factors) boxes = coder.decode(rel_codes, anchors) with self.test_session() as sess: boxes_out, keypoints_out = sess.run( [boxes.get(), boxes.get_field(fields.BoxListFields.keypoints)]) self.assertAllClose(boxes_out, expected_boxes) self.assertAllClose(keypoints_out, expected_keypoints)
Example #10
Source File: box_list_ops_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_prune_completely_outside_window(self): window = tf.constant([0, 0, 9, 14], tf.float32) corners = tf.constant([[5.0, 5.0, 6.0, 6.0], [-1.0, -2.0, 4.0, 5.0], [2.0, 3.0, 5.0, 9.0], [0.0, 0.0, 9.0, 14.0], [-10.0, -10.0, -9.0, -9.0], [-100.0, -100.0, 300.0, 600.0]]) boxes = box_list.BoxList(corners) boxes.add_field('extra_data', tf.constant([[1], [2], [3], [4], [5], [6]])) exp_output = [[5.0, 5.0, 6.0, 6.0], [-1.0, -2.0, 4.0, 5.0], [2.0, 3.0, 5.0, 9.0], [0.0, 0.0, 9.0, 14.0], [-100.0, -100.0, 300.0, 600.0]] pruned, keep_indices = box_list_ops.prune_completely_outside_window(boxes, window) with self.test_session() as sess: pruned_output = sess.run(pruned.get()) self.assertAllClose(pruned_output, exp_output) keep_indices_out = sess.run(keep_indices) self.assertAllEqual(keep_indices_out, [0, 1, 2, 3, 5]) extra_data_out = sess.run(pruned.get_field('extra_data')) self.assertAllEqual(extra_data_out, [[1], [2], [3], [4], [6]])
Example #11
Source File: mean_stddev_box_coder.py From DOTA_models with Apache License 2.0 | 6 votes |
def _decode(self, rel_codes, anchors): """Decode. Args: rel_codes: a tensor representing N anchor-encoded boxes. anchors: BoxList of anchors. We assume that anchors has an associated stddev field. Returns: boxes: BoxList holding N bounding boxes Raises: ValueError: if the anchors BoxList does not have a stddev field """ if not anchors.has_field('stddev'): raise ValueError('anchors must have a stddev field') means = anchors.get() stddevs = anchors.get_field('stddev') box_corners = rel_codes * stddevs + means return box_list.BoxList(box_corners)
Example #12
Source File: box_list_ops_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_clip_to_window_filter_boxes_which_fall_outside_the_window( self): window = tf.constant([0, 0, 9, 14], tf.float32) corners = tf.constant([[5.0, 5.0, 6.0, 6.0], [-1.0, -2.0, 4.0, 5.0], [2.0, 3.0, 5.0, 9.0], [0.0, 0.0, 9.0, 14.0], [-100.0, -100.0, 300.0, 600.0], [-10.0, -10.0, -9.0, -9.0]]) boxes = box_list.BoxList(corners) boxes.add_field('extra_data', tf.constant([[1], [2], [3], [4], [5], [6]])) exp_output = [[5.0, 5.0, 6.0, 6.0], [0.0, 0.0, 4.0, 5.0], [2.0, 3.0, 5.0, 9.0], [0.0, 0.0, 9.0, 14.0], [0.0, 0.0, 9.0, 14.0]] pruned = box_list_ops.clip_to_window( boxes, window, filter_nonoverlapping=True) with self.test_session() as sess: pruned_output = sess.run(pruned.get()) self.assertAllClose(pruned_output, exp_output) extra_data_out = sess.run(pruned.get_field('extra_data')) self.assertAllEqual(extra_data_out, [[1], [2], [3], [4], [5]])
Example #13
Source File: box_list_ops_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_filter_greater_than(self): corners = tf.constant([[0, 0, 1, 1], [0, 0.1, 1, 1.1], [0, -0.1, 1, 0.9], [0, 10, 1, 11], [0, 10.1, 1, 11.1], [0, 100, 1, 101]], tf.float32) boxes = box_list.BoxList(corners) boxes.add_field('scores', tf.constant([.1, .75, .9, .5, .5, .8])) thresh = .6 exp_output = [[0, 0.1, 1, 1.1], [0, -0.1, 1, 0.9], [0, 100, 1, 101]] filtered_boxes = box_list_ops.filter_greater_than(boxes, thresh) with self.test_session() as sess: filtered_output = sess.run(filtered_boxes.get()) self.assertAllClose(filtered_output, exp_output)
Example #14
Source File: target_assigner_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_raises_error_on_invalid_groundtruth_labels(self): similarity_calc = region_similarity_calculator.NegSqDistSimilarity() matcher = bipartite_matcher.GreedyBipartiteMatcher() box_coder = mean_stddev_box_coder.MeanStddevBoxCoder() unmatched_cls_target = tf.constant([[0, 0], [0, 0], [0, 0]], tf.float32) target_assigner = targetassigner.TargetAssigner( similarity_calc, matcher, box_coder, unmatched_cls_target=unmatched_cls_target) prior_means = tf.constant([[0.0, 0.0, 0.5, 0.5]]) prior_stddevs = tf.constant([[1.0, 1.0, 1.0, 1.0]]) priors = box_list.BoxList(prior_means) priors.add_field('stddev', prior_stddevs) box_corners = [[0.0, 0.0, 0.5, 0.5], [0.5, 0.5, 0.9, 0.9], [.75, 0, .95, .27]] boxes = box_list.BoxList(tf.constant(box_corners)) groundtruth_labels = tf.constant([[[0, 1], [1, 0]]], tf.float32) with self.assertRaises(ValueError): target_assigner.assign(priors, boxes, groundtruth_labels, num_valid_rows=3)
Example #15
Source File: box_list_ops_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_gather_with_dynamic_indexing(self): corners = tf.constant([4 * [0.0], 4 * [1.0], 4 * [2.0], 4 * [3.0], 4 * [4.0] ]) weights = tf.constant([.5, .3, .7, .1, .9], tf.float32) indices = tf.reshape(tf.where(tf.greater(weights, 0.4)), [-1]) expected_subset = [4 * [0.0], 4 * [2.0], 4 * [4.0]] expected_weights = [.5, .7, .9] boxes = box_list.BoxList(corners) boxes.add_field('weights', weights) subset = box_list_ops.gather(boxes, indices, ['weights']) with self.test_session() as sess: subset_output, weights_output = sess.run([subset.get(), subset.get_field( 'weights')]) self.assertAllClose(subset_output, expected_subset) self.assertAllClose(weights_output, expected_weights)
Example #16
Source File: box_list_ops_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_sort_by_field_ascending_order(self): exp_corners = [[0, 0, 1, 1], [0, 0.1, 1, 1.1], [0, -0.1, 1, 0.9], [0, 10, 1, 11], [0, 10.1, 1, 11.1], [0, 100, 1, 101]] exp_scores = [.95, .9, .75, .6, .5, .3] exp_weights = [.2, .45, .6, .75, .8, .92] shuffle = [2, 4, 0, 5, 1, 3] corners = tf.constant([exp_corners[i] for i in shuffle], tf.float32) boxes = box_list.BoxList(corners) boxes.add_field('scores', tf.constant( [exp_scores[i] for i in shuffle], tf.float32)) boxes.add_field('weights', tf.constant( [exp_weights[i] for i in shuffle], tf.float32)) sort_by_weight = box_list_ops.sort_by_field( boxes, 'weights', order=box_list_ops.SortOrder.ascend) with self.test_session() as sess: corners_out, scores_out, weights_out = sess.run([ sort_by_weight.get(), sort_by_weight.get_field('scores'), sort_by_weight.get_field('weights')]) self.assertAllClose(corners_out, exp_corners) self.assertAllClose(scores_out, exp_scores) self.assertAllClose(weights_out, exp_weights)
Example #17
Source File: box_list_ops_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_sort_by_field_descending_order(self): exp_corners = [[0, 0, 1, 1], [0, 0.1, 1, 1.1], [0, -0.1, 1, 0.9], [0, 10, 1, 11], [0, 10.1, 1, 11.1], [0, 100, 1, 101]] exp_scores = [.95, .9, .75, .6, .5, .3] exp_weights = [.2, .45, .6, .75, .8, .92] shuffle = [2, 4, 0, 5, 1, 3] corners = tf.constant([exp_corners[i] for i in shuffle], tf.float32) boxes = box_list.BoxList(corners) boxes.add_field('scores', tf.constant( [exp_scores[i] for i in shuffle], tf.float32)) boxes.add_field('weights', tf.constant( [exp_weights[i] for i in shuffle], tf.float32)) sort_by_score = box_list_ops.sort_by_field(boxes, 'scores') with self.test_session() as sess: corners_out, scores_out, weights_out = sess.run([sort_by_score.get( ), sort_by_score.get_field('scores'), sort_by_score.get_field('weights')]) self.assertAllClose(corners_out, exp_corners) self.assertAllClose(scores_out, exp_scores) self.assertAllClose(weights_out, exp_weights)
Example #18
Source File: box_list_ops_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_sort_by_field_invalid_inputs(self): corners = tf.constant([4 * [0.0], 4 * [0.5], 4 * [1.0], 4 * [2.0], 4 * [3.0], 4 * [4.0]]) misc = tf.constant([[.95, .9], [.5, .3]], tf.float32) weights = tf.constant([.1, .2], tf.float32) boxes = box_list.BoxList(corners) boxes.add_field('misc', misc) boxes.add_field('weights', weights) with self.test_session() as sess: with self.assertRaises(ValueError): box_list_ops.sort_by_field(boxes, 'area') with self.assertRaises(ValueError): box_list_ops.sort_by_field(boxes, 'misc') with self.assertRaisesWithPredicateMatch(errors.InvalidArgumentError, 'Incorrect field size'): sess.run(box_list_ops.sort_by_field(boxes, 'weights').get())
Example #19
Source File: box_list_ops_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_filter_field_value_equals(self): corners = tf.constant([[0, 0, 1, 1], [0, 0.1, 1, 1.1], [0, -0.1, 1, 0.9], [0, 10, 1, 11], [0, 10.1, 1, 11.1], [0, 100, 1, 101]], tf.float32) boxes = box_list.BoxList(corners) boxes.add_field('classes', tf.constant([1, 2, 1, 2, 2, 1])) exp_output1 = [[0, 0, 1, 1], [0, -0.1, 1, 0.9], [0, 100, 1, 101]] exp_output2 = [[0, 0.1, 1, 1.1], [0, 10, 1, 11], [0, 10.1, 1, 11.1]] filtered_boxes1 = box_list_ops.filter_field_value_equals( boxes, 'classes', 1) filtered_boxes2 = box_list_ops.filter_field_value_equals( boxes, 'classes', 2) with self.test_session() as sess: filtered_output1, filtered_output2 = sess.run([filtered_boxes1.get(), filtered_boxes2.get()]) self.assertAllClose(filtered_output1, exp_output1) self.assertAllClose(filtered_output2, exp_output2)
Example #20
Source File: box_list_ops_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_clip_to_window_without_filtering_boxes_which_fall_outside_the_window( self): window = tf.constant([0, 0, 9, 14], tf.float32) corners = tf.constant([[5.0, 5.0, 6.0, 6.0], [-1.0, -2.0, 4.0, 5.0], [2.0, 3.0, 5.0, 9.0], [0.0, 0.0, 9.0, 14.0], [-100.0, -100.0, 300.0, 600.0], [-10.0, -10.0, -9.0, -9.0]]) boxes = box_list.BoxList(corners) boxes.add_field('extra_data', tf.constant([[1], [2], [3], [4], [5], [6]])) exp_output = [[5.0, 5.0, 6.0, 6.0], [0.0, 0.0, 4.0, 5.0], [2.0, 3.0, 5.0, 9.0], [0.0, 0.0, 9.0, 14.0], [0.0, 0.0, 9.0, 14.0], [0.0, 0.0, 0.0, 0.0]] pruned = box_list_ops.clip_to_window( boxes, window, filter_nonoverlapping=False) with self.test_session() as sess: pruned_output = sess.run(pruned.get()) self.assertAllClose(pruned_output, exp_output) extra_data_out = sess.run(pruned.get_field('extra_data')) self.assertAllEqual(extra_data_out, [[1], [2], [3], [4], [5], [6]])
Example #21
Source File: box_coder_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_batch_decode(self): mock_anchor_corners = tf.constant( [[0, 0.1, 0.2, 0.3], [0.2, 0.4, 0.4, 0.6]], tf.float32) mock_anchors = box_list.BoxList(mock_anchor_corners) mock_box_coder = MockBoxCoder() expected_boxes = [[[0.0, 0.1, 0.5, 0.6], [0.5, 0.6, 0.7, 0.8]], [[0.1, 0.2, 0.3, 0.4], [0.7, 0.8, 0.9, 1.0]]] encoded_boxes_list = [mock_box_coder.encode( box_list.BoxList(tf.constant(boxes)), mock_anchors) for boxes in expected_boxes] encoded_boxes = tf.stack(encoded_boxes_list) decoded_boxes = box_coder.batch_decode( encoded_boxes, mock_box_coder, mock_anchors) with self.test_session() as sess: decoded_boxes_result = sess.run(decoded_boxes) self.assertAllClose(expected_boxes, decoded_boxes_result)
Example #22
Source File: box_list_ops_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_boolean_mask_with_field(self): corners = tf.constant( [4 * [0.0], 4 * [1.0], 4 * [2.0], 4 * [3.0], 4 * [4.0]]) indicator = tf.constant([True, False, True, False, True], tf.bool) weights = tf.constant([[.1], [.3], [.5], [.7], [.9]], tf.float32) expected_subset = [4 * [0.0], 4 * [2.0], 4 * [4.0]] expected_weights = [[.1], [.5], [.9]] boxes = box_list.BoxList(corners) boxes.add_field('weights', weights) subset = box_list_ops.boolean_mask(boxes, indicator, ['weights']) with self.test_session() as sess: subset_output, weights_output = sess.run( [subset.get(), subset.get_field('weights')]) self.assertAllClose(subset_output, expected_subset) self.assertAllClose(weights_output, expected_weights)
Example #23
Source File: box_list_ops_test.py From DOTA_models with Apache License 2.0 | 5 votes |
def test_change_coordinate_frame(self): corners = tf.constant([[0.25, 0.5, 0.75, 0.75], [0.5, 0.0, 1.0, 1.0]]) window = tf.constant([0.25, 0.25, 0.75, 0.75]) boxes = box_list.BoxList(corners) expected_corners = tf.constant([[0, 0.5, 1.0, 1.0], [0.5, -0.5, 1.5, 1.5]]) expected_boxes = box_list.BoxList(expected_corners) output = box_list_ops.change_coordinate_frame(boxes, window) with self.test_session() as sess: output_, expected_boxes_ = sess.run([output.get(), expected_boxes.get()]) self.assertAllClose(output_, expected_boxes_)
Example #24
Source File: box_list_ops_test.py From DOTA_models with Apache License 2.0 | 5 votes |
def test_prune_small_boxes_prunes_boxes_with_negative_side(self): boxes = tf.constant([[4.0, 3.0, 7.0, 5.0], [5.0, 6.0, 10.0, 7.0], [3.0, 4.0, 6.0, 8.0], [14.0, 14.0, 15.0, 15.0], [0.0, 0.0, 20.0, 20.0], [2.0, 3.0, 1.5, 7.0], # negative height [2.0, 3.0, 5.0, 1.7]]) # negative width exp_boxes = [[3.0, 4.0, 6.0, 8.0], [0.0, 0.0, 20.0, 20.0]] boxes = box_list.BoxList(boxes) pruned_boxes = box_list_ops.prune_small_boxes(boxes, 3) with self.test_session() as sess: pruned_boxes = sess.run(pruned_boxes.get()) self.assertAllEqual(pruned_boxes, exp_boxes)
Example #25
Source File: box_list_ops_test.py From DOTA_models with Apache License 2.0 | 5 votes |
def test_boolean_mask(self): corners = tf.constant( [4 * [0.0], 4 * [1.0], 4 * [2.0], 4 * [3.0], 4 * [4.0]]) indicator = tf.constant([True, False, True, False, True], tf.bool) expected_subset = [4 * [0.0], 4 * [2.0], 4 * [4.0]] boxes = box_list.BoxList(corners) subset = box_list_ops.boolean_mask(boxes, indicator) with self.test_session() as sess: subset_output = sess.run(subset.get()) self.assertAllClose(subset_output, expected_subset)
Example #26
Source File: box_list_ops_test.py From DOTA_models with Apache License 2.0 | 5 votes |
def test_pairwise_distances(self): corners1 = tf.constant([[0.0, 0.0, 0.0, 0.0], [1.0, 1.0, 0.0, 2.0]]) corners2 = tf.constant([[3.0, 4.0, 1.0, 0.0], [-4.0, 0.0, 0.0, 3.0], [0.0, 0.0, 0.0, 0.0]]) exp_output = [[26, 25, 0], [18, 27, 6]] boxes1 = box_list.BoxList(corners1) boxes2 = box_list.BoxList(corners2) dist_matrix = box_list_ops.sq_dist(boxes1, boxes2) with self.test_session() as sess: dist_output = sess.run(dist_matrix) self.assertAllClose(dist_output, exp_output)
Example #27
Source File: box_list_ops_test.py From DOTA_models with Apache License 2.0 | 5 votes |
def test_prune_small_boxes(self): boxes = tf.constant([[4.0, 3.0, 7.0, 5.0], [5.0, 6.0, 10.0, 7.0], [3.0, 4.0, 6.0, 8.0], [14.0, 14.0, 15.0, 15.0], [0.0, 0.0, 20.0, 20.0]]) exp_boxes = [[3.0, 4.0, 6.0, 8.0], [0.0, 0.0, 20.0, 20.0]] boxes = box_list.BoxList(boxes) pruned_boxes = box_list_ops.prune_small_boxes(boxes, 3) with self.test_session() as sess: pruned_boxes = sess.run(pruned_boxes.get()) self.assertAllEqual(pruned_boxes, exp_boxes)
Example #28
Source File: box_list_ops_test.py From DOTA_models with Apache License 2.0 | 5 votes |
def test_gather_with_invalid_inputs(self): corners = tf.constant( [4 * [0.0], 4 * [1.0], 4 * [2.0], 4 * [3.0], 4 * [4.0]]) indices_float32 = tf.constant([0, 2, 4], tf.float32) boxes = box_list.BoxList(corners) with self.assertRaises(ValueError): _ = box_list_ops.gather(boxes, indices_float32) indices_2d = tf.constant([[0, 2, 4]], tf.int32) boxes = box_list.BoxList(corners) with self.assertRaises(ValueError): _ = box_list_ops.gather(boxes, indices_2d)
Example #29
Source File: grid_anchor_generator.py From DOTA_models with Apache License 2.0 | 5 votes |
def _generate(self, feature_map_shape_list): """Generates a collection of bounding boxes to be used as anchors. Args: feature_map_shape_list: list of pairs of convnet layer resolutions in the format [(height_0, width_0)]. For example, setting feature_map_shape_list=[(8, 8)] asks for anchors that correspond to an 8x8 layer. For this anchor generator, only lists of length 1 are allowed. Returns: boxes: a BoxList holding a collection of N anchor boxes Raises: ValueError: if feature_map_shape_list, box_specs_list do not have the same length. ValueError: if feature_map_shape_list does not consist of pairs of integers """ if not (isinstance(feature_map_shape_list, list) and len(feature_map_shape_list) == 1): raise ValueError('feature_map_shape_list must be a list of length 1.') if not all([isinstance(list_item, tuple) and len(list_item) == 2 for list_item in feature_map_shape_list]): raise ValueError('feature_map_shape_list must be a list of pairs.') grid_height, grid_width = feature_map_shape_list[0] scales_grid, aspect_ratios_grid = ops.meshgrid(self._scales, self._aspect_ratios) scales_grid = tf.reshape(scales_grid, [-1]) aspect_ratios_grid = tf.reshape(aspect_ratios_grid, [-1]) return tile_anchors(grid_height, grid_width, scales_grid, aspect_ratios_grid, self._base_anchor_size, self._anchor_stride, self._anchor_offset)
Example #30
Source File: square_box_coder_test.py From DOTA_models with Apache License 2.0 | 5 votes |
def test_correct_boxes_with_non_default_scale(self): anchors = [[15.0, 12.0, 30.0, 18.0], [0.1, 0.0, 0.7, 0.9]] rel_codes = [[-1., -1.25, -1.62186], [-0.166667, -0.666667, -2.772588]] scale_factors = [2, 3, 4] expected_boxes = [[14.594306, 7.884875, 20.918861, 14.209432], [0.155051, 0.102989, 0.522474, 0.470412]] anchors = box_list.BoxList(tf.constant(anchors)) coder = square_box_coder.SquareBoxCoder(scale_factors=scale_factors) boxes = coder.decode(rel_codes, anchors) with self.test_session() as sess: (boxes_out,) = sess.run([boxes.get()]) self.assertAllClose(boxes_out, expected_boxes)