Skip to content

Commit

Permalink
apply anchor transformations beforehand to make inference slightly fa…
Browse files Browse the repository at this point in the history
…ster
  • Loading branch information
zylo117 committed Jun 3, 2020
1 parent 42c0bcd commit 494e02f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions efficientdet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def forward(self, anchors, regression):
Returns:
"""
y_centers_a = (anchors[..., 0] + anchors[..., 2]) / 2
x_centers_a = (anchors[..., 1] + anchors[..., 3]) / 2
ha = anchors[..., 2] - anchors[..., 0]
wa = anchors[..., 3] - anchors[..., 1]
x_centers_a = anchors[..., 0]
y_centers_a = anchors[..., 1]
wa = anchors[..., 2]
ha = anchors[..., 3]

w = regression[..., 3].exp() * wa
h = regression[..., 2].exp() * ha
Expand Down Expand Up @@ -130,6 +130,14 @@ def forward(self, image, dtype=torch.float32):
anchor_boxes = np.vstack(boxes_all)

anchor_boxes = torch.from_numpy(anchor_boxes.astype(dtype)).to(image.device)

# transform
y_centers_a = (anchor_boxes[..., 0] + anchor_boxes[..., 2]) / 2
x_centers_a = (anchor_boxes[..., 1] + anchor_boxes[..., 3]) / 2
ha = anchor_boxes[..., 2] - anchor_boxes[..., 0]
wa = anchor_boxes[..., 3] - anchor_boxes[..., 1]

anchor_boxes = torch.stack([x_centers_a, y_centers_a, wa, ha], 1)
anchor_boxes = anchor_boxes.unsqueeze(0)

# save it for later use to reduce overhead
Expand Down

0 comments on commit 494e02f

Please sign in to comment.