U uPh @sTddlmZddlZddlmZddlmZmZddlm Z GdddeZ e Z dS)) annotationsN)_Loss) COMPUTE_DTYPE box_pair_giou) LossReductioncs@eZdZdZejfdddfdd Zddddd d ZZS) BoxGIoULossa\ Compute the generalized intersection over union (GIoU) loss of a pair of boxes. The two inputs should have the same shape. giou_loss = 1.0 - giou The range of GIoU is (-1.0, 1.0]. Thus the range of GIoU loss is [0.0, 2.0). Args: reduction: {``"none"``, ``"mean"``, ``"sum"``} Specifies the reduction to apply to the output. Defaults to ``"mean"``. - ``"none"``: no reduction will be applied. - ``"mean"``: the sum of the output will be divided by the number of elements in the output. - ``"sum"``: the output will be summed. zLossReduction | strNone) reductionreturncstjt|jddS)N)r )super__init__rvalue)selfr  __class__K/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/losses/giou_loss.pyr $szBoxGIoULoss.__init__z torch.Tensor)inputtargetr cCs|j|jkr&td|jd|jd|j}t|jtd|jtd}d|}|jtjj krf| }n:|jtj j kr~| }n"|jtj j krntd|jd||S)aN Args: input: predicted bounding boxes, Nx4 or Nx6 torch tensor. The box mode is assumed to be ``StandardMode`` target: GT bounding boxes, Nx4 or Nx6 torch tensor. The box mode is assumed to be ``StandardMode`` Raises: ValueError: When the two inputs have different shape. z"ground truth has different shape (z) from input ())dtypeg?zUnsupported reduction: z0, available options are ["mean", "sum", "none"].)shape ValueErrorrrtorr rMEANr meanSUMsumNONE)rrr box_dtypegioulossrrrforward's    zBoxGIoULoss.forward) __name__ __module__ __qualname____doc__rrr r" __classcell__rrrrrsr) __future__rtorchtorch.nn.modules.lossrZmonai.data.box_utilsrr monai.utilsrrr rrrr s   .