-
Notifications
You must be signed in to change notification settings - Fork 3
/
create_pillars.py
33 lines (28 loc) · 1.28 KB
/
create_pillars.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import numpy as np
import pdb
import torch
import torch.nn as nn
import torch.nn.functional as F
from ops import Voxelization, nms_cuda
class PillarLayer(nn.Module):
def __init__(self, voxel_size, point_cloud_range, max_num_points, max_voxels):
super().__init__()
self.voxel_layer = Voxelization(voxel_size=voxel_size,
point_cloud_range=point_cloud_range,
max_num_points=max_num_points,
max_voxels=max_voxels)
@torch.no_grad()
def forward(self, batched_pts):
pillars, coors, npoints_per_pillar = [], [], []
for i, pts in enumerate(batched_pts):
voxels_out, coors_out, num_points_per_voxel_out = self.voxel_layer(pts)
pillars.append(voxels_out)
coors.append(coors_out.long())
npoints_per_pillar.append(num_points_per_voxel_out)
pillars = torch.cat(pillars, dim=0)
npoints_per_pillar = torch.cat(npoints_per_pillar, dim=0)
coors_batch = []
for i, cur_coors in enumerate(coors):
coors_batch.append(F.pad(cur_coors, (1, 0), value=i))
coors_batch = torch.cat(coors_batch, dim=0)
return pillars, coors_batch, npoints_per_pillar