class_docstr: Linear head for re-identification.
  
  Args:
      num_fcs (int): Number of fcs.
      in_channels (int): Number of channels in the input.
      fc_channels (int): Number of channels in the fcs.
      out_channels (int): Number of channels in the output.
      norm_cfg (dict, optional): Configuration of normlization method
          after fc. Defaults to None.
      act_cfg (dict, optional): Configuration of activation method after fc.
          Defaults to None.
      num_classes (int, optional): Number of the identities. Default to None.
      loss_cls (dict, optional): Cross entropy loss to train the ReID module.
          Defaults to None.
      loss_triplet (dict, optional): Triplet loss to train the ReID module.
          Defaults to None.
      topk (int | Tuple[int]): Top-k accuracy. Defaults to ``(1, )``.
      init_cfg (dict or list[dict], optional): Initialization config dict.
          Defaults to dict(type='Normal',layer='Linear', mean=0, std=0.01,
          bias=0).
class_docstr_tok: ["Linear","head","for","re-identification",".","Args",":","num_fcs","(","int",")",":","Number","of","fcs",".","in_channels","(","int",")",":","Number","of","channels","in","the","input",".","fc_channels","(","int",")",":","Number","of","channels","in","the","fcs",".","out_channels","(","int",")",":","Number","of","channels","in","the","output",".","norm_cfg","(","dict",",","optional",")",":","Configuration","of","normlization","method","after","fc",".","Defaults","to","None",".","act_cfg","(","dict",",","optional",")",":","Configuration","of","activation","method","after","fc",".","Defaults","to","None",".","num_classes","(","int",",","optional",")",":","Number","of","the","identities",".","Default","to","None",".","loss_cls","(","dict",",","optional",")",":","Cross","entropy","loss","to","train","the","ReID","module",".","Defaults","to","None",".","loss_triplet","(","dict",",","optional",")",":","Triplet","loss","to","train","the","ReID","module",".","Defaults","to","None",".","topk","(","int","|","Tuple","[","int","]",")",":","Top-k","accuracy",".","Defaults","to","``","(","1",",",")","``",".","init_cfg","(","dict","or","list","[","dict","]",",","optional",")",":","Initialization","config","dict",".","Defaults","to","dict","(","type='Normal","'",",","layer='Linear","'",",","mean=0",",","std=0.01",",","bias=0",")","."]
docstr: Unpack data samples and compute loss.
docstr_tok: ["Unpack","data","samples","and","compute","loss","."]
code: def loss_by_feat(
      self, feats: torch.Tensor, data_samples: List[ReIDDataSample]
  ) -> dict:
      """Unpack data samples and compute loss."""
      losses = dict()
      gt_label = torch.cat([i.gt_label.label for i in data_samples])
      gt_label = gt_label.to(feats.device)
  
      if self.loss_triplet:
          losses["triplet_loss"] = self.loss_triplet(feats, gt_label)
  
      if self.loss_cls:
          feats_bn = self.bn(feats)
          cls_score = self.classifier(feats_bn)
          losses["ce_loss"] = self.loss_cls(cls_score, gt_label)
          acc = Accuracy.calculate(cls_score, gt_label, topk=self.topk)
          losses.update(
              {f"accuracy_top-{k}": a for k, a in zip(self.topk, acc)}
          )
  
      return losses
  
file_path: mmdetection/mmdet/models/reid/linear_reid_head.py
imports: import warnings
  from typing import List, Optional, Tuple, Union
  import torch
  import torch.nn
  from mmengine.model import BaseModule
  from mmdet.registry import MODELS
  from mmdet.structures import ReIDDataSample
  from .fc_module import FcModule
label_desc: Use image node_id 5 for calling the LinearReIDHead obj's underlying member method code with example usage: obj.loss_by_feat(feats, data_samples) and returns: losses