Skip to content

Commit aac9dd5

Browse files
authored
Merge pull request #113 from magehrig/device-optim
Create tensors on device
2 parents 2243205 + 0d123fd commit aac9dd5

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

core/corr.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def __call__(self, coords):
3434
out_pyramid = []
3535
for i in range(self.num_levels):
3636
corr = self.corr_pyramid[i]
37-
dx = torch.linspace(-r, r, 2*r+1)
38-
dy = torch.linspace(-r, r, 2*r+1)
39-
delta = torch.stack(torch.meshgrid(dy, dx), axis=-1).to(coords.device)
37+
dx = torch.linspace(-r, r, 2*r+1, device=coords.device)
38+
dy = torch.linspace(-r, r, 2*r+1, device=coords.device)
39+
delta = torch.stack(torch.meshgrid(dy, dx), axis=-1)
4040

4141
centroid_lvl = coords.reshape(batch*h1*w1, 1, 1, 2) / 2**i
4242
delta_lvl = delta.view(1, 2*r+1, 2*r+1, 2)

core/raft.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ def freeze_bn(self):
6363
def initialize_flow(self, img):
6464
""" Flow is represented as difference between two coordinate grids flow = coords1 - coords0"""
6565
N, C, H, W = img.shape
66-
coords0 = coords_grid(N, H//8, W//8).to(img.device)
67-
coords1 = coords_grid(N, H//8, W//8).to(img.device)
66+
coords0 = coords_grid(N, H//8, W//8, device=img.device)
67+
coords1 = coords_grid(N, H//8, W//8, device=img.device)
6868

6969
# optical flow computed as difference: flow = coords1 - coords0
7070
return coords0, coords1

core/utils/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def bilinear_sampler(img, coords, mode='bilinear', mask=False):
7171
return img
7272

7373

74-
def coords_grid(batch, ht, wd):
75-
coords = torch.meshgrid(torch.arange(ht), torch.arange(wd))
74+
def coords_grid(batch, ht, wd, device):
75+
coords = torch.meshgrid(torch.arange(ht, device=device), torch.arange(wd, device=device))
7676
coords = torch.stack(coords[::-1], dim=0).float()
7777
return coords[None].repeat(batch, 1, 1, 1)
7878

0 commit comments

Comments
 (0)