inet.losses package

Submodules

inet.losses.giou_loss module

Wrapper implementation for GIoU-Loss.

Fork of tensorflow_addons.losses.giou_loss https://github.com/tensorflow/addons/blob/b2dafcfa74c5de268b8a5c53813bc0b89cadf386/tensorflow_addons/losses/giou_loss.py

Forked to bypass version issue with TF 2.4 and unavailable package tensorflow_addons.

class GIoULoss(mode: str = 'giou', reduction: str = 'auto', name: Optional[str] = 'giou_loss')[source]

Bases: inet.losses.giou_loss.LossFunctionWrapper

GIoULoss as class instance

class LossFunctionWrapper(fn, reduction='auto', name=None, **kwargs)[source]

Bases: keras.losses.Loss

Wraps a loss function in the Loss class.

call(y_true, y_pred)[source]

Invokes the LossFunctionWrapper instance.

Args:

y_true: Ground truth values. y_pred: The predicted values.

Returns:

Loss values per sample.

get_config()[source]

Configuration getter for LossWrapper

convert_values(data) tensorflow.python.framework.ops.Tensor[source]

converts values of shape [y, x, h, w] into [y_min, x_min, y_max, x_max]

Parameters

data – bounding box coordinates

Returns

converted bounding box coordinates

giou_loss(bb1, bb2, mode: str = 'giou') tensorflow.python.framework.ops.Tensor[source]

fork of tensorflow_addons.losses.giou_loss.giou_loss internally converts [y, x, h, w] -> [y_min, x_min, y_max, x_max]

Parameters
  • bb1 – ground truth bounding box

  • bb2 – predicted bounding box

  • mode – Mode to use, either ‘giou’ (default) or ‘iou’

Returns

computed giou-loss

tf_giou_loss(y_true, y_pred, mode: str = 'giou') tensorflow.python.framework.ops.Tensor[source]

Implements the GIoU loss function.

GIoU loss was first introduced in the [Generalized Intersection over Union: A Metric and A Loss for Bounding Box Regression] (https://giou.stanford.edu/GIoU.pdf). GIoU is an enhancement for models which use IoU in object detection.

Parameters
  • y_true – true targets tensor. The coordinates of the each bounding box in boxes are encoded as [y_min, x_min, y_max, x_max].

  • y_pred – predictions tensor. The coordinates of the each bounding box in boxes are encoded as [y_min, x_min, y_max, x_max].

  • mode – one of [‘giou’, ‘iou’], decided to calculate GIoU or IoU loss.

Returns

GIoU loss float Tensor.