class_docstr: NetVLAD layer implementation.
  
  Args:
      num_clusters (`int`):
          The number of clusters.
      dim (`int`):
          Dimension of descriptors.
      alpha (`float`):
          Parameter of initialization. Larger value is harder assignment.
      normalize_input (`bool`):
          If true, descriptor-wise L2 normalization is applied to input.
class_docstr_tok: ["NetVLAD","layer","implementation",".","Args",":","num_clusters","(","`","int","`",")",":","The","number","of","clusters",".","dim","(","`","int","`",")",":","Dimension","of","descriptors",".","alpha","(","`","float","`",")",":","Parameter","of","initialization",".","Larger","value","is","harder","assignment",".","normalize_input","(","`","bool","`",")",":","If","true",",","descriptor-wise","L2","normalization","is","applied","to","input","."]
code: def forward(self, x: torch.Tensor):
      num_sample, in_dim = x.shape[:2]
  
      if self.normalize_input:
          x = F.normalize(x, p=2, dim=1)  # across descriptor dim
  
      # soft-assignment
      soft_assign = self.conv(x).view(num_sample, self.num_clusters, -1)
      soft_assign = F.softmax(soft_assign, dim=1)
  
      x_flatten = x.view(num_sample, in_dim, -1)
  
      # calculate residuals to each clusters
      residual = x_flatten.expand(
          self.num_clusters, -1, -1, -1
      ).permute(1, 0, 2, 3) - self.centroids.expand(
          x_flatten.size(-1), -1, -1
      ).permute(
          1, 2, 0
      ).unsqueeze(
          0
      )
      residual *= soft_assign.unsqueeze(2)
      vlad = residual.sum(dim=-1)
  
      vlad = F.normalize(vlad, p=2, dim=2)  # intra-normalization
      vlad = vlad.view(x.size(0), -1)  # flatten
      vlad = F.normalize(vlad, p=2, dim=1)  # L2 normalize
  
      return vlad
  
file_path: towhee/towhee/models/layers/netvlad.py
imports: import torch
  import torch.nn.functional
  from torch import nn
label_desc: Use image node_id 3 for calling the NetVLAD obj's underlying member method code with example usage: obj.forward(x) and returns: vlad