| 170 | |
| 171 | |
| 172 | class PVCNN2Base(nn.Module): |
| 173 | |
| 174 | def __init__(self, num_classes, embed_dim, use_att, dropout=0.1, |
| 175 | extra_feature_channels=3, width_multiplier=1, voxel_resolution_multiplier=1): |
| 176 | super().__init__() |
| 177 | assert extra_feature_channels >= 0 |
| 178 | self.embed_dim = embed_dim |
| 179 | self.in_channels = extra_feature_channels + 3 |
| 180 | |
| 181 | sa_layers, sa_in_channels, channels_sa_features, _ = create_pointnet2_sa_components( |
| 182 | sa_blocks=self.sa_blocks, extra_feature_channels=extra_feature_channels, with_se=True, embed_dim=embed_dim, |
| 183 | use_att=use_att, dropout=dropout, |
| 184 | width_multiplier=width_multiplier, voxel_resolution_multiplier=voxel_resolution_multiplier |
| 185 | ) |
| 186 | self.sa_layers = nn.ModuleList(sa_layers) |
| 187 | |
| 188 | self.global_att = None if not use_att else Attention(channels_sa_features, 8, D=1) |
| 189 | |
| 190 | # only use extra features in the last fp module |
| 191 | sa_in_channels[0] = extra_feature_channels |
| 192 | fp_layers, channels_fp_features = create_pointnet2_fp_modules( |
| 193 | fp_blocks=self.fp_blocks, in_channels=channels_sa_features, sa_in_channels=sa_in_channels, with_se=True, embed_dim=embed_dim, |
| 194 | use_att=use_att, dropout=dropout, |
| 195 | width_multiplier=width_multiplier, voxel_resolution_multiplier=voxel_resolution_multiplier |
| 196 | ) |
| 197 | self.fp_layers = nn.ModuleList(fp_layers) |
| 198 | |
| 199 | |
| 200 | layers, _ = create_mlp_components(in_channels=channels_fp_features, out_channels=[128, dropout, num_classes], # was 0.5 |
| 201 | classifier=True, dim=2, width_multiplier=width_multiplier) |
| 202 | self.classifier = nn.Sequential(*layers) |
| 203 | |
| 204 | self.embedf = nn.Sequential( |
| 205 | nn.Linear(embed_dim, embed_dim), |
| 206 | nn.LeakyReLU(0.1, inplace=True), |
| 207 | nn.Linear(embed_dim, embed_dim), |
| 208 | ) |
| 209 | |
| 210 | def get_timestep_embedding(self, timesteps, device): |
| 211 | assert len(timesteps.shape) == 1 # and timesteps.dtype == tf.int32 |
| 212 | |
| 213 | half_dim = self.embed_dim // 2 |
| 214 | emb = np.log(10000) / (half_dim - 1) |
| 215 | emb = torch.from_numpy(np.exp(np.arange(0, half_dim) * -emb)).float().to(device) |
| 216 | # emb = tf.range(num_embeddings, dtype=DEFAULT_DTYPE)[:, None] * emb[None, :] |
| 217 | emb = timesteps[:, None] * emb[None, :] |
| 218 | emb = torch.cat([torch.sin(emb), torch.cos(emb)], dim=1) |
| 219 | if self.embed_dim % 2 == 1: # zero pad |
| 220 | # emb = tf.concat([emb, tf.zeros([num_embeddings, 1])], axis=1) |
| 221 | emb = nn.functional.pad(emb, (0, 1), "constant", 0) |
| 222 | assert emb.shape == torch.Size([timesteps.shape[0], self.embed_dim]) |
| 223 | return emb |
| 224 | |
| 225 | def forward(self, inputs, t): |
| 226 | |
| 227 | temb = self.embedf(self.get_timestep_embedding(t, inputs.device))[:,:,None].expand(-1,-1,inputs.shape[-1]) |
| 228 | import pdb |
| 229 | pdb.set_trace() |
nothing calls this directly
no outgoing calls
no test coverage detected