code: def emb_loss(self, p_ide, t_conf, t_ide, emb_scale, classifier):
      emb_dim = p_ide.shape[1]
      p_ide = p_ide.transpose((0, 2, 3, 1))
      p_ide_flatten = paddle.reshape(p_ide, [-1, emb_dim])
      mask = t_conf > 0
      mask = paddle.cast(mask, dtype="int64")
      mask.stop_gradient = True
      emb_mask = mask.max(1).flatten()
      emb_mask_inds = paddle.nonzero(emb_mask > 0).flatten()
      emb_mask_inds.stop_gradient = True
      # use max(1) to decide the id, TODO: more reseanable strategy
      t_ide_flatten = t_ide.max(1).flatten()
      t_ide_flatten = paddle.cast(t_ide_flatten, dtype="int64")
      valid_inds = paddle.nonzero(t_ide_flatten != -1).flatten()
  
      if emb_mask_inds.numel() == 0 or valid_inds.numel() == 0:
          # loss_ide = paddle.to_tensor([0]) # will be error in gradient backward
          loss_ide = self.phony * 0  # todo
      else:
          embedding = paddle.gather(p_ide_flatten, emb_mask_inds)
          embedding = emb_scale * F.normalize(embedding)
          logits = classifier(embedding)
  
          ide_target = paddle.gather(t_ide_flatten, emb_mask_inds)
  
          loss_ide = F.cross_entropy(
              logits, ide_target, ignore_index=-1, reduction="mean"
          )
      loss_ide.stop_gradient = False
  
      return loss_ide
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import paddle
  import paddle.nn
  import paddle.nn.functional
  from ppdet.core.workspace import register
label_desc: Use image node_id 2 for calling the JDEEmbeddingLoss obj's underlying member method code with example usage: obj.emb_loss(p_ide, t_conf, t_ide, emb_scale, classifier) and returns: loss_ide