Decode locations from predictions using priors to undo the encoding we did for offset regression at train time. Args: loc (tensor): location predictions for loc layers, Shape: [num_priors,4] priors (tensor): Prior boxes in center-offset form. Shape: [n
(loc, priors, variances)
| 138 | |
| 139 | # Adapted from https://github.com/Hakuyume/chainer-ssd |
| 140 | def decode(loc, priors, variances): |
| 141 | """Decode locations from predictions using priors to undo |
| 142 | the encoding we did for offset regression at train time. |
| 143 | Args: |
| 144 | loc (tensor): location predictions for loc layers, |
| 145 | Shape: [num_priors,4] |
| 146 | priors (tensor): Prior boxes in center-offset form. |
| 147 | Shape: [num_priors,4]. |
| 148 | variances: (list[float]) Variances of priorboxes |
| 149 | Return: |
| 150 | decoded bounding box predictions |
| 151 | """ |
| 152 | |
| 153 | boxes = torch.cat(( |
| 154 | priors[:, :2] + loc[:, :2] * variances[0] * priors[:, 2:], |
| 155 | priors[:, 2:] * torch.exp(loc[:, 2:] * variances[1])), 1) |
| 156 | boxes[:, :2] -= boxes[:, 2:] / 2 |
| 157 | boxes[:, 2:] += boxes[:, :2] |
| 158 | return boxes |
| 159 | |
| 160 | |
| 161 | def log_sum_exp(x): |