def METHOD_NAME(self):
    """Tests tood head loss when truth is empty and non-empty."""
    s = 256
    img_metas = [{
        'img_shape': (s, s, 3),
        'pad_shape': (s, s, 3),
        'scale_factor': 1
    }]
    tood_head = _tood_head('anchor_free')
    tood_head.init_weights()
    feat = [
        torch.rand(1, 1, s // feat_size, s // feat_size)
        for feat_size in [8, 16, 32, 64, 128]
    ]
    cls_scores, bbox_preds = tood_head(feat)
    message_hub = MessageHub.get_instance('runtime_info')
    message_hub.update_info('epoch', 0)
    # Test that empty ground truth encourages the network to predict
    # background
    gt_instances = InstanceData()
    gt_instances.bboxes = torch.empty((0, 4))
    gt_instances.labels = torch.LongTensor([])
    gt_bboxes_ignore = None
    empty_gt_losses = tood_head.loss_by_feat(cls_scores, bbox_preds,
                                             [gt_instances], img_metas,
                                             gt_bboxes_ignore)
    # When there is no truth, the cls loss should be nonzero but there
    # should be no box loss.
    empty_cls_loss = empty_gt_losses['loss_cls']
    empty_box_loss = empty_gt_losses['loss_bbox']
    self.assertGreater(
        sum(empty_cls_loss).item(), 0, 'cls loss should be non-zero')
    self.assertEqual(
        sum(empty_box_loss).item(), 0,
        'there should be no box loss when there are no true boxes')
    # When truth is non-empty then both cls and box loss should be nonzero
    # for random inputs
    gt_instances = InstanceData()
    gt_instances.bboxes = torch.Tensor(
        [[23.6667, 23.8757, 238.6326, 151.8874]])
    gt_instances.labels = torch.LongTensor([2])
    gt_bboxes_ignore = None
    one_gt_losses = tood_head.loss_by_feat(cls_scores, bbox_preds,
                                           [gt_instances], img_metas,
                                           gt_bboxes_ignore)
    onegt_cls_loss = one_gt_losses['loss_cls']
    onegt_box_loss = one_gt_losses['loss_bbox']
    self.assertGreater(
        sum(onegt_cls_loss).item(), 0, 'cls loss should be non-zero')
    self.assertGreater(
        sum(onegt_box_loss).item(), 0, 'box loss should be non-zero')
    # Test that empty ground truth encourages the network to predict
    # background
    gt_instances = InstanceData()
    gt_instances.bboxes = torch.empty((0, 4))
    gt_instances.labels = torch.LongTensor([])
    gt_bboxes_ignore = None
    empty_gt_losses = tood_head.loss_by_feat(cls_scores, bbox_preds,
                                             [gt_instances], img_metas,
                                             gt_bboxes_ignore)
    # When there is no truth, the cls loss should be nonzero but there
    # should be no box loss.
    empty_cls_loss = empty_gt_losses['loss_cls']
    empty_box_loss = empty_gt_losses['loss_bbox']
    self.assertGreater(
        sum(empty_cls_loss).item(), 0, 'cls loss should be non-zero')
    self.assertEqual(
        sum(empty_box_loss).item(), 0,
        'there should be no box loss when there are no true boxes')
    # When truth is non-empty then both cls and box loss should be nonzero
    # for random inputs
    gt_instances = InstanceData()
    gt_instances.bboxes = torch.Tensor(
        [[23.6667, 23.8757, 238.6326, 151.8874]])
    gt_instances.labels = torch.LongTensor([2])
    gt_bboxes_ignore = None
    one_gt_losses = tood_head.loss_by_feat(cls_scores, bbox_preds,
                                           [gt_instances], img_metas,
                                           gt_bboxes_ignore)
    onegt_cls_loss = one_gt_losses['loss_cls']
    onegt_box_loss = one_gt_losses['loss_bbox']
    self.assertGreater(
        sum(onegt_cls_loss).item(), 0, 'cls loss should be non-zero')
    self.assertGreater(
        sum(onegt_box_loss).item(), 0, 'box loss should be non-zero')