code: def get_fed_loss_inds(labels, num_sample_cats, C, weight=None):
      appeared = torch.unique(labels)  # C'
      prob = appeared.new_ones(C + 1).float()
      prob[-1] = 0
      if len(appeared) < num_sample_cats:
          if weight is not None:
              prob[:C] = weight.float().clone()
          prob[appeared] = 0
          more_appeared = torch.multinomial(
              prob, num_sample_cats - len(appeared), replacement=False
          )
          appeared = torch.cat([appeared, more_appeared])
      return appeared
  
imports: import json
  from typing import List, Optional
  import torch
  from mmengine.config import ConfigDict
  from mmengine.structures import InstanceData
  from torch import Tensor
  from torch.nn import functional
  from mmdet.models.layers import multiclass_nms
  from mmdet.models.losses import accuracy
  from mmdet.models.roi_heads.bbox_heads import Shared2FCBBoxHead
  from mmdet.models.utils import empty_instances
  from mmdet.registry import MODELS
  from mmdet.structures.bbox import get_box_tensor, scale_boxes
  from mmdet.utils import ConfigType, InstanceList
label_desc: Use image node_id 2 for calling a global function with example usage: get_fed_loss_inds(labels, num_sample_cats, C, weight) and returns: appeared