class_docstr: L2 loss.
  
  Args:
      reduction (str, optional): The method to reduce the loss.
          Options are "none", "mean" and "sum".
      loss_weight (float, optional): The weight of loss.
docstr: Random select some elements from the gallery.
  
  It seems that Pytorch's implementation is slower than numpy so we use
  numpy to randperm the indices.
docstr_tok: ["Random","select","some","elements","from","the","gallery",".","It","seems","that","Pytorch","'s","implementation","is","slower","than","numpy","so","we","use","numpy","to","randperm","the","indices","."]
code: def random_choice(
      gallery: Union[list, np.ndarray, Tensor], num: int
  ) -> np.ndarray:
      """Random select some elements from the gallery.
  
      It seems that Pytorch's implementation is slower than numpy so we use
      numpy to randperm the indices.
      """
      assert len(gallery) >= num
      if isinstance(gallery, list):
          gallery = np.array(gallery)
      cands = np.arange(len(gallery))
      np.random.shuffle(cands)
      rand_inds = cands[:num]
      if not isinstance(gallery, np.ndarray):
          rand_inds = (
              torch.from_numpy(rand_inds).long().to(gallery.device)
          )
      return gallery[rand_inds]
  
file_path: mmdetection/mmdet/models/losses/l2_loss.py
imports: from typing import Optional, Tuple, Union
  import numpy
  import torch
  from mmengine.model import BaseModule
  from torch import Tensor
  from mmdet.registry import MODELS
  from .utils import weighted_loss
label_desc: Use image node_id 4 for calling the L2Loss obj's underlying member method code with example usage: obj.random_choice(gallery, num) and returns: gallery