MCPcopy Create free account
hub / github.com/amdegroot/ssd.pytorch / decode

Function decode

layers/box_utils.py:140–158  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

138
139# Adapted from https://github.com/Hakuyume/chainer-ssd
140def 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
161def log_sum_exp(x):

Callers 1

forwardMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected