| 48 | |
| 49 | class PointNetSAModule(nn.Module): |
| 50 | def __init__(self, num_centers, radius, num_neighbors, in_channels, out_channels, include_coordinates=True): |
| 51 | super().__init__() |
| 52 | if not isinstance(radius, (list, tuple)): |
| 53 | radius = [radius] |
| 54 | if not isinstance(num_neighbors, (list, tuple)): |
| 55 | num_neighbors = [num_neighbors] * len(radius) |
| 56 | assert len(radius) == len(num_neighbors) |
| 57 | if not isinstance(out_channels, (list, tuple)): |
| 58 | out_channels = [[out_channels]] * len(radius) |
| 59 | elif not isinstance(out_channels[0], (list, tuple)): |
| 60 | out_channels = [out_channels] * len(radius) |
| 61 | assert len(radius) == len(out_channels) |
| 62 | |
| 63 | groupers, mlps = [], [] |
| 64 | total_out_channels = 0 |
| 65 | for _radius, _out_channels, _num_neighbors in zip(radius, out_channels, num_neighbors): |
| 66 | groupers.append( |
| 67 | BallQuery(radius=_radius, num_neighbors=_num_neighbors, include_coordinates=include_coordinates) |
| 68 | ) |
| 69 | mlps.append( |
| 70 | SharedMLP(in_channels=in_channels + (3 if include_coordinates else 0), |
| 71 | out_channels=_out_channels, dim=2) |
| 72 | ) |
| 73 | total_out_channels += _out_channels[-1] |
| 74 | |
| 75 | self.num_centers = num_centers |
| 76 | self.out_channels = total_out_channels |
| 77 | self.groupers = nn.ModuleList(groupers) |
| 78 | self.mlps = nn.ModuleList(mlps) |
| 79 | |
| 80 | def forward(self, inputs): |
| 81 | features, coords, temb = inputs |