StreamPETR
StreamPETR copied to clipboard
'pos2posemb3d' in positional_encoding.py
Is there any special design to transpose 'x' & 'y' dimentions ?
def pos2posemb3d(pos, num_pos_feats=128, temperature=10000):
scale = 2 * math.pi
dim_t = torch.arange(num_pos_feats//2, dtype=torch.float32, device=pos.device)
dim_t = temperature ** (2 * dim_t / num_pos_feats)
pos_x = pos[..., 0, None]* scale / dim_t
pos_y = pos[..., 1, None]* scale / dim_t
pos_z = pos[..., 2, None]* scale / dim_t
pos_x = torch.stack((pos_x.sin(), pos_x.cos()), dim=-1).flatten(-2)
pos_y = torch.stack((pos_y.sin(), pos_y.cos()), dim=-1).flatten(-2)
pos_z = torch.stack((pos_z.sin(), pos_z.cos()), dim=-1).flatten(-2)
posemb = torch.cat((pos_y, pos_x, pos_z), dim=-1)
return posemb