utils.py 1.14 KB
Newer Older
Kai Chen's avatar
Kai Chen committed
1
2
3
import mmcv


4
def split_combined_polys(polys, poly_lens, polys_per_mask):
Kai Chen's avatar
Kai Chen committed
5
6
7
8
9
10
11
    """Split the combined 1-D polys into masks.

    A mask is represented as a list of polys, and a poly is represented as
    a 1-D array. In dataset, all masks are concatenated into a single 1-D
    tensor. Here we need to split the tensor into original representations.

    Args:
12
13
14
        polys (list): a list (length = image num) of 1-D tensors
        poly_lens (list): a list (length = image num) of poly length
        polys_per_mask (list): a list (length = image num) of poly number
Kai Chen's avatar
Kai Chen committed
15
16
17
18
19
20
21
            of each mask

    Returns:
        list: a list (length = image num) of list (length = mask num) of
            list (length = poly num) of numpy array
    """
    mask_polys_list = []
22
23
24
25
    for img_id in range(len(polys)):
        polys_single = polys[img_id]
        polys_lens_single = poly_lens[img_id].tolist()
        polys_per_mask_single = polys_per_mask[img_id].tolist()
Kai Chen's avatar
Kai Chen committed
26

27
28
        split_polys = mmcv.slice_list(polys_single, polys_lens_single)
        mask_polys = mmcv.slice_list(split_polys, polys_per_mask_single)
Kai Chen's avatar
Kai Chen committed
29
30
        mask_polys_list.append(mask_polys)
    return mask_polys_list