GIoU Loss


GIoULoss class

keras_cv.losses.GIoULoss(bounding_box_format, axis=-1, **kwargs)

Implements the Generalized IoU Loss

GIoU loss is a modified IoU loss commonly used for object detection. This loss aims to directly optimize the IoU score between true boxes and predicted boxes. GIoU loss adds a penalty term to the IoU loss that takes in account the area of the smallest box enclosing both the boxes being considered for the iou. The length of the last dimension should be 4 to represent the bounding boxes.


  • bounding_box_format: a case-insensitive string (for example, "xyxy"). Each bounding box is defined by these 4 values.For detailed information on the supported formats, see the KerasCV bounding box documentation.
  • axis: the axis along which to mean the ious, defaults to -1.


Sample Usage:

y_true = np.random.uniform(size=(5, 10, 5), low=0, high=10)
y_pred = np.random.uniform(size=(5, 10, 4), low=0, high=10)
loss = GIoULoss(bounding_box_format = "xyWH")
loss(y_true, y_pred).numpy()

Usage with the compile() API:

model.compile(optimizer='adam', loss=keras_cv.losses.GIoULoss())