CrossEntropyIoULoss2D is a combination of the Generalized Intersection over Union and Cross-Entropy losses. In simple words, it is the average of the outputs of these two losses. As of today, none of the Deep Learning frameworks has a built-in CrossEntropyIoULoss2D, so it has to be implemented manually (you can use the code below as an example).
import torch
import torch.nn as nn
import torchvision.ops as ops
input = torch.randn(3, 5, requires_grad=True)
target = torch.empty(3, dtype=torch.long).random_(5)
cross_entropy_loss = nn.CrossEntropyLoss()
output_cross_entropy = cross_entropy_loss(input, target)
output_cross_entropy.backward()
input = torch.Tensor([[1, 1, 2, 2], [2, 2, 3, 3], [3, 3, 4, 4]])
target = torch.Tensor([[0, 0, 2, 2], [2, 2, 4, 4], [4, 4, 6, 6]])
generalized_iou_loss = ops.generalized_box_iou(input, target)
print('output: ', torch.cat([generalized_iou_loss.mean().view(1, 1),
output_cross_entropy.view(1,1)]).mean())
Accelerated Annotation.
Maximize model performance quickly with AI-powered labeling and 100% QA.
Learn more