This performs the loss computation. Parameters: outputs: dict of tensors, see the output specification of the model for the format targets: list of dicts, such that len(targets) == batch_size. The expected keys in each dict depends on the loss
(self, outputs, targets, data_batch, return_indices=False)
| 1700 | |
| 1701 | |
| 1702 | def forward(self, outputs, targets, data_batch, return_indices=False): |
| 1703 | """ This performs the loss computation. |
| 1704 | Parameters: |
| 1705 | outputs: dict of tensors, see the output specification of the model for the format |
| 1706 | targets: list of dicts, such that len(targets) == batch_size. |
| 1707 | The expected keys in each dict depends on the losses applied, see each loss' doc |
| 1708 | |
| 1709 | return_indices: used for vis. if True, the layer0-5 indices will be returned as well. |
| 1710 | |
| 1711 | """ |
| 1712 | # import pdb; pdb.set_trace() |
| 1713 | outputs_without_aux = { |
| 1714 | k: v |
| 1715 | for k, v in outputs.items() if k != 'aux_outputs' |
| 1716 | } |
| 1717 | device = next(iter(outputs.values())).device |
| 1718 | |
| 1719 | # Compute the average number of target boxes accross all nodes, for normalization purposes |
| 1720 | num_boxes = sum(len(t['boxes']) for t in targets) |
| 1721 | num_boxes = torch.as_tensor([num_boxes], |
| 1722 | dtype=torch.float, |
| 1723 | device=device) |
| 1724 | if is_dist_avail_and_initialized(): |
| 1725 | torch.distributed.all_reduce(num_boxes) |
| 1726 | num_boxes = torch.clamp(num_boxes / get_world_size(), min=1).item() |
| 1727 | |
| 1728 | # loss for final layer |
| 1729 | # pdb.set_trace() |
| 1730 | indices = self.matcher(outputs_without_aux, targets) |
| 1731 | if return_indices: |
| 1732 | indices0_copy = indices |
| 1733 | indices_list = [] |
| 1734 | losses = {} |
| 1735 | smpl_loss = ['smpl_pose', 'smpl_beta', 'smpl_expr', 'smpl_kp2d', |
| 1736 | 'smpl_kp3d', 'smpl_kp3d_ra'] |
| 1737 | # import pdb; pdb.set_trace() |
| 1738 | for loss in self.losses: |
| 1739 | # print(loss) |
| 1740 | # print(self.get_loss(loss, outputs, targets, indices, num_boxes)) |
| 1741 | kwargs = {} |
| 1742 | |
| 1743 | if loss == 'keypoints' or loss in smpl_loss: |
| 1744 | kwargs.update({'face_hand_kpt': True}) |
| 1745 | if loss == 'boxes': |
| 1746 | kwargs.update({'face_hand_box': True}) |
| 1747 | |
| 1748 | losses.update( |
| 1749 | self.get_loss( |
| 1750 | loss, outputs, targets, |
| 1751 | data_batch, indices, |
| 1752 | num_boxes, **kwargs |
| 1753 | )) |
| 1754 | |
| 1755 | # In case of auxiliary losses, we repeat this process with the output of each intermediate layer. |
| 1756 | if 'aux_outputs' in outputs: |
| 1757 | for idx, aux_outputs in enumerate(outputs['aux_outputs']): |
| 1758 | indices = self.matcher(aux_outputs, targets) |
| 1759 | if return_indices: |
nothing calls this directly
no test coverage detected