예제 #1
0
def build_debug_sample(components):
    """
    Builds a sample for a model ONLY FOR DEBUGING. It returns the full meta
    instance instead of an image

    :param components: components
    :return: list of final components of a sample.
    """
    meta = components[0]

    if meta.mask is None:
        mask_paf = ALL_PAF_MASK
        mask_heatmap = ALL_HEATMAP_MASK
    else:
        mask_paf = create_all_mask(meta.mask, 20, stride=8)
        mask_heatmap = create_all_mask(meta.mask, 8, stride=8)

    heatmap = create_heatmap(JointsLoader.num_joints_and_bkg,
                             46,
                             46,
                             meta.aug_joints,
                             7.0,
                             stride=8)

    pafmap = create_paf(JointsLoader.num_connections,
                        46,
                        46,
                        meta.aug_joints,
                        1,
                        stride=8)

    return [meta, mask_paf, mask_heatmap, pafmap, heatmap]
def build_sample(components):
    """
    Builds a sample for a model.

    :param components: components
    :return: list of final components of a sample.
    """
    meta = components[0]
    image = meta.img

    if meta.mask is None:
        mask_paf = ALL_PAF_MASK
        mask_heatmap = ALL_HEATMAP_MASK
    else:
        mask_paf = create_all_mask(meta.mask, 38, stride=8)
        mask_heatmap = create_all_mask(meta.mask, 19, stride=8)

    # print("hdebug:meta.aug_joints:",len(meta.aug_joints[0]))
    # print(type(JointsLoader.num_joints_and_bkg))
    heatmap = create_heatmap(JointsLoader.num_joints_and_bkg, 46, 46,
                             meta.aug_joints, 7.0, stride=8)                             

    pafmap = create_paf(JointsLoader.num_connections, 46, 46,
                        meta.aug_joints, 1, stride=8)

    # release reference to the image/mask/augmented data. Otherwise it would easily consume all memory at some point
    meta.mask = None
    meta.img = None
    meta.aug_joints = None
    meta.aug_center = None
    return [image.astype(np.uint8), mask_paf, mask_heatmap, pafmap, heatmap]
def build_sample(components):
    """
    Builds a sample for a model.

    :param components: components
    :return: list of final components of a sample.
    """
    meta = components[0]
    image = meta.img

    if meta.mask is None:
        mask_paf = ALL_PAF_MASK
        mask_heatmap = ALL_HEATMAP_MASK
    else:
        mask_paf = create_all_mask(meta.mask, KEY_POINT_LINK, stride=1)
        mask_heatmap = create_all_mask(meta.mask, KEY_POINT_NUM, stride=1)

    stride = 4
    heatmap = create_heatmap(JointsLoader.num_joints_and_bkg,
                             int(meta.crop_y_max / stride),
                             int(meta.crop_x_max / stride),
                             int(meta.crop_y / stride),
                             int(meta.crop_x / stride),
                             meta.aug_joints,
                             4.00,
                             stride=stride)

    pafmap = create_paf(JointsLoader.num_connections,
                        int(meta.crop_y_max / stride),
                        int(meta.crop_x_max / stride),
                        int(meta.crop_y / stride),
                        int(meta.crop_x / stride),
                        meta.aug_joints,
                        1,
                        stride=stride)

    maskmap, numlist = create_mask(JointsLoader.num_joints_and_bkg,
                                   JointsLoader.num_connections,
                                   int(meta.crop_y_max / stride),
                                   int(meta.crop_x_max / stride),
                                   int(meta.crop_y / stride),
                                   int(meta.crop_x / stride),
                                   meta.aug_joints,
                                   4.00,
                                   1,
                                   stride=stride)
    # release reference to the image/mask/augmented data. Otherwise it would easily consume all memory at some point
    meta.mask = None
    meta.img = None
    meta.aug_joints = None
    meta.aug_center = None
    return [
        image.astype(np.uint8), mask_paf, mask_heatmap, pafmap, heatmap,
        maskmap, numlist
    ]
