ZrrSkywalker / Point-NN

[CVPR 2023] Parameter is Not All You Need: Starting from Non-Parametric Networks for 3D Point Cloud Analysis
MIT License
477 stars 50 forks source link

why this simple code can obtain the mean of xyz? #7

Open black-prince222 opened 1 year ago

black-prince222 commented 1 year ago

`class LGA(nn.Module): def init(self, out_dim, alpha, beta): super().init() self.geo_extract = PosE_Geo(3, out_dim, alpha, beta)

def forward(self, lc_xyz, lc_x, knn_xyz, knn_x):

    # Normalize x (features) and xyz (coordinates)
    mean_x = lc_x.unsqueeze(dim=-2)
    std_x = torch.std(knn_x - mean_x)

    mean_xyz = lc_xyz.unsqueeze(dim=-2)
    std_xyz = torch.std(knn_xyz - mean_xyz)

    knn_x = (knn_x - mean_x) / (std_x + 1e-5)
    knn_xyz = (knn_xyz - mean_xyz) / (std_xyz + 1e-5)

    # Feature Expansion
    B, G, K, C = knn_x.shape
    knn_x = torch.cat([knn_x, lc_x.reshape(B, G, 1, -1).repeat(1, 1, K, 1)], dim=-1)

    # Geometry Extraction
    knn_xyz = knn_xyz.permute(0, 3, 1, 2)
    knn_x = knn_x.permute(0, 3, 1, 2)
    knn_x_w = self.geo_extract(knn_xyz, knn_x)

    return knn_x_w`

why the code mean_x = lc_x.unsqueeze(dim=-2) can obtain the mean of lc_x?

ZrrSkywalker commented 1 year ago

Here we define the average coordinate/feature of a k-nn group by the coordinate/feature of the corresponding local center. Thus, mean_xyz and mean_x are equivalent to lc_xyz and lc_x.

black-prince222 commented 1 year ago

Here we define the average coordinate/feature of a k-nn group by the coordinate/feature of the corresponding local center. Thus, mean_xyz and mean_x are equivalent to lc_xyz and lc_x.

thanks, i get it.