Skip to content

Commit

Permalink
Fix variable naming error
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiqwang committed Oct 17, 2021
1 parent fab48d7 commit 261590f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions yolort/models/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def decode_single(
anchors_tupe (Tensor, Tensor, Tensor): reference boxes.
"""

pred_wh = (rel_codes[..., 0:2] * 2.0 + anchors_tuple[0]) * anchors_tuple[1] # wh
pred_xy = (rel_codes[..., 2:4] * 2) ** 2 * anchors_tuple[2] # xy
pred_boxes = torch.cat([pred_wh, pred_xy], dim=1)
pred_xy = (rel_codes[..., 0:2] * 2.0 + anchors_tuple[0]) * anchors_tuple[1] # xy
pred_wh = (rel_codes[..., 2:4] * 2) ** 2 * anchors_tuple[2] # wh
pred_boxes = torch.cat([pred_xy, pred_wh], dim=1)
pred_boxes = box_convert(pred_boxes, in_fmt="cxcywh", out_fmt="xyxy")

return pred_boxes
Expand Down
20 changes: 10 additions & 10 deletions yolort/models/anchor_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,43 @@ def __init__(
self.strides = strides
self.anchor_grids = anchor_grids

def set_wh_weights(
def set_xy_weights(
self,
grid_sizes: List[List[int]],
dtype: torch.dtype = torch.float32,
device: torch.device = torch.device("cpu"),
) -> Tensor:

wh_weights = []
xy_weights = []

for size, stride in zip(grid_sizes, self.strides):
grid_height, grid_width = size
stride = torch.as_tensor([stride], dtype=dtype, device=device)
stride = stride.view(-1, 1)
stride = stride.repeat(1, grid_height * grid_width * self.num_anchors)
stride = stride.reshape(-1, 1)
wh_weights.append(stride)
xy_weights.append(stride)

return torch.cat(wh_weights)
return torch.cat(xy_weights)

def set_xy_weights(
def set_wh_weights(
self,
grid_sizes: List[List[int]],
dtype: torch.dtype = torch.float32,
device: torch.device = torch.device("cpu"),
) -> Tensor:

xy_weights = []
wh_weights = []

for size, anchor_grid in zip(grid_sizes, self.anchor_grids):
grid_height, grid_width = size
anchor_grid = torch.as_tensor(anchor_grid, dtype=dtype, device=device)
anchor_grid = anchor_grid.view(-1, 2)
anchor_grid = anchor_grid.repeat(1, grid_height * grid_width)
anchor_grid = anchor_grid.reshape(-1, 2)
xy_weights.append(anchor_grid)
wh_weights.append(anchor_grid)

return torch.cat(xy_weights)
return torch.cat(wh_weights)

def grid_anchors(
self,
Expand Down Expand Up @@ -91,8 +91,8 @@ def forward(self, feature_maps: List[Tensor]) -> Tuple[Tensor, Tensor, Tensor]:
grid_sizes = list([feature_map.shape[-2:] for feature_map in feature_maps])
dtype, device = feature_maps[0].dtype, feature_maps[0].device

wh_weights = self.set_wh_weights(grid_sizes, dtype, device)
xy_weights = self.set_xy_weights(grid_sizes, dtype, device)
wh_weights = self.set_wh_weights(grid_sizes, dtype, device)
anchors = self.grid_anchors(grid_sizes, dtype, device)

return anchors, wh_weights, xy_weights
return anchors, xy_weights, wh_weights

0 comments on commit 261590f

Please sign in to comment.