def build_debug_sample(components):
    """
    Builds a sample for a model ONLY FOR DEBUGING. It returns the full meta
    instance instead of an image

    :param components: components
    :return: list of final components of a sample.
    """
    meta = components[0]

    if meta.mask is None:
        mask_paf = None
        mask_heatmap = None
    else:
        mask_paf = create_all_mask(meta.mask, KEY_POINT_LINK, stride=4)
        mask_heatmap = create_all_mask(meta.mask, KEY_POINT_NUM, stride=4)

    stride = 4
    heatmap = create_heatmap(JointsLoader.num_joints_and_bkg,
                             int(meta.crop_y_max / stride),
                             int(meta.crop_x_max / stride),
                             int(meta.crop_y / stride),
                             int(meta.crop_x / stride),
                             meta.aug_joints,
                             3.5,
                             stride=stride)

    pafmap = create_paf(JointsLoader.num_connections,
                        int(meta.crop_y_max / stride),
                        int(meta.crop_x_max / stride),
                        int(meta.crop_y / stride),
                        int(meta.crop_x / stride),
                        meta.aug_joints,
                        1.00,
                        stride=stride)

    return [meta, mask_paf, mask_heatmap, pafmap, heatmap]
예제 #5
0
def load_refs(batch_refs):
    videos = []
    masks = [[], []]
    targets = [[], []]

    for refs in batch_refs:
        zipped, augment = refs
        frames, boxes, maskpaths, _, coco_coords = zip(*zipped)
        imgs, heats, pafs, mask_heats, mask_pafs = [], [], [], [], []

        __masks = np.array([np.load(fl) for fl in maskpaths])

        imgs = [imread(path) for path in frames]
        imsize = imgs[0].shape
        imgs = shape_image(imgs, boxes, augment)

        width, height = int(imgs[0].shape[0] / 8), int(imgs[0].shape[1] / 8)
        for frame_ii in range(len(frames)):
            coords = shape_coords(coco_coords[frame_ii], boxes[frame_ii],
                                  imsize, augment)
            assert len(coords) == len(coco_coords[frame_ii])
            heat = create_heatmap(19,
                                  width,
                                  height, [coords],
                                  sigma=7.0,
                                  stride=8)
            paf = create_paf(19,
                             width,
                             height, [coords],
                             threshold=1.0,
                             stride=8)
            assert paf.shape[-1] == 38

            heat_mask = create_mask(19, width, height, __masks[frame_ii])
            mask_heats.append(heat_mask)

            for ind in PENN_MISSING:
                heat_mask[:, :, ind] = 0

            paf_mask = create_mask(38, width, height, __masks[frame_ii])
            mask_pafs.append(paf_mask)

            for ind, (j_idx1, j_idx2) in enumerate(JointsLoader.joint_pairs):
                if j_idx1 in PENN_MISSING or j_idx2 in PENN_MISSING:
                    paf_mask[:, :, ind] = 0

            heat = np.multiply(heat, heat_mask.astype(np.float32))
            paf = np.multiply(paf, paf_mask.astype(np.float32))

            heats.append(heat)
            pafs.append(paf)

        mask_heats = shape_image(mask_heats, boxes, augment, stride=8)
        mask_pafs = shape_image(mask_pafs, boxes, augment, stride=8)

        imgs = crop(imgs, 368)
        mask_heats = crop(mask_heats, 46)
        mask_pafs = crop(mask_pafs, 46)
        heats = crop(heats, 46)
        pafs = crop(pafs, 46)

        videos.append(imgs)
        masks[0].append(mask_heats)
        masks[1].append(mask_pafs)
        targets[0].append(heats)
        targets[1].append(pafs)

    return [
        np.array(videos),
        np.array(masks[1]),
        np.array(masks[0]),
    ], [
        np.array(targets[1]),
        np.array(targets[0]),
    ]