class_docstr: Improved version over VectorQuantizer, can be used as a drop-in replacement. Mostly
  avoids costly matrix multiplications and allows for post-hoc remapping of indices.
class_docstr_tok: ["Improved","version","over","VectorQuantizer",",","can","be","used","as","a","drop-in","replacement",".","Mostly","avoids","costly","matrix","multiplications","and","allows","for","post-hoc","remapping","of","indices","."]
code: def get_codebook_entry(self, indices, shape):
      # shape specifying (batch, height, width, channel)
      if self.remap is not None:
          indices = indices.reshape(shape[0], -1)  # add batch axis
          indices = self.unmap_to_all(indices)
          indices = indices.reshape(-1)  # flatten again
  
      # get quantized latent vectors
      z_q = self.embedding(indices)
  
      if shape is not None:
          z_q = z_q.view(shape)
          # reshape back to match original input shape
          z_q = z_q.permute(0, 3, 1, 2).contiguous()
  
      return z_q
  
file_path: stable-diffusion-webui/extensions-builtin/LDSR/vqvae_quantize.py
imports: import torch
  import torch.nn
  import numpy
  from einops import rearrange
label_desc: Use image node_id 5 for calling the VectorQuantizer2 obj's underlying member method code with example usage: obj.get_codebook_entry(indices, shape) and returns: z_q