code: def get_tp_fp_fn_tn(
      net_output, gt, axes=None, mask=None, square=False
  ):
      if axes is None:
          axes = tuple(range(2, net_output.ndim))
  
      shp_x = net_output.shape
      shp_y = gt.shape
  
      with paddle.no_grad():
          if len(shp_x) != len(shp_y):
              gt = gt.reshape((shp_y[0], 1, *shp_y[1:]))
  
          if all([i == j for i, j in zip(net_output.shape, gt.shape)]):
              # if this is the case then gt is probably already a one hot encoding
              y_onehot = gt
          else:
              gt = gt.astype("int64")[:, 0, ...]
              y_onehot = paddle.nn.functional.one_hot(
                  gt, num_classes=net_output.shape[1]
              )
              y_onehot = y_onehot.transpose(
                  [
                      0,
                      y_onehot.ndim - 1,
                      *[i for i in range(1, y_onehot.ndim - 1)],
                  ]
              )
  
      tp = net_output * y_onehot
      fp = net_output * (1 - y_onehot)
      fn = (1 - net_output) * y_onehot
      tn = (1 - net_output) * (1 - y_onehot)
  
      if mask is not None:
          tp = paddle.stack(
              tuple(
                  x_i * mask[:, 0] for x_i in paddle.unbind(tp, axis=1)
              ),
              axis=1,
          )
          fp = paddle.stack(
              tuple(
                  x_i * mask[:, 0] for x_i in paddle.unbind(fp, axis=1)
              ),
              axis=1,
          )
          fn = paddle.stack(
              tuple(
                  x_i * mask[:, 0] for x_i in paddle.unbind(fn, axis=1)
              ),
              axis=1,
          )
          tn = paddle.stack(
              tuple(
                  x_i * mask[:, 0] for x_i in paddle.unbind(tn, axis=1)
              ),
              axis=1,
          )
      if square:
          tp = tp**2
          fp = fp**2
          fn = fn**2
          tn = tn**2
  
      if len(axes) > 0:
          tp = sum_tensor(tp, axes, keepdim=False)
          fp = sum_tensor(fp, axes, keepdim=False)
          fn = sum_tensor(fn, axes, keepdim=False)
          tn = sum_tensor(tn, axes, keepdim=False)
      return tp, fp, fn, tn
  
file_path: PaddleSeg/contrib/MedicalSeg/nnunet/losses/dice_and_ce_loss.py
imports: import numpy
  import paddle
  from paddle import nn
  import paddle.nn.functional
  from medicalseg.cvlibs import manager
label_desc: Use image node_id 1 for calling a global function with example usage: get_tp_fp_fn_tn(net_output, gt, axes, mask, square) and returns: tp,  fp,  fn,  tn