class_docstr: Contrastive Model, currently mainly focused on memory bank and CSC.
class_docstr_tok: ["Contrastive","Model",",","currently","mainly","focused","on","memory","bank","and","CSC","."]
code: def init_knn_labels(self, train_loader):
      logger.info("initializing knn labels")
      self.num_imgs = len(train_loader.dataset._labels)
      self.train_labels = np.zeros((self.num_imgs,), dtype=np.int32)
      for i in range(self.num_imgs):
          self.train_labels[i] = train_loader.dataset._labels[i]
      self.train_labels = torch.LongTensor(self.train_labels).cuda()
      if self.length != self.num_imgs:
          logger.error(
              "Kinetics dataloader size: {} differs from memorybank length {}".format(
                  self.num_imgs, self.length
              )
          )
          self.knn_mem.resize(self.num_imgs, 1, self.dim)
  
imports: import math
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import slowfast.models.losses
  import slowfast.utils.distributed
  import slowfast.utils.logging
  from slowfast.models.video_model_builder import X3D, MViT, ResNet, SlowFast
  from .build import MODEL_REGISTRY
label_desc: Use image node_id 3 for calling the ContrastiveModel obj's underlying member method code with example usage: obj.init_knn_labels(train_loader) without return types