Beispiel #1
0
    def _match_to_lbl(self, proposals, bbx, cat, match):
        cls_lbl = []
        bbx_lbl = []
        for i, (proposals_i, bbx_i, cat_i,
                match_i) in enumerate(zip(proposals, bbx, cat, match)):
            if match_i is not None:
                pos = match_i >= 0

                # Objectness labels
                cls_lbl_i = proposals_i.new_zeros(proposals_i.size(0),
                                                  dtype=torch.long)
                cls_lbl_i[pos] = cat_i[match_i[pos]] + 1 - self.num_stuff

                # Bounding box regression labels
                if pos.any().item():
                    bbx_lbl_i = calculate_shift(proposals_i[pos],
                                                bbx_i[match_i[pos]])
                    bbx_lbl_i *= bbx_lbl_i.new(self.bbx_reg_weights)
                else:
                    bbx_lbl_i = None

                cls_lbl.append(cls_lbl_i)
                bbx_lbl.append(bbx_lbl_i)
            else:
                cls_lbl.append(None)
                bbx_lbl.append(None)

        return PackedSequence(cls_lbl), PackedSequence(bbx_lbl)
Beispiel #2
0
    def _match_to_lbl(self, proposals, bbx, cat, ids, msk, match):
        cls_lbl = []
        bbx_lbl = []
        msk_lbl = []
        for i, (proposals_i, bbx_i, cat_i, ids_i, msk_i,
                match_i) in enumerate(zip(proposals, bbx, cat, ids, msk,
                                          match)):
            if match_i is not None:
                pos = match_i >= 0

                # Objectness labels
                cls_lbl_i = proposals_i.new_zeros(proposals_i.size(0),
                                                  dtype=torch.long)
                cls_lbl_i[pos] = cat_i[match_i[pos]] + 1 - self.num_stuff

                # Bounding box regression labels
                if pos.any().item():
                    bbx_lbl_i = calculate_shift(proposals_i[pos],
                                                bbx_i[match_i[pos]])
                    bbx_lbl_i *= bbx_lbl_i.new(self.bbx_reg_weights)

                    iis_lbl_i = ids_i[match_i[pos]]

                    # Compute instance segmentation masks
                    msk_i = roi_sampling(
                        msk_i.unsqueeze(0),
                        proposals_i[pos],
                        msk_i.new_zeros(pos.long().sum().item()),
                        self.lbl_roi_size,  #28*28
                        interpolation="nearest")

                    # Calculate mask segmentation labels
                    msk_lbl_i = (msk_i == iis_lbl_i.view(
                        -1, 1, 1, 1)).any(dim=1).to(torch.long)
                    if not self.void_is_background:
                        msk_lbl_i[(msk_i == 0).all(dim=1)] = -1
                else:
                    bbx_lbl_i = None
                    msk_lbl_i = None

                cls_lbl.append(cls_lbl_i)
                bbx_lbl.append(bbx_lbl_i)
                msk_lbl.append(msk_lbl_i)
            else:
                cls_lbl.append(None)
                bbx_lbl.append(None)
                msk_lbl.append(None)

        return PackedSequence(cls_lbl), PackedSequence(
            bbx_lbl), PackedSequence(msk_lbl)
Beispiel #3
0
    def _match_to_lbl(anchors, bbx, match):
        pos, neg = match >= 0, match == -1

        # Objectness labels from matching tensor
        obj_lbl = torch.full_like(match, -1)
        obj_lbl[neg] = 0
        obj_lbl[pos] = 1

        # Bounding box regression labels from matching tensor
        bbx_lbl = anchors.new_zeros(len(bbx), anchors.size(0), anchors.size(1))
        for i, (pos_i, bbx_i, match_i) in enumerate(zip(pos, bbx, match)):
            if pos_i.any():
                bbx_lbl[i, pos_i] = calculate_shift(anchors[pos_i],
                                                    bbx_i[match_i[pos_i]])

        return obj_lbl, bbx_lbl