Deep Patel commited on
Commit
c72270c
1 Parent(s): afa5cfb

Init tensor directly on device (#6068)

Browse files

Slightly more efficient than .to(device)

Files changed (1) hide show
  1. models/yolo.py +2 -2
models/yolo.py CHANGED
@@ -72,9 +72,9 @@ class Detect(nn.Module):
72
  def _make_grid(self, nx=20, ny=20, i=0):
73
  d = self.anchors[i].device
74
  if check_version(torch.__version__, '1.10.0'): # torch>=1.10.0 meshgrid workaround for torch>=0.7 compatibility
75
- yv, xv = torch.meshgrid([torch.arange(ny).to(d), torch.arange(nx).to(d)], indexing='ij')
76
  else:
77
- yv, xv = torch.meshgrid([torch.arange(ny).to(d), torch.arange(nx).to(d)])
78
  grid = torch.stack((xv, yv), 2).expand((1, self.na, ny, nx, 2)).float()
79
  anchor_grid = (self.anchors[i].clone() * self.stride[i]) \
80
  .view((1, self.na, 1, 1, 2)).expand((1, self.na, ny, nx, 2)).float()
 
72
  def _make_grid(self, nx=20, ny=20, i=0):
73
  d = self.anchors[i].device
74
  if check_version(torch.__version__, '1.10.0'): # torch>=1.10.0 meshgrid workaround for torch>=0.7 compatibility
75
+ yv, xv = torch.meshgrid([torch.arange(ny, device=d), torch.arange(nx, device=d)], indexing='ij')
76
  else:
77
+ yv, xv = torch.meshgrid([torch.arange(ny, device=d), torch.arange(nx, device=d)])
78
  grid = torch.stack((xv, yv), 2).expand((1, self.na, ny, nx, 2)).float()
79
  anchor_grid = (self.anchors[i].clone() * self.stride[i]) \
80
  .view((1, self.na, 1, 1, 2)).expand((1, self.na, ny, nx, 2)).float()