본문 바로가기

Deep Learning

Pytorch에서 meshgrid 만들기

반응형
'''
x : forward direction
y : side (left) direction
'''


s, b, c, h, w = seq_z.size()

h_meters = self.cfg['bev']['h_meters']
w_meters = self.cfg['bev']['w_meters']

h_grid = torch.linspace(0, h_meters, h) - (h_meters / 2)
w_grid = torch.linspace(0, w_meters, w) - (w_meters / 2)

grid_x, grid_y = torch.meshgrid(torch.flip(h_grid, dims=(0,)), torch.flip(w_grid, dims=(0,)), indexing='ij')
grid = torch.stack((grid_x, grid_y), dim=0)
grid = F.pad(grid, (0, 0, 0, 0, 0, 1), value=1.0).unsqueeze(0) # b 3 h w