class_docstr: PyTorch implementation of the Smooth-AP loss.
  implementation of the Smooth-AP loss. Takes as input the mini-batch of CNN-produced feature embeddings and returns
  the value of the Smooth-AP loss. The mini-batch must be formed of a defined number of classes. Each class must
  have the same number of instances represented in the mini-batch and must be ordered sequentially by class.
  e.g. the labels for a mini-batch with batch size 9, and 3 represented classes (A,B,C) must look like:
      labels = ( A, A, A, B, B, B, C, C, C)
  (the order of the classes however does not matter)
  For each instance in the mini-batch, the loss computes the Smooth-AP when it is used as the query and the rest of the
  mini-batch is used as the retrieval set. The positive set is formed of the other instances in the batch from the
  same class. The loss returns the average Smooth-AP across all instances in the mini-batch.
  Args:
      anneal : float
          the temperature of the sigmoid that is used to smooth the ranking function. A low value of the temperature
          results in a steep sigmoid, that tightly approximates the heaviside step function in the ranking function.
      batch_size : int
          the batch size being used during training.
      num_id : int
          the number of different classes that are represented in the batch.
      feat_dims : int
          the dimension of the input feature embeddings
  Shape:
      - Input (preds): (batch_size, feat_dims) (must be a cuda torch float tensor)
      - Output: scalar
  Examples::
      >>> loss = SmoothAP(0.01, 60, 6, 256)
      >>> input = torch.randn(60, 256, requires_grad=True).cuda()
      >>> output = loss(input)
      >>> output.backward()
class_docstr_tok: ["PyTorch","implementation","of","the","Smooth-AP","loss",".","implementation","of","the","Smooth-AP","loss",".","Takes","as","input","the","mini-batch","of","CNN-produced","feature","embeddings","and","returns","the","value","of","the","Smooth-AP","loss",".","The","mini-batch","must","be","formed","of","a","defined","number","of","classes",".","Each","class","must","have","the","same","number","of","instances","represented","in","the","mini-batch","and","must","be","ordered","sequentially","by","class",".","e.g",".","the","labels","for","a","mini-batch","with","batch","size","9",",","and","3","represented","classes","(","A",",","B",",","C",")","must","look","like",":","labels","=","(","A",",","A",",","A",",","B",",","B",",","B",",","C",",","C",",","C",")","(","the","order","of","the","classes","however","does","not","matter",")","For","each","instance","in","the","mini-batch",",","the","loss","computes","the","Smooth-AP","when","it","is","used","as","the","query","and","the","rest","of","the","mini-batch","is","used","as","the","retrieval","set",".","The","positive","set","is","formed","of","the","other","instances","in","the","batch","from","the","same","class",".","The","loss","returns","the","average","Smooth-AP","across","all","instances","in","the","mini-batch",".","Args",":","anneal",":","float","the","temperature","of","the","sigmoid","that","is","used","to","smooth","the","ranking","function",".","A","low","value","of","the","temperature","results","in","a","steep","sigmoid",",","that","tightly","approximates","the","heaviside","step","function","in","the","ranking","function",".","batch_size",":","int","the","batch","size","being","used","during","training",".","num_id",":","int","the","number","of","different","classes","that","are","represented","in","the","batch",".","feat_dims",":","int","the","dimension","of","the","input","feature","embeddings","Shape",":","-","Input","(","preds",")",":","(","batch_size",",","feat_dims",")","(","must","be","a","cuda","torch","float","tensor",")","-","Output",":","scalar","Examples",":",":",">",">",">","loss","=","SmoothAP","(","0.01",",","60",",","6",",","256",")",">",">",">","input","=","torch.randn","(","60",",","256",",","requires_grad=True",")",".cuda","(",")",">",">",">","output","=","loss","(","input",")",">",">",">","output.backward","(",")"]
docstr: Parameters
  ----------
  anneal : float
      the temperature of the sigmoid that is used to smooth the ranking function
  batch_size : int
      the batch size being used
  num_id : int
      the number of different classes that are represented in the batch
  feat_dims : int
      the dimension of the input feature embeddings
docstr_tok: ["Parameters","--","--","--","--","--","anneal",":","float","the","temperature","of","the","sigmoid","that","is","used","to","smooth","the","ranking","function","batch_size",":","int","the","batch","size","being","used","num_id",":","int","the","number","of","different","classes","that","are","represented","in","the","batch","feat_dims",":","int","the","dimension","of","the","input","feature","embeddings"]
code: def __init__(self, anneal, batch_size, num_id, feat_dims):
      """
      Parameters
      ----------
      anneal : float
          the temperature of the sigmoid that is used to smooth the ranking function
      batch_size : int
          the batch size being used
      num_id : int
          the number of different classes that are represented in the batch
      feat_dims : int
          the dimension of the input feature embeddings
      """
      super(SmoothAP, self).__init__()
  
      assert batch_size % num_id == 0
  
      self.anneal = anneal
      self.batch_size = batch_size
      self.num_id = num_id
      self.feat_dims = feat_dims
  
file_path: dgl/examples/pytorch/hilander/PSS/Smooth_AP/src/losses.py
imports: import warnings
  import faiss
  import numpy
  import torch
  from scipy import sparse
label_desc: Use image node_id 1 to create a new SmoothAP object from inherited base classes: torch.nn with example: obj = SmoothAP(anneal, batch_size, num_id, feat_dims)