コード例 #1
0
ファイル: inputs.py プロジェクト: jiapei100/TensorflowModels
def assert_or_prune_invalid_boxes(boxes):
    """Makes sure boxes have valid sizes (ymax >= ymin, xmax >= xmin).

  When the hardware supports assertions, the function raises an error when
  boxes have an invalid size. If assertions are not supported (e.g. on TPU),
  boxes with invalid sizes are filtered out.

  Args:
    boxes: float tensor of shape [num_boxes, 4]

  Returns:
    boxes: float tensor of shape [num_valid_boxes, 4] with invalid boxes
      filtered out.

  Raises:
    tf.errors.InvalidArgumentError: When we detect boxes with invalid size.
      This is not supported on TPUs.
  """

    ymin, xmin, ymax, xmax = tf.split(boxes, num_or_size_splits=4, axis=1)

    height_check = tf.Assert(tf.reduce_all(ymax >= ymin), [ymin, ymax])
    width_check = tf.Assert(tf.reduce_all(xmax >= xmin), [xmin, xmax])

    with tf.control_dependencies([height_check, width_check]):
        boxes_tensor = tf.concat([ymin, xmin, ymax, xmax], axis=1)
        boxlist = box_list.BoxList(boxes_tensor)
        # TODO(b/149221748) Remove pruning when XLA supports assertions.
        boxlist = box_list_ops.prune_small_boxes(boxlist, 0)

    return boxlist.get()
コード例 #2
0
 def graph_fn():
   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]])
   boxes = box_list.BoxList(boxes)
   pruned_boxes = box_list_ops.prune_small_boxes(boxes, 3)
   return pruned_boxes.get()
コード例 #3
0
 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)
コード例 #4
0
 def graph_fn():
   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
   boxes = box_list.BoxList(boxes)
   pruned_boxes = box_list_ops.prune_small_boxes(boxes, 3)
   return pruned_boxes.get()
コード例 #5
0
 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)
コード例 #6
0
 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)
コード例 #7
0
 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)