Esempio n. 1
0
 def box_iou(self, true_box, pred_box):
     # based on the type of loss, compute the iou loss for a box
     # compute_<name> indicated the type of iou to use
     if self.iou_type == 'giou':
         _, iou = box_ops.compute_giou(true_box, pred_box)
     elif self.iou_type == 'ciou':
         _, iou = box_ops.compute_ciou(true_box, pred_box)
     else:
         iou = box_ops.compute_iou(true_box, pred_box)
     return iou
Esempio n. 2
0
 def box_loss(self, true_box, pred_box, darknet=False):
   """Call iou function and use it to compute the loss for the box maps."""
   if self._loss_type == 'giou':
     iou, liou = box_ops.compute_giou(true_box, pred_box)
   elif self._loss_type == 'ciou':
     iou, liou = box_ops.compute_ciou(true_box, pred_box, darknet=darknet)
   else:
     liou = iou = box_ops.compute_iou(true_box, pred_box)
   loss_box = 1 - liou
   return iou, liou, loss_box
 def test_ious(self, num_boxes):
     boxes = tf.convert_to_tensor(np.random.rand(num_boxes, 4))
     expected_shape = np.array([
         num_boxes,
     ])
     expected_iou = np.ones([
         num_boxes,
     ])
     iou = box_ops.compute_iou(boxes, boxes)
     _, giou = box_ops.compute_giou(boxes, boxes)
     _, ciou = box_ops.compute_ciou(boxes, boxes)
     _, diou = box_ops.compute_diou(boxes, boxes)
     self.assertAllEqual(tf.shape(iou).numpy(), expected_shape)
     self.assertArrayNear(iou, expected_iou, 0.001)
     self.assertArrayNear(giou, expected_iou, 0.001)
     self.assertArrayNear(ciou, expected_iou, 0.001)
     self.assertArrayNear(diou, expected_iou, 0.001)