Forward function.
(output, target, target_weight)
| 71 | |
| 72 | |
| 73 | def myloss(output, target, target_weight): |
| 74 | """Forward function.""" |
| 75 | use_target_weight = True |
| 76 | batch_size = output.size(0) |
| 77 | num_joints = output.size(1) |
| 78 | |
| 79 | heatmaps_pred = output.reshape( |
| 80 | (batch_size, num_joints, -1)).split(1, 1) |
| 81 | heatmaps_gt = target.reshape((batch_size, num_joints, -1)).split(1, 1) |
| 82 | |
| 83 | loss = 0. |
| 84 | |
| 85 | for idx in range(num_joints): |
| 86 | heatmap_pred = heatmaps_pred[idx].squeeze(1) |
| 87 | heatmap_gt = heatmaps_gt[idx].squeeze(1) |
| 88 | if use_target_weight: |
| 89 | loss += criterion(heatmap_pred * target_weight[:, idx], |
| 90 | heatmap_gt * target_weight[:, idx]) |
| 91 | else: |
| 92 | loss += criterion(heatmap_pred, heatmap_gt) |
| 93 | |
| 94 | return loss / num_joints * 1.0 |
| 95 | |
| 96 | |
| 97 | def _get_max_preds(heatmaps): |