class_docstr: An implementation for Vector Quantization
class_docstr_tok: ["An","implementation","for","Vector","Quantization"]
docstr: Decodes latent representations into discrete codes by comparing with the codebook.
  
  Parameters
  ----------
  latents : torch.Tensor
      The latent tensor representations to be decoded.
  
  Returns
  -------
  Tuple[torch.Tensor, torch.Tensor]
      A tuple containing the decoded latent tensor (`z_q`) and the indices of the codes.
docstr_tok: ["Decodes","latent","representations","into","discrete","codes","by","comparing","with","the","codebook",".","Parameters","--","--","--","--","--","latents",":","torch.Tensor","The","latent","tensor","representations","to","be","decoded",".","Returns","--","--","--","-","Tuple","[","torch.Tensor",",","torch.Tensor","]","A","tuple","containing","the","decoded","latent","tensor","(","`","z_q","`",")","and","the","indices","of","the","codes","."]
code: def decode_latents(self, latents: torch.Tensor):
      """
      Decodes latent representations into discrete codes by comparing with the codebook.
  
      Parameters
      ----------
      latents : torch.Tensor
          The latent tensor representations to be decoded.
  
      Returns
      -------
      Tuple[torch.Tensor, torch.Tensor]
          A tuple containing the decoded latent tensor (`z_q`) and the indices of the codes.
      """
      encodings = latents.permute(0, 2, 1).reshape(-1, latents.size(1))
      codebook = self.codebook.weight  # codebook: (N x D)
  
      # L2 normalize encodings and codebook (ViT-VQGAN)
      encodings = F.normalize(encodings)
      codebook = F.normalize(codebook)
  
      # Compute euclidean distance with codebook
      dist = (
          encodings.pow(2).sum(1, keepdim=True)
          - 2 * encodings @ codebook.t()
          + codebook.pow(2).sum(1, keepdim=True).t()
      )
  
      # indices = rearrange((-dist).max(1)[1], "(b t) -> b t", b=latents.size(0))
  
      max_indices = (-dist).max(dim=1)[1]
      b = latents.size(0)
      t = max_indices.numel() // b
      indices = max_indices.view(b, t)
      z_q = self.decode_code(indices)
      return z_q, indices
  
imports: import math
  from pathlib import Path
  from typing import List, Union
  import logging
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.nn.utils.parametrizations import weight_norm
label_desc: Use image node_id 5 for calling the VectorQuantize obj's underlying member method code with example usage: obj.decode_latents(latents) and returns: z_q,  indices