Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusion about NetVLAD and PointNetVLAD #7

Open
where2go947 opened this issue Oct 22, 2022 · 0 comments
Open

Confusion about NetVLAD and PointNetVLAD #7

where2go947 opened this issue Oct 22, 2022 · 0 comments

Comments

@where2go947
Copy link

Hi, thanks for your Pytorch implementation of PointNetVLAD.
I'm a new learner. When I read the code, I'm confused at PointNetVLAD:

def forward(self, x):
x = x.transpose(1, 3).contiguous()
x = x.view((-1, self.max_samples, self.feature_size))
activation = torch.matmul(x, self.cluster_weights)
if self.add_batch_norm:
# activation = activation.transpose(1,2).contiguous()
activation = activation.view(-1, self.cluster_size)
activation = self.bn1(activation)
activation = activation.view(-1,
self.max_samples, self.cluster_size)
# activation = activation.transpose(1,2).contiguous()
else:
activation = activation + self.cluster_biases
activation = self.softmax(activation)
activation = activation.view((-1, self.max_samples, self.cluster_size))
a_sum = activation.sum(-2, keepdim=True)
a = a_sum * self.cluster_weights2
activation = torch.transpose(activation, 2, 1)
x = x.view((-1, self.max_samples, self.feature_size))
vlad = torch.matmul(activation, x)
vlad = torch.transpose(vlad, 2, 1)
vlad = vlad - a
vlad = F.normalize(vlad, dim=1, p=2)
vlad = vlad.view((-1, self.cluster_size * self.feature_size))
vlad = F.normalize(vlad, dim=1, p=2)
vlad = torch.matmul(vlad, self.hidden1_weights)
vlad = self.bn2(vlad)
if self.gating:
vlad = self.context_gating(vlad)
return vlad

According to my view:

  • activation at line 59 represents the distribution of each point n belonging to the cluster k. (the weight)
  • a at line 62 represents the learned cluster
  • But what vlad at line 68 means? Where is the residuals and the sum of them according to points n?

Why not the following:

def forward(self, x):
        x = x.transpose(1, 3).contiguous()
        x = x.view((-1, self.max_samples, self.feature_size)) # [B,N,C]
        activation = torch.matmul(x, self.cluster_weights)
        if self.add_batch_norm:
            # activation = activation.transpose(1,2).contiguous()
            activation = activation.view(-1, self.cluster_size)
            activation = self.bn1(activation)
            activation = activation.view(-1,
                                         self.max_samples, self.cluster_size)
            # activation = activation.transpose(1,2).contiguous()
        else:
            activation = activation + self.cluster_biases
        activation = self.softmax(activation)
        activation = activation.view((-1, self.max_samples, self.cluster_size))
        
        a_sum = activation.sum(-2, keepdim=True)
        a = a_sum * self.cluster_weights2 # [B,C,k]
        
       ### ----------------- different-------------------
        N = x.shape[1]
        residual = x.unsqueeze(-1).repeat(1,1,1,self.cluster_size) - \
                          a.unsqueeze(1).repeat(1,N,1,1)  # [B,C,N,k]
        vlad = activation.unsqueeze(2) * residual
        vlad = torch.sum(vlad, dim=1) # [B,C,k]
       ### ----------------- different-------------------

        # intra-normalization and L2 normalize
        vlad = F.normalize(vlad, dim=1, p=2)    
        vlad = vlad.reshape((-1, self.cluster_size*self.feature_size))
        vlad = F.normalize(vlad, dim=1, p=2)

        # compress into a compact output
        vlad = torch.matmul(vlad, self.hidden1_weights)
        vlad = self.bn2(vlad)

        if self.gating:
            vlad = self.context_gating(vlad)

        return vlad

Is there anything wrong with my understanding?
Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant