code: def mask_to_rle_paddle(tensor: paddle.Tensor) -> List[Dict[str, Any]]:
      """
      Encodes masks to an uncompressed RLE, in the format expected by
      pycoco tools.
      """
      # Put in fortran order and flatten h,w
      b, h, w = tensor.shape
      tensor = tensor.transpose([0, 2, 1]).flatten(1)
  
      # Compute change indices
      diff = paddle.logical_xor(tensor[:, 1:], tensor[:, :-1])
      change_indices = diff.nonzero()
  
      # Encode run length
      out = []
      for i in range(b):
          cur_idxs = change_indices[change_indices[:, 0] == i][:, 1]
          cur_idxs = paddle.concat(
              [
                  paddle.to_tensor([0], dtype=cur_idxs.dtype),
                  cur_idxs + 1,
                  paddle.to_tensor([h * w], dtype=cur_idxs.dtype),
              ]
          )
          btw_idxs = cur_idxs[1:] - cur_idxs[:-1]
          counts = [] if tensor[i, 0] == 0 else [0]
          counts.extend(btw_idxs.detach().cpu().tolist())
          out.append({"size": [h, w], "counts": counts})
      return out
  
imports: import numpy
  import paddle
  import math
  from copy import deepcopy
  from itertools import product
  from typing import Any, Dict, Generator, ItemsView, List, Tuple
label_desc: Use image node_id 4 for calling a global function with example usage: mask_to_rle_paddle(tensor) and returns: out