You need to sign in or sign up before continuing.
Unverified Commit 388b19c8 authored by Camilo De La Torre's avatar Camilo De La Torre Committed by GitHub
Browse files

Explicitely store a distance value that is reused (#4341)



* Explicitely store a distance value that is reused 

I don't see a reason to calculate the value twice for each distance. 

Knowing that this code is going to be called at every epoch and that probably there is not a compiler that optimizes this (+ also code clarity), I think is best to store the value for x and y.

* Update torchvision/models/detection/_utils.py
Co-authored-by: default avatarNicolas Hug <contact@nicolas-hug.com>

* removing spaces
Co-authored-by: default avatarNicolas Hug <contact@nicolas-hug.com>
Co-authored-by: default avatarVasilis Vryniotis <datumbox@users.noreply.github.com>
parent 57725901
...@@ -216,10 +216,14 @@ class BoxCoder(object): ...@@ -216,10 +216,14 @@ class BoxCoder(object):
pred_w = torch.exp(dw) * widths[:, None] pred_w = torch.exp(dw) * widths[:, None]
pred_h = torch.exp(dh) * heights[:, None] pred_h = torch.exp(dh) * heights[:, None]
pred_boxes1 = pred_ctr_x - torch.tensor(0.5, dtype=pred_ctr_x.dtype, device=pred_w.device) * pred_w # Distance from center to box's corner.
pred_boxes2 = pred_ctr_y - torch.tensor(0.5, dtype=pred_ctr_y.dtype, device=pred_h.device) * pred_h c_to_c_h = torch.tensor(0.5, dtype=pred_ctr_y.dtype, device=pred_h.device) * pred_h
pred_boxes3 = pred_ctr_x + torch.tensor(0.5, dtype=pred_ctr_x.dtype, device=pred_w.device) * pred_w c_to_c_w = torch.tensor(0.5, dtype=pred_ctr_x.dtype, device=pred_w.device) * pred_w
pred_boxes4 = pred_ctr_y + torch.tensor(0.5, dtype=pred_ctr_y.dtype, device=pred_h.device) * pred_h
pred_boxes1 = pred_ctr_x - c_to_c_w
pred_boxes2 = pred_ctr_y - c_to_c_h
pred_boxes3 = pred_ctr_x + c_to_c_w
pred_boxes4 = pred_ctr_y + c_to_c_h
pred_boxes = torch.stack((pred_boxes1, pred_boxes2, pred_boxes3, pred_boxes4), dim=2).flatten(1) pred_boxes = torch.stack((pred_boxes1, pred_boxes2, pred_boxes3, pred_boxes4), dim=2).flatten(1)
return pred_boxes return pred_boxes
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment