class_docstr: Loss used for DeepClusterV2 approach as provided in SwAV paper
  https://arxiv.org/abs/2006.09882
  
  Config params:
      DROP_LAST (bool): automatically inferred from DATA.TRAIN.DROP_LAST
      BATCHSIZE_PER_REPLICA (int): 256  # automatically inferred from
                                          DATA.TRAIN.BATCHSIZE_PER_REPLICA
      num_crops (int): 2                # automatically inferred from DATA.TRAIN.TRANSFORMS
      temperature (float): 0.1
      num_clusters (List[int]): [3000, 3000, 3000]
      kmeans_iters (int): 10
      crops_for_mb: [0]
      embedding_dim: 128
      num_train_samples (int): -1       # @auto-filled
class_docstr_tok: ["Loss","used","for","DeepClusterV2","approach","as","provided","in","SwAV","paper","https",":","\/\/arxiv.org\/abs\/2006.09882","Config","params",":","DROP_LAST","(","bool",")",":","automatically","inferred","from","DATA.TRAIN.DROP_LAST","BATCHSIZE_PER_REPLICA","(","int",")",":","256","#","automatically","inferred","from","DATA.TRAIN.BATCHSIZE_PER_REPLICA","num_crops","(","int",")",":","2","#","automatically","inferred","from","DATA.TRAIN.TRANSFORMS","temperature","(","float",")",":","0.1","num_clusters","(","List","[","int","]",")",":","[","3000",",","3000",",","3000","]","kmeans_iters","(","int",")",":","10","crops_for_mb",":","[","0","]","embedding_dim",":","128","num_train_samples","(","int",")",":","-1","#","@","auto-filled"]
code: def __init__(self, loss_config: AttrDict):
      super().__init__()
  
      self.loss_config = loss_config
      size_dataset = self.loss_config.num_train_samples
      size_memory_per_process = int(
          math.ceil(size_dataset * 1.0 / get_world_size())
      )
  
      if self.loss_config.DROP_LAST:
          size_memory_per_process -= (
              size_memory_per_process
              % self.loss_config.BATCHSIZE_PER_REPLICA
          )
  
      self.nmb_mbs = len(self.loss_config.memory_params.crops_for_mb)
      self.nmb_heads = len(self.loss_config.num_clusters)
      self.num_clusters = self.loss_config.num_clusters
      self.embedding_dim = self.loss_config.memory_params.embedding_dim
      self.crops_for_mb = self.loss_config.memory_params.crops_for_mb
      self.nmb_unique_idx = self.loss_config.BATCHSIZE_PER_REPLICA
      self.num_crops = self.loss_config.num_crops
      self.temperature = self.loss_config.temperature
      self.nmb_kmeans_iters = self.loss_config.kmeans_iters
      self.start_idx = 0
  
      self.register_buffer(
          "local_memory_embeddings",
          torch.zeros(
              self.nmb_mbs, size_memory_per_process, self.embedding_dim
          ),
      )
      self.register_buffer(
          "local_memory_index",
          torch.zeros(size_memory_per_process).long(),
      )
      self.register_buffer(
          "assignments",
          -100 * torch.ones(self.nmb_heads, size_dataset).long(),
      )
      for i, k in enumerate(self.loss_config.num_clusters):
          self.register_buffer(
              "centroids" + str(i), torch.rand(k, self.embedding_dim)
          )
  
      self.cross_entropy_loss = nn.CrossEntropyLoss(ignore_index=-100)
  
file_path: vissl/vissl/losses/deepclusterv2_loss.py
imports: import logging
  import math
  import pprint
  import torch
  import torch.distributed
  from classy_vision.generic.distributed_util import all_reduce_sum, gather_from_all, get_rank, get_world_size
  from classy_vision.losses import ClassyLoss, register_loss
  from torch import nn
  from vissl.config import AttrDict
  from vissl.utils.misc import get_indices_sparse
label_desc: Use image node_id 1 to create a new DeepClusterV2Loss object from inherited base classes: ClassyLoss with example: obj = DeepClusterV2Loss(loss_config)