MCPcopy Create free account
hub / github.com/openai/point-e / PointNetSetAbstractionMsg

Class PointNetSetAbstractionMsg

point_e/evals/pointnet2_utils.py:244–301  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

242
243
244class PointNetSetAbstractionMsg(nn.Module):
245 def __init__(self, npoint, radius_list, nsample_list, in_channel, mlp_list):
246 super(PointNetSetAbstractionMsg, self).__init__()
247 self.npoint = npoint
248 self.radius_list = radius_list
249 self.nsample_list = nsample_list
250 self.conv_blocks = nn.ModuleList()
251 self.bn_blocks = nn.ModuleList()
252 for i in range(len(mlp_list)):
253 convs = nn.ModuleList()
254 bns = nn.ModuleList()
255 last_channel = in_channel + 3
256 for out_channel in mlp_list[i]:
257 convs.append(nn.Conv2d(last_channel, out_channel, 1))
258 bns.append(nn.BatchNorm2d(out_channel))
259 last_channel = out_channel
260 self.conv_blocks.append(convs)
261 self.bn_blocks.append(bns)
262
263 def forward(self, xyz, points):
264 """
265 Input:
266 xyz: input points position data, [B, C, N]
267 points: input points data, [B, D, N]
268 Return:
269 new_xyz: sampled points position data, [B, C, S]
270 new_points_concat: sample points feature data, [B, D', S]
271 """
272 xyz = xyz.permute(0, 2, 1)
273 if points is not None:
274 points = points.permute(0, 2, 1)
275
276 B, N, C = xyz.shape
277 S = self.npoint
278 new_xyz = index_points(xyz, farthest_point_sample(xyz, S, deterministic=not self.training))
279 new_points_list = []
280 for i, radius in enumerate(self.radius_list):
281 K = self.nsample_list[i]
282 group_idx = query_ball_point(radius, K, xyz, new_xyz)
283 grouped_xyz = index_points(xyz, group_idx)
284 grouped_xyz -= new_xyz.view(B, S, 1, C)
285 if points is not None:
286 grouped_points = index_points(points, group_idx)
287 grouped_points = torch.cat([grouped_points, grouped_xyz], dim=-1)
288 else:
289 grouped_points = grouped_xyz
290
291 grouped_points = grouped_points.permute(0, 3, 2, 1) # [B, D, K, S]
292 for j in range(len(self.conv_blocks[i])):
293 conv = self.conv_blocks[i][j]
294 bn = self.bn_blocks[i][j]
295 grouped_points = F.relu(bn(conv(grouped_points)))
296 new_points = torch.max(grouped_points, 2)[0] # [B, D', S]
297 new_points_list.append(new_points)
298
299 new_xyz = new_xyz.permute(0, 2, 1)
300 new_points_concat = torch.cat(new_points_list, dim=1)
301 return new_xyz, new_points_concat

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected