當前位置: 首頁>>代碼示例>>Python>>正文


Python segmentation_mask.SegmentationMask方法代碼示例

本文整理匯總了Python中maskrcnn_benchmark.structures.segmentation_mask.SegmentationMask方法的典型用法代碼示例。如果您正苦於以下問題:Python segmentation_mask.SegmentationMask方法的具體用法?Python segmentation_mask.SegmentationMask怎麽用?Python segmentation_mask.SegmentationMask使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在maskrcnn_benchmark.structures.segmentation_mask的用法示例。


在下文中一共展示了segmentation_mask.SegmentationMask方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __getitem__

# 需要導入模塊: from maskrcnn_benchmark.structures import segmentation_mask [as 別名]
# 或者: from maskrcnn_benchmark.structures.segmentation_mask import SegmentationMask [as 別名]
def __getitem__(self, idx):
        img, anno = super(COCODataset, self).__getitem__(idx)

        # filter crowd annotations
        # TODO might be better to add an extra field
        anno = [obj for obj in anno if obj["iscrowd"] == 0]

        boxes = [obj["bbox"] for obj in anno]
        boxes = torch.as_tensor(boxes).reshape(-1, 4)  # guard against no boxes
        target = BoxList(boxes, img.size, mode="xywh").convert("xyxy")

        classes = [obj["category_id"] for obj in anno]
        classes = [self.json_category_id_to_contiguous_id[c] for c in classes]
        classes = torch.tensor(classes)
        target.add_field("labels", classes)

        masks = [obj["segmentation"] for obj in anno]
        masks = SegmentationMask(masks, img.size)
        target.add_field("masks", masks)

        if anno and "keypoints" in anno[0]:
            keypoints = [obj["keypoints"] for obj in anno]
            keypoints = PersonKeypoints(keypoints, img.size)
            target.add_field("keypoints", keypoints)

        target = target.clip_to_image(remove_empty=True)

        if self.transforms is not None:
            img, target = self.transforms(img, target)

        return img, target, idx 
開發者ID:Res2Net,項目名稱:Res2Net-maskrcnn,代碼行數:33,代碼來源:coco.py

示例2: __getitem__

# 需要導入模塊: from maskrcnn_benchmark.structures import segmentation_mask [as 別名]
# 或者: from maskrcnn_benchmark.structures.segmentation_mask import SegmentationMask [as 別名]
def __getitem__(self, idx):
        img, anno = super(ModaNetDataset, self).__getitem__(idx)
        
        # filter crowd annotations
        # TODO might be better to add an extra field
        anno = [obj for obj in anno if obj["iscrowd"] == 0]

        boxes = [obj["bbox"] for obj in anno]
        boxes = torch.as_tensor(boxes).reshape(-1, 4)  # guard against no boxes
        target = BoxList(boxes, img.size, mode="xywh").convert("xyxy")

        classes = [obj["category_id"]+1 for obj in anno]
        #print(classes,'old')
        classes = [self.json_category_id_to_contiguous_id[c] for c in classes]
        #print(classes,classes2)
        classes = torch.tensor(classes)
        target.add_field("labels", classes) #

        #masks = [obj["segmentation"] for obj in anno]
        #masks = SegmentationMask(masks, img.size, mode='poly')
        #target.add_field("masks", masks)

        #if anno and "keypoints" in anno[0]:
         #   keypoints = [obj["keypoints"] for obj in anno]
          #  keypoints = PersonKeypoints(keypoints, img.size)
           # target.add_field("keypoints", keypoints)

        target = target.clip_to_image(remove_empty=True)

        if self.transforms is not None:
            img, target = self.transforms(img, target)

        return img, target, idx 
開發者ID:simaiden,項目名稱:Clothing-Detection,代碼行數:35,代碼來源:modanet.py

示例3: __getitem__

# 需要導入模塊: from maskrcnn_benchmark.structures import segmentation_mask [as 別名]
# 或者: from maskrcnn_benchmark.structures.segmentation_mask import SegmentationMask [as 別名]
def __getitem__(self, idx):
        img, anno = super(COCODataset, self).__getitem__(idx)

        # filter crowd annotations
        # TODO might be better to add an extra field
        anno = [obj for obj in anno if obj["iscrowd"] == 0]

        boxes = [obj["bbox"] for obj in anno]
        boxes = torch.as_tensor(boxes).reshape(-1, 4)  # guard against no boxes
        target = BoxList(boxes, img.size, mode="xywh").convert("xyxy")

        classes = [obj["category_id"] for obj in anno]
        classes = [self.json_category_id_to_contiguous_id[c] for c in classes]
        classes = torch.tensor(classes)
        target.add_field("labels", classes)

        if anno and "segmentation" in anno[0]:
            masks = [obj["segmentation"] for obj in anno]
            masks = SegmentationMask(masks, img.size, mode='poly')
            target.add_field("masks", masks)

        if anno and "keypoints" in anno[0]:
            keypoints = [obj["keypoints"] for obj in anno]
            keypoints = PersonKeypoints(keypoints, img.size)
            target.add_field("keypoints", keypoints)

        target = target.clip_to_image(remove_empty=True)

        if self._transforms is not None:
            img, target = self._transforms(img, target)

        return img, target, idx 
開發者ID:simaiden,項目名稱:Clothing-Detection,代碼行數:34,代碼來源:coco.py

示例4: __getitem__

# 需要導入模塊: from maskrcnn_benchmark.structures import segmentation_mask [as 別名]
# 或者: from maskrcnn_benchmark.structures.segmentation_mask import SegmentationMask [as 別名]
def __getitem__(self, idx):
        img, anno = super(DeepFashion2Dataset, self).__getitem__(idx)

        # filter crowd annotations
        # TODO might be better to add an extra field
        anno = [obj for obj in anno if obj["iscrowd"] == 0]

        boxes = [obj["bbox"] for obj in anno]
        boxes = torch.as_tensor(boxes).reshape(-1, 4)  # guard against no boxes
        target = BoxList(boxes, img.size, mode="xywh").convert("xyxy")

        classes = [obj["category_id"] for obj in anno]
        #print(classes)
        classes = [self.json_category_id_to_contiguous_id[c] for c in classes]
        classes = torch.tensor(classes)
        target.add_field("labels", classes)

        #masks = [obj["segmentation"] for obj in anno]
        #masks = SegmentationMask(masks, img.size, mode='poly')
        #target.add_field("masks", masks)

        #if anno and "keypoints" in anno[0]:
         #   keypoints = [obj["keypoints"] for obj in anno]
          #  keypoints = PersonKeypoints(keypoints, img.size)
           # target.add_field("keypoints", keypoints)

        target = target.clip_to_image(remove_empty=True)

        if self.transforms is not None:
            img, target = self.transforms(img, target)

        return img, target, idx 
開發者ID:simaiden,項目名稱:Clothing-Detection,代碼行數:34,代碼來源:deepfashion2.py

示例5: __init__

# 需要導入模塊: from maskrcnn_benchmark.structures import segmentation_mask [as 別名]
# 或者: from maskrcnn_benchmark.structures.segmentation_mask import SegmentationMask [as 別名]
def __init__(self, method_name='runTest'):
        super(TestSegmentationMask, self).__init__(method_name)
        poly = [[[423.0, 306.5, 406.5, 277.0, 400.0, 271.5, 389.5, 277.0,
                  387.5, 292.0, 384.5, 295.0, 374.5, 220.0, 378.5, 210.0,
                  391.0, 200.5, 404.0, 199.5, 414.0, 203.5, 425.5, 221.0,
                  438.5, 297.0, 423.0, 306.5],
                 [100, 100,     200, 100,     200, 200,     100, 200],
                ]]
        width = 640
        height = 480
        size = width, height

        self.P = SegmentationMask(poly, size, 'poly')
        self.M = SegmentationMask(poly, size, 'poly').convert('mask') 
開發者ID:megvii-model,項目名稱:DetNAS,代碼行數:16,代碼來源:test_segmentation_mask.py

示例6: __getitem__

# 需要導入模塊: from maskrcnn_benchmark.structures import segmentation_mask [as 別名]
# 或者: from maskrcnn_benchmark.structures.segmentation_mask import SegmentationMask [as 別名]
def __getitem__(self, idx):
        img, anno = super(COCODataset, self).__getitem__(idx)

        # filter crowd annotations
        # TODO might be better to add an extra field
        anno = [obj for obj in anno if obj["iscrowd"] == 0]

        boxes = [obj["bbox"] for obj in anno]
        boxes = torch.as_tensor(boxes).reshape(-1, 4)  # guard against no boxes
        target = BoxList(boxes, img.size, mode="xywh").convert("xyxy")

        classes = [obj["category_id"] for obj in anno]
        classes = [self.json_category_id_to_contiguous_id[c] for c in classes]
        classes = torch.tensor(classes)
        target.add_field("labels", classes)

        masks = [obj["segmentation"] for obj in anno]
        masks = SegmentationMask(masks, img.size)
        target.add_field("masks", masks)

        target = target.clip_to_image(remove_empty=True)

        if self.transforms is not None:
            img, target = self.transforms(img, target)

        return img, target, idx 
開發者ID:clw5180,項目名稱:remote_sensing_object_detection_2019,代碼行數:28,代碼來源:coco_origin.py

示例7: __getitem__

# 需要導入模塊: from maskrcnn_benchmark.structures import segmentation_mask [as 別名]
# 或者: from maskrcnn_benchmark.structures.segmentation_mask import SegmentationMask [as 別名]
def __getitem__(self, idx):
        img, anno = super(COCODataset, self).__getitem__(idx)

        # filter crowd annotations
        # TODO might be better to add an extra field
        anno = [obj for obj in anno if obj["iscrowd"] == 0]

        boxes = [obj["bbox"] for obj in anno]
        #boxes = torch.as_tensor(boxes).reshape(-1, 4)  # guard against no boxes
        boxes = torch.as_tensor(boxes).reshape(-1, 5)  # clw modify
        #target = BoxList(boxes, img.size, mode="xywh").convert("xyxy")
        target = BoxList(boxes, img.size, mode="xywh_angle")  # clw modify

        classes = [obj["category_id"] for obj in anno]
        classes = [self.json_category_id_to_contiguous_id[c] for c in classes]
        classes = torch.tensor(classes)
        target.add_field("labels", classes)

        masks = [obj["segmentation"] for obj in anno]
        masks = SegmentationMask(masks, img.size)
        target.add_field("masks", masks)

        target = target.clip_to_image(remove_empty=True)

        if self.transforms is not None:
            img, target = self.transforms(img, target)

        return img, target, idx 
開發者ID:clw5180,項目名稱:remote_sensing_object_detection_2019,代碼行數:30,代碼來源:coco.py

示例8: __getitem__

# 需要導入模塊: from maskrcnn_benchmark.structures import segmentation_mask [as 別名]
# 或者: from maskrcnn_benchmark.structures.segmentation_mask import SegmentationMask [as 別名]
def __getitem__(self, idx):
        #img, anno = super(COCODataset, self).__getitem__(idx)
        # use zipreader, change the function of super.getitem
        coco = self.coco
        img_id = self.ids[idx]
        ann_ids = coco.getAnnIds(imgIds=img_id)
        anno = coco.loadAnns(ann_ids)

        path = coco.loadImgs(img_id)[0]['file_name']
        # In philly cluster use zipreader instead Image.open
        #img = Image.open(os.path.join(self.root, path)).convert('RGB')
        img = zipreader.imread(os.path.join(self.root, path), \
                               cv2.IMREAD_COLOR | cv2.IMREAD_IGNORE_ORIENTATION)
        img = Image.fromarray(img)

        # filter crowd annotations
        # TODO might be better to add an extra field
        anno = [obj for obj in anno if obj["iscrowd"] == 0]

        boxes = [obj["bbox"] for obj in anno]
        boxes = torch.as_tensor(boxes).reshape(-1, 4)  # guard against no boxes
        target = BoxList(boxes, img.size, mode="xywh").convert("xyxy")

        classes = [obj["category_id"] for obj in anno]
        classes = [self.json_category_id_to_contiguous_id[c] for c in classes]
        classes = torch.tensor(classes)
        target.add_field("labels", classes)

        masks = [obj["segmentation"] for obj in anno]
        masks = SegmentationMask(masks, img.size)
        target.add_field("masks", masks)

        target = target.clip_to_image(remove_empty=True)

        if self.transforms is not None:
            img, target = self.transforms(img, target)

        return img, target, idx 
開發者ID:HRNet,項目名稱:HRNet-MaskRCNN-Benchmark,代碼行數:40,代碼來源:coco.py

示例9: __getitem__

# 需要導入模塊: from maskrcnn_benchmark.structures import segmentation_mask [as 別名]
# 或者: from maskrcnn_benchmark.structures.segmentation_mask import SegmentationMask [as 別名]
def __getitem__(self, idx):
        img_path = self.img_paths[idx]
        ann_path = self.ann_paths[idx]

        if self.mode == "mask":
            ann = torch.from_numpy(np.asarray(Image.open(ann_path)))
            # masks are represented with tensors
            boxes, segmentations, labels = self._processBinayMasks(ann)
        else:
            with open(ann_path, "r") as ann_file:
                ann = json.load(ann_file)
            # masks are represented with polygons
            boxes, segmentations, labels = self._processPolygons(ann)

        boxes, segmentations, labels = self._filterGT(boxes, segmentations, labels)

        if len(segmentations) == 0:
            empty_ann_path = self.get_img_info(idx)["ann_path"]
            print("EMPTY ENTRY:", empty_ann_path)
            # self.img_paths.pop(idx)
            # self.ann_paths.pop(idx)
            img, target, _ = self[(idx + 1) % len(self)]

            # just override this image with the next
            return img, target, idx

        img = Image.open(img_path)
        # Compose all into a BoxList instance
        target = BoxList(boxes, img.size, mode="xyxy")
        target.add_field("labels", torch.tensor(labels))
        masks = SegmentationMask(segmentations, img.size, mode=self.mode)
        target.add_field("masks", masks)
        if self.transforms is not None:
            img, target = self.transforms(img, target)

        return img, target, idx 
開發者ID:facebookresearch,項目名稱:maskrcnn-benchmark,代碼行數:38,代碼來源:cityscapes.py

示例10: __getitem__

# 需要導入模塊: from maskrcnn_benchmark.structures import segmentation_mask [as 別名]
# 或者: from maskrcnn_benchmark.structures.segmentation_mask import SegmentationMask [as 別名]
def __getitem__(self, idx):
        img, anno = super(COCODataset, self).__getitem__(idx)

        # filter crowd annotations
        # TODO might be better to add an extra field
        anno = [obj for obj in anno if obj["iscrowd"] == 0]

        boxes = [obj["bbox"] for obj in anno]
        boxes = torch.as_tensor(boxes).reshape(-1, 4)  # guard against no boxes
        target = BoxList(boxes, img.size, mode="xywh").convert("xyxy")

        classes = [obj["category_id"] for obj in anno]
        classes = [self.json_category_id_to_contiguous_id[c] for c in classes]
        classes = torch.tensor(classes)
        target.add_field("labels", classes)

#         masks = [obj["segmentation"] for obj in anno]
#         masks = SegmentationMask(masks, img.size)
#         target.add_field("masks", masks)

        target = target.clip_to_image(remove_empty=True)

        if self.transforms is not None:
            img, target = self.transforms(img, target)

        return img, target, idx 
開發者ID:zhangxiaosong18,項目名稱:FreeAnchor,代碼行數:28,代碼來源:coco.py

示例11: __getitem__

# 需要導入模塊: from maskrcnn_benchmark.structures import segmentation_mask [as 別名]
# 或者: from maskrcnn_benchmark.structures.segmentation_mask import SegmentationMask [as 別名]
def __getitem__(self, idx):
        img, anno = super(COCODataset, self).__getitem__(idx)

        # filter crowd annotations
        # TODO might be better to add an extra field
        anno = [obj for obj in anno if obj["iscrowd"] == 0]

        boxes = [obj["bbox"] for obj in anno]
        boxes = torch.as_tensor(boxes).reshape(-1, 4)  # guard against no boxes
        target = BoxList(boxes, img.size, mode="xywh").convert("xyxy")

        classes = [obj["category_id"] for obj in anno]
        classes = [self.json_category_id_to_contiguous_id[c] for c in classes]
        classes = torch.tensor(classes)
        target.add_field("labels", classes)

        # masks = [obj["segmentation"] for obj in anno]
        # masks = SegmentationMask(masks, img.size, mode='poly')
        # target.add_field("masks", masks)

        if anno and "keypoints" in anno[0]:
            keypoints = [obj["keypoints"] for obj in anno]
            keypoints = PersonKeypoints(keypoints, img.size)
            target.add_field("keypoints", keypoints)

        target = target.clip_to_image(remove_empty=True)

        if self.transforms is not None:
            img, target = self.transforms(img, target)

        return img, target, idx 
開發者ID:HuangQinJian,項目名稱:DF-Traffic-Sign-Identification,代碼行數:33,代碼來源:coco.py

示例12: __getitem__

# 需要導入模塊: from maskrcnn_benchmark.structures import segmentation_mask [as 別名]
# 或者: from maskrcnn_benchmark.structures.segmentation_mask import SegmentationMask [as 別名]
def __getitem__(self, idx):
        img, anno = super(COCODataset, self).__getitem__(idx)
        # ########################## add by hui ########################################
        img_info = self.get_img_info(idx)
        if 'corner' in img_info:
            img = img.crop(img_info['corner'])
        ################################################################################

        # filter crowd annotations
        # TODO might be better to add an extra field
        anno = [obj for obj in anno if obj["iscrowd"] == 0]
        # ######################### add by hui ####################################
        if self.filter_ignore and anno and "ignore" in anno[0]:  # filter ignore out
            anno = [obj for obj in anno if not obj["ignore"]]
        ###########################################################################

        boxes = [obj["bbox"] for obj in anno]
        boxes = torch.as_tensor(boxes).reshape(-1, 4)  # guard against no boxes
        target = BoxList(boxes, img.size, mode="xywh").convert("xyxy")

        classes = [obj["category_id"] for obj in anno]
        classes = [self.json_category_id_to_contiguous_id[c] for c in classes]
        classes = torch.tensor(classes)
        target.add_field("labels", classes)

        masks = [obj["segmentation"] for obj in anno]
        masks = SegmentationMask(masks, img.size)
        target.add_field("masks", masks)

        if anno and "keypoints" in anno[0]:
            keypoints = [obj["keypoints"] for obj in anno]
            keypoints = PersonKeypoints(keypoints, img.size)
            target.add_field("keypoints", keypoints)

        target = target.clip_to_image(remove_empty=True)

        if self.transforms is not None:
            img, target = self.transforms(img, target)

        return img, target, idx 
開發者ID:ucas-vg,項目名稱:TinyBenchmark,代碼行數:42,代碼來源:coco.py

示例13: __getitem__

# 需要導入模塊: from maskrcnn_benchmark.structures import segmentation_mask [as 別名]
# 或者: from maskrcnn_benchmark.structures.segmentation_mask import SegmentationMask [as 別名]
def __getitem__(self, idx):
        #img, anno = super(COCODataset, self).__getitem__(idx)
        coco = self.coco
        img_id = self.ids[idx]
        ann_ids = coco.getAnnIds(imgIds=img_id)
        anno = coco.loadAnns(ann_ids)

        path = coco.loadImgs(img_id)[0]['file_name']

        if isinstance(self.root, list):
            root = [r for r in self.root if path.split('_')[1] in r][0]
        else:
            root = self.root
        img = Image.open(os.path.join(root, path)).convert('RGB')
        if self.transform is not None:
            img = self.transform(img)

        if self.target_transform is not None:
            anno = self.target_transform(anno)

        # filter crowd annotations
        # TODO might be better to add an extra field
        anno = [obj for obj in anno if obj["iscrowd"] == 0]

        boxes = [obj["bbox"] for obj in anno]
        boxes = torch.as_tensor(boxes).reshape(-1, 4)  # guard against no boxes
        target = BoxList(boxes, img.size, mode="xywh").convert("xyxy")

        classes = [obj["category_id"] for obj in anno]
        classes = [self.json_category_id_to_contiguous_id[c] for c in classes]
        classes = torch.tensor(classes)
        target.add_field("labels", classes)

        if anno and "segmentation" in anno[0]:
            masks = [obj["segmentation"] for obj in anno]
            masks = SegmentationMask(masks, img.size, mode='poly')
            target.add_field("masks", masks)

        if anno and "keypoints" in anno[0]:
            keypoints = [obj["keypoints"] for obj in anno]
            keypoints = PersonKeypoints(keypoints, img.size)
            target.add_field("keypoints", keypoints)

        target = target.clip_to_image(remove_empty=True)

        if self._transforms is not None:
            img, target = self._transforms(img, target)

        return img, target, idx 
開發者ID:megvii-model,項目名稱:DetNAS,代碼行數:51,代碼來源:coco.py

示例14: __getitem__

# 需要導入模塊: from maskrcnn_benchmark.structures import segmentation_mask [as 別名]
# 或者: from maskrcnn_benchmark.structures.segmentation_mask import SegmentationMask [as 別名]
def __getitem__(self, idx):
        if self.mode == 0:
            img, anno = super(COCODataset, self).__getitem__(idx)
            # filter crowd annotations
            # TODO might be better to add an extra field
            anno = [obj for obj in anno if obj["iscrowd"] == 0]

            boxes = [obj["bbox"] for obj in anno]
            boxes = torch.as_tensor(boxes).reshape(-1, 4)  # guard against no boxes
            target = BoxList(boxes, img.size, mode="xywh").convert("xyxy")

            classes = [obj["category_id"] for obj in anno]
            classes = [self.json_category_id_to_contiguous_id[c] for c in classes]
            classes = torch.tensor(classes)
            target.add_field("labels", classes)

            masks = [obj["segmentation"] for obj in anno]
            masks = SegmentationMask(masks, img.size)
            target.add_field("masks", masks)

            target = target.clip_to_image(remove_empty=True)

            if self.transforms is not None:
                img, target = self.transforms(img, target)
            return img, target, idx

        elif self.mode == 1:
            img_id = self.ids[index]
            feature_list = torch.load(self._split_feature % (self.backbone, self.resolution, img_id)
                            , map_location=torch.device("cpu"))
            if self.special_deal:
                label = torch.load(self._split_label % (self.backbone, self.resolution, img_id)
                                , map_location=torch.device("cpu"))
                reg = torch.load(self._split_reg % (self.backbone, self.resolution, img_id)
                                , map_location=torch.device("cpu"))
                return feature_list, label, reg, index
            else:
                target = torch.load(self._split_target % (self.backbone, self.resolution, img_id)
                                , map_location=torch.device("cpu"))
                return feature_list, target, index
        else:
            raise ValueError("Mode {} do not support now".format(self.mode)) 
開發者ID:Lausannen,項目名稱:NAS-FCOS,代碼行數:44,代碼來源:coco.py


注:本文中的maskrcnn_benchmark.structures.segmentation_mask.SegmentationMask方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。