Exemplo n.º 1
0
    def from_config(cls, cfg):
        augs = [
            T.ResizeShortestEdge(
                cfg.INPUT.MIN_SIZE_TRAIN,
                cfg.INPUT.MAX_SIZE_TRAIN,
                cfg.INPUT.MIN_SIZE_TRAIN_SAMPLING,
            )
        ]
        if cfg.INPUT.CROP.ENABLED:
            augs.append(T.RandomCrop(cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE))
        augs.append(T.RandomFlip())

        # Assume always applies to the training set.
        dataset_names = cfg.DATASETS.TRAIN
        meta = MetadataCatalog.get(dataset_names[0])
        panoptic_target_generator = PanopticDeepLabTargetGenerator(
            ignore_label=meta.ignore_label,
            thing_ids=list(meta.thing_dataset_id_to_contiguous_id.values()),
            sigma=cfg.INPUT.GAUSSIAN_SIGMA,
            ignore_stuff_in_offset=cfg.INPUT.IGNORE_STUFF_IN_OFFSET,
            small_instance_area=cfg.INPUT.SMALL_INSTANCE_AREA,
            small_instance_weight=cfg.INPUT.SMALL_INSTANCE_WEIGHT,
            ignore_crowd_in_semantic=cfg.INPUT.IGNORE_CROWD_IN_SEMANTIC,
        )

        ret = {
            "augmentations": augs,
            "image_format": cfg.INPUT.FORMAT,
            "panoptic_target_generator": panoptic_target_generator,
        }
        return ret
    def __init__(self, cfg, is_train=True):
        if cfg.INPUT.CROP.ENABLED:
            self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE)
            logging.getLogger(__name__).info("CropGen used in training: " + str(self.crop_gen))
        else:
            self.crop_gen = None

        self.tfm_gens = utils.build_transform_gen(cfg, is_train)

        # fmt: off
        self.img_format = cfg.INPUT.FORMAT
        self.mask_on = cfg.MODEL.MASK_ON
        self.mask_format = cfg.INPUT.MASK_FORMAT
        self.keypoint_on = cfg.MODEL.KEYPOINT_ON
        self.load_proposals = cfg.MODEL.LOAD_PROPOSALS
        # fmt: on
        if self.keypoint_on and is_train:
            # Flip only makes sense in training
            self.keypoint_hflip_indices = utils.create_keypoint_hflip_indices(cfg.DATASETS.TRAIN)
        else:
            self.keypoint_hflip_indices = None

        if self.load_proposals:
            self.min_box_side_len = cfg.MODEL.PROPOSAL_GENERATOR.MIN_SIZE
            self.proposal_topk = (
                cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TRAIN
                if is_train
                else cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TEST
            )
        self.is_train = is_train
Exemplo n.º 3
0
    def __init__(self, cfg, is_train=True):
        # build_transform_gen
        logger = logging.getLogger(__name__)

        # random crop augmentation
        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE,
                                         cfg.INPUT.CROP.SIZE)
            logging.getLogger(__name__).info("CropGen used in training: " +
                                             str(self.crop_gen))
        else:
            self.crop_gen = None

        self.img_format = cfg.INPUT.FORMAT
        self.is_train = is_train
        self.mask_type = cfg.INPUT.TRAIN_MASK_TYPE

        # TODO: configure it
        self.min_num_vertex = 4
        self.max_num_vertex = 12
        self.mean_angle = 2 * math.pi / 5  # 72 deg
        self.angle_range = 2 * math.pi / 15  # 24 deg
        self.min_width = 12
        self.max_width = 40

        assert self.mask_type in ["random_regular", "random_irregular"]
    def from_config(cls, cfg, is_train: bool = True):
        augs = utils.build_augmentation(cfg, is_train)
        if cfg.INPUT.CROP.ENABLED and is_train:
            augs.insert(0, T.RandomCrop(cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE))
            recompute_boxes = cfg.MODEL.MASK_ON
        else:
            recompute_boxes = False

        ret = {
            "is_train": is_train,
            "augmentations": augs,
            "image_format": cfg.INPUT.FORMAT,
            "use_instance_mask": cfg.MODEL.MASK_ON,
            "instance_mask_format": cfg.INPUT.MASK_FORMAT,
            "use_keypoint": cfg.MODEL.KEYPOINT_ON,
            "recompute_boxes": recompute_boxes,
        }
        if cfg.MODEL.KEYPOINT_ON:
            ret["keypoint_hflip_indices"] = utils.create_keypoint_hflip_indices(cfg.DATASETS.TRAIN)

        if cfg.MODEL.LOAD_PROPOSALS:
            ret["precomputed_proposal_topk"] = (
                cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TRAIN
                if is_train
                else cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TEST
            )
        return ret
Exemplo n.º 5
0
    def __init__(self, cfg, is_train=True):
        self.augmentation = utils.build_augmentation(cfg, is_train)
        if cfg.INPUT.CROP.ENABLED and is_train:
            self.augmentation.insert(
                0, T.RandomCrop(cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE))
            logging.getLogger(__name__).info("Cropping used in training: " +
                                             str(self.augmentation[0]))
            self.compute_tight_boxes = True
        else:
            self.compute_tight_boxes = False

        # fmt: off
        self.img_format = cfg.INPUT.FORMAT
        self.mask_on = cfg.MODEL.MASK_ON
        self.mask_format = cfg.INPUT.MASK_FORMAT
        self.keypoint_on = cfg.MODEL.KEYPOINT_ON
        self.load_proposals = cfg.MODEL.LOAD_PROPOSALS
        # fmt: on
        if self.keypoint_on and is_train:
            # Flip only makes sense in training
            self.keypoint_hflip_indices = utils.create_keypoint_hflip_indices(
                cfg.DATASETS.TRAIN)
        else:
            self.keypoint_hflip_indices = None

        if self.load_proposals:
            self.proposal_min_box_size = cfg.MODEL.PROPOSAL_GENERATOR.MIN_SIZE
            self.proposal_topk = (cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TRAIN
                                  if is_train else
                                  cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TEST)
        self.is_train = is_train
Exemplo n.º 6
0
    def __init__(self, cfg, is_train=True):
        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE,
                                         cfg.INPUT.CROP.SIZE)
            logging.getLogger(__name__).info("CropGen used in training: " +
                                             str(self.crop_gen))
        else:
            self.crop_gen = None

        self.tfm_gens = utils.build_transform_gen(cfg, is_train)

        if cfg.INPUT.COLOR_AUG_SSD:
            self.tfm_gens.append(
                ColorAugSSDTransform(img_format=cfg.INPUT.FORMAT))
            logging.getLogger(
                __name__).info("Color augmnetation used in training: " +
                               str(self.tfm_gens[-1]))

        # fmt: off
        self.img_format = cfg.INPUT.FORMAT
        self.single_category_max_area = cfg.INPUT.CROP.SINGLE_CATEGORY_MAX_AREA
        self.ignore_value = cfg.MODEL.SEM_SEG_HEAD.IGNORE_VALUE
        # fmt: on

        self.is_train = is_train
Exemplo n.º 7
0
    def __call__(self, dataset_dict):

        self.tfm_gens = []

        dataset_dict = deepcopy(dataset_dict)
        image = utils.read_image(dataset_dict["file_name"],
                                 format=self.img_format)
        utils.check_image_size(dataset_dict, image)

        if self.is_train:
            # Crop
            if 'crop' in self.da.keys():
                crop_gen = T.RandomCrop(self.da['crop']['type'],
                                        self.da['crop']['size'])
                self.tfm_gens.append(crop_gen)
            # Horizontal flip
            if 'flip' in self.da.keys():
                flip_gen = T.RandomFlip(
                    prob=self.da['flip']['prob'],
                    horizontal=self.da['flip']['horizontal'],
                    vertical=self.da['flip']['vertical'])
                self.tfm_gens.append(flip_gen)

        image, transforms = T.apply_transform_gens(self.tfm_gens, image)

        image_shape = image.shape[:2]  # h, w

        dataset_dict["image"] = torch.as_tensor(
            np.ascontiguousarray(image.transpose(2, 0, 1)))

        if not self.is_train:
            dataset_dict.pop("annotations", None)
            dataset_dict.pop("sem_seg_file_name", None)
            return dataset_dict

        if "annotations" in dataset_dict:
            for anno in dataset_dict["annotations"]:
                if not self.mask_on:
                    anno.pop("segmentation", None)
                if not self.keypoint_on:
                    anno.pop("keypoints", None)

            annos = [
                utils.transform_instance_annotations(
                    obj,
                    transforms,
                    image_shape,
                    keypoint_hflip_indices=self.keypoint_hflip_indices)
                for obj in dataset_dict.pop("annotations")
                if obj.get("iscrowd", 0) == 0
            ]
            instances = utils.annotations_to_instances(
                annos, image_shape, mask_format=self.mask_format)

            if self.crop_gen and instances.has("gt_masks"):
                instances.gt_boxes = instances.gt_masks.get_bounding_boxes()
            dataset_dict["instances"] = utils.filter_empty_instances(instances)

        return dataset_dict
Exemplo n.º 8
0
 def __init__(self, cfg, is_train=True):
     self.aug = self._get_aug(cfg.INPUT.ALBUMENTATIONS)
     self.img_format = cfg.INPUT.FORMAT
     self.resize_gen = utils.build_transform_gen(cfg, is_train)
     if cfg.INPUT.CROP.ENABLED and is_train:
         self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE)
     else:
         self.crop_gen = None
    def __init__(self, cfg, is_train=True):
        assert cfg.MODEL.MASK_ON, '今回はセグメンテーションのみを対象にする'
        assert not cfg.MODEL.KEYPOINT_ON, 'キーポイントは扱わない'
        assert not cfg.MODEL.LOAD_PROPOSALS, 'pre-computed proposals っていうのがよくわからん・・・・とりあえず無効前提で'

        self.cont_gen = None
        self.bright_gen = None
        self.sat_gen = None
        self.cutout_gen = None
        self.extent_gen = None
        self.crop_gen = None
        self.rotate_gen = None
        self.shear_gen = None

        if is_train:
            if cfg.INPUT.CONTRAST.ENABLED:
                self.cont_gen = T.RandomContrast(cfg.INPUT.CONTRAST.RANGE[0],
                                                 cfg.INPUT.CONTRAST.RANGE[1])
                logging.getLogger(__name__).info('ContGen used in training.')
            if cfg.INPUT.BRIGHTNESS.ENABLED:
                self.bright_gen = T.RandomBrightness(
                    cfg.INPUT.BRIGHTNESS.RANGE[0],
                    cfg.INPUT.BRIGHTNESS.RANGE[1])
                logging.getLogger(__name__).info('BrightGen used in training.')
            if cfg.INPUT.SATURATION.ENABLED:
                self.sat_gen = T.RandomSaturation(
                    cfg.INPUT.SATURATION.RANGE[0],
                    cfg.INPUT.SATURATION.RANGE[1])
                logging.getLogger(__name__).info('SatGen used in training.')
            if cfg.INPUT.CUTOUT.ENABLED:
                self.cutout_gen = RandomCutout(cfg.INPUT.CUTOUT.NUM_HOLE_RANGE,
                                               cfg.INPUT.CUTOUT.RADIUS_RANGE,
                                               cfg.INPUT.CUTOUT.COLOR_RANGE)
                logging.getLogger(__name__).info('CutoutGen used in training.')
            if cfg.INPUT.EXTENT.ENABLED:
                self.extent_gen = T.RandomExtent(
                    scale_range=(1, 1),
                    shift_range=cfg.INPUT.EXTENT.SHIFT_RANGE)
                logging.getLogger(__name__).info('ExtentGen used in training.')
            if cfg.INPUT.CROP.ENABLED:
                self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE,
                                             cfg.INPUT.CROP.SIZE)
                logging.getLogger(__name__).info('CropGen used in training: ' +
                                                 str(self.crop_gen))
            if cfg.INPUT.ROTATE.ENABLED:
                self.rotate_gen = T.RandomRotation(cfg.INPUT.ROTATE.ANGLE,
                                                   expand=False)
                logging.getLogger(__name__).info('RotateGen used in training.')
            if cfg.INPUT.SHEAR.ENABLED:
                self.shear_gen = RandomShear(cfg.INPUT.SHEAR.ANGLE_H_RANGE,
                                             cfg.INPUT.SHEAR.ANGLE_V_RANGE)
                logging.getLogger(__name__).info('ShearGen used in training.')

        self.tfm_gens = utils.build_transform_gen(cfg, is_train)

        self.img_format = cfg.INPUT.FORMAT
        self.mask_format = cfg.INPUT.MASK_FORMAT
        self.is_train = is_train
Exemplo n.º 10
0
 def __init__(self, cfg, json_file_path, is_train=True):
     super().__init__(cfg, is_train=is_train)
     self.aug_handler = AugHandler.load_from_path(json_file_path)
     if is_train:
         self.tfm_gens = self.tfm_gens[:-1]
         #self.tfm_gens.insert(0, T.RandomFlip(prob=0.5, horizontal=True,  vertical=False))
         self.tfm_gens.insert(0, T.RandomCrop("relative_range", (0.8, 1.0)))
         self.tfm_gens.insert(
             0, T.RandomRotation([0, 90, 180, 270], sample_style="choice"))
Exemplo n.º 11
0
    def test_print_transform_gen(self):
        t = T.RandomCrop("relative", (100, 100))
        self.assertTrue(str(t) == "RandomCrop(crop_type='relative', crop_size=(100, 100))")

        t = T.RandomFlip(prob=0.5)
        self.assertTrue(str(t) == "RandomFlip(prob=0.5)")

        t = T.RandomFlip()
        self.assertTrue(str(t) == "RandomFlip()")
def build_sem_seg_train_aug(cfg):
    augs = [
        T.ResizeShortestEdge(cfg.INPUT.MIN_SIZE_TRAIN,
                             cfg.INPUT.MAX_SIZE_TRAIN,
                             cfg.INPUT.MIN_SIZE_TRAIN_SAMPLING)
    ]
    if cfg.INPUT.CROP.ENABLED:
        augs.append(T.RandomCrop(cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE))
    augs.append(T.RandomFlip())
    return augs
Exemplo n.º 13
0
def build_train_aug(cfg):
    augs = [
        T.ResizeShortestEdge(cfg.INPUT.MIN_SIZE_TRAIN, cfg.INPUT.MAX_SIZE_TRAIN, cfg.INPUT.MIN_SIZE_TRAIN_SAMPLING),
        T.RandomContrast(0.5, 1.5),
        T.RandomBrightness(0.5, 1.5),
        T.RandomSaturation(0.5, 1.5),
        T.RandomFlip(),
    ]
    if cfg.INPUT.CROP.ENABLED:
        augs.insert(0, T.RandomCrop(cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE))
    return augs
Exemplo n.º 14
0
    def __init__(self, cfg, is_train=True):

        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE,
                                         cfg.INPUT.CROP.SIZE)
            logging.getLogger(__name__).info("CropGen used in training: " +
                                             str(self.crop_gen))
        else:
            self.crop_gen = None

        if is_train:
            min_size = cfg.INPUT.MIN_SIZE_TRAIN
            max_size = cfg.INPUT.MAX_SIZE_TRAIN
            sample_style = cfg.INPUT.MIN_SIZE_TRAIN_SAMPLING
        else:
            min_size = cfg.INPUT.MIN_SIZE_TEST
            max_size = cfg.INPUT.MAX_SIZE_TEST
            sample_style = "choice"
        if sample_style == "range":
            assert len(
                min_size
            ) == 2, "more than 2 ({}) min_size(s) are provided for ranges".format(
                len(min_size))

        logger = logging.getLogger(__name__)
        self.tfm_gens = []
        self.tfm_gens.append(
            T.ResizeShortestEdge(min_size, max_size, sample_style))
        # if self.is_train:
        #     self.tfm_gens.append(T.RandomBrightness())
        #     self.tfm_gens.append(T.RandomContrast())
        #     self.tfm_gens.append(T.RandomLighting())
        #     self.tfm_gens.append(T.RandomSaturation())

        # fmt: off
        self.img_format = cfg.INPUT.FORMAT
        self.mask_on = cfg.MODEL.MASK_ON
        self.mask_format = cfg.INPUT.MASK_FORMAT
        self.keypoint_on = cfg.MODEL.KEYPOINT_ON
        self.load_proposals = cfg.MODEL.LOAD_PROPOSALS
        # fmt: on
        if self.keypoint_on and is_train:
            # Flip only makes sense in training
            self.keypoint_hflip_indices = utils.create_keypoint_hflip_indices(
                cfg.DATASETS.TRAIN)
        else:
            self.keypoint_hflip_indices = None

        if self.load_proposals:
            self.min_box_side_len = cfg.MODEL.PROPOSAL_GENERATOR.MIN_SIZE
            self.proposal_topk = (cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TRAIN
                                  if is_train else
                                  cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TEST)
        self.is_train = is_train
 def build_train_loader(cls, cfg):
     return build_detection_train_loader(
         cfg,
         mapper=DatasetMapper(
             cfg,
             is_train=True,
             augmentations=[
                 # T.RandomBrightness(0.9, 1.1),
                 # T.RandomFlip(prob=0.5, horizontal=True, vertical=False),
                 T.RandomCrop("absolute", (640, 640))
             ]))
Exemplo n.º 16
0
    def __init__(self, cfg, is_train=True):
        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = d2_transforms.RandomCrop(
                    cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE)
            logging.getLogger(__name__).info(
                    "CropGen used in training: " + str(self.crop_gen))
        else:
            self.crop_gen = None

        self.tfm_gens = d2_dutils.build_transform_gen(cfg, is_train)
        self.is_train = is_train
Exemplo n.º 17
0
    def __init__(self, cfg, is_train=True):
        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE)
            # logging.getLogger(__name__).info("CropGen used in training: " + str(self.crop_gen))
        else:
            self.crop_gen = None

        self.tfm_gens = [
                         T.RandomBrightness(0.5, 1.6),
                         T.RandomContrast(0.5, 1),
                         T.RandomSaturation(0.5, 1),
                         T.RandomRotation(angle=[-90, 90]),
                         T.RandomFlip(horizontal=True, vertical=False),
                         T.RandomCrop('relative_range', (0.4, 0.6)),
                         T.Resize((640,640)),
                         # CutOut()
                         ]

        # self.tfm_gens = utils.build_transform_gen(cfg, is_train)

        # fmt: off
        self.img_format = cfg.INPUT.FORMAT
        self.mask_on = cfg.MODEL.MASK_ON
        self.mask_format = cfg.INPUT.MASK_FORMAT
        self.keypoint_on = cfg.MODEL.KEYPOINT_ON
        self.load_proposals = cfg.MODEL.LOAD_PROPOSALS
        # fmt: on
        if self.keypoint_on and is_train:
            # Flip only makes sense in training
            self.keypoint_hflip_indices = utils.create_keypoint_hflip_indices(cfg.DATASETS.TRAIN)
        else:
            self.keypoint_hflip_indices = None

        if self.load_proposals:
            self.min_box_side_len = cfg.MODEL.PROPOSAL_GENERATOR.MIN_SIZE
            self.proposal_topk = (
                cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TRAIN
                if is_train
                else cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TEST
            )
        self.is_train = is_train
Exemplo n.º 18
0
    def test_print_augmentation(self):
        t = T.RandomCrop("relative", (100, 100))
        self.assertEqual(str(t), "RandomCrop(crop_type='relative', crop_size=(100, 100))")

        t0 = T.RandomFlip(prob=0.5)
        self.assertEqual(str(t0), "RandomFlip(prob=0.5)")

        t1 = T.RandomFlip()
        self.assertEqual(str(t1), "RandomFlip()")

        t = T.AugmentationList([t0, t1])
        self.assertEqual(str(t), f"AugmentationList[{t0}, {t1}]")
Exemplo n.º 19
0
    def __init__(self, cfg, is_train=True):
        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE,
                                         cfg.INPUT.CROP.SIZE)
            logging.getLogger(__name__).info("CropGen used in training: " +
                                             str(self.crop_gen))
        else:
            self.crop_gen = None

        self.tfm_gens = utils.build_transform_gen(cfg, is_train)

        # fmt: off
        self.img_format = cfg.INPUT.FORMAT
        self.mask_on = cfg.MODEL.MASK_ON
        self.mask_format = cfg.INPUT.MASK_FORMAT
        self.keypoint_on = cfg.MODEL.KEYPOINT_ON
        self.load_proposals = cfg.MODEL.LOAD_PROPOSALS

        self.few_shot = cfg.INPUT.FS.FEW_SHOT
        self.support_way = cfg.INPUT.FS.SUPPORT_WAY
        self.support_shot = cfg.INPUT.FS.SUPPORT_SHOT
        # fmt: on
        if self.keypoint_on and is_train:
            # Flip only makes sense in training
            self.keypoint_hflip_indices = utils.create_keypoint_hflip_indices(
                cfg.DATASETS.TRAIN)
        else:
            self.keypoint_hflip_indices = None

        if self.load_proposals:
            self.proposal_min_box_size = cfg.MODEL.PROPOSAL_GENERATOR.MIN_SIZE
            self.proposal_topk = (cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TRAIN
                                  if is_train else
                                  cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TEST)
        self.is_train = is_train

        if self.is_train:
            # support_df
            self.support_on = True
            if self.few_shot:
                self.support_df = pd.read_pickle(
                    "./datasets/coco/10_shot_support_df.pkl")
            else:
                self.support_df = pd.read_pickle(
                    "./datasets/coco/train_support_df.pkl")

            metadata = MetadataCatalog.get('coco_2017_train')
            # unmap the category mapping ids for COCO
            reverse_id_mapper = lambda dataset_id: metadata.thing_dataset_id_to_contiguous_id[
                dataset_id]  # noqa
            self.support_df['category_id'] = self.support_df[
                'category_id'].map(reverse_id_mapper)
Exemplo n.º 20
0
    def __init__(self, cfg, is_train=True, image_loader=None, tfm_gens=None):
        self.tfm_gens = (tfm_gens if tfm_gens is not None else
                         utils.build_transform_gen(cfg, is_train))

        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE,
                                         cfg.INPUT.CROP.SIZE)
            # D2GO NOTE: when INPUT.CROP.ENABLED, don't allow using RandomCropOp
            assert all(not isinstance(gen, T.RandomCrop)
                       for gen in self.tfm_gens)
        else:
            self.crop_gen = None

        # fmt: off
        self.img_format = cfg.INPUT.FORMAT  # noqa
        self.mask_on = cfg.MODEL.MASK_ON  # noqa
        self.mask_format = cfg.INPUT.MASK_FORMAT  # noqa
        self.keypoint_on = cfg.MODEL.KEYPOINT_ON  # noqa
        # fmt: on
        if self.keypoint_on and is_train:
            # Flip only makes sense in training
            self.keypoint_hflip_indices = utils.create_keypoint_hflip_indices(
                cfg.DATASETS.TRAIN)
        else:
            self.keypoint_hflip_indices = None

        self.load_proposals = cfg.MODEL.LOAD_PROPOSALS
        if self.load_proposals:
            self.proposal_min_box_size = cfg.MODEL.PROPOSAL_GENERATOR.MIN_SIZE
            self.proposal_topk = (cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TRAIN
                                  if is_train else
                                  cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TEST)

        self.is_train = is_train

        # Setup image loader:
        self.image_loader = image_loader
        self.backfill_size = cfg.D2GO_DATA.MAPPER.BACKFILL_SIZE
        self.retry = cfg.D2GO_DATA.MAPPER.RETRY
        self.catch_exception = cfg.D2GO_DATA.MAPPER.CATCH_EXCEPTION

        if self.backfill_size:
            if cfg.DATALOADER.ASPECT_RATIO_GROUPING:
                logger.warning(
                    "ASPECT_RATIO_GROUPING may not work if image's width & height"
                    " are not given in json dataset when calling extended_coco_load,"
                    " if you encounter issue, consider disable ASPECT_RATIO_GROUPING."
                )

        self._error_count = 0
        self._total_counts = 0
        self._error_types = {}
Exemplo n.º 21
0
    def __init__(self, cfg, is_train=True):
        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = [
                T.ResizeShortestEdge([400, 500, 600], sample_style="choice"),
                T.RandomCrop(cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE),
            ]
        else:
            self.crop_gen = None

        assert not cfg.MODEL.MASK_ON, "Mask is not supported"

        self.tfm_gens = build_transform_gen(cfg, is_train)
        logging.getLogger("detectron2").info(
            "Full TransformGens used in pre-process: {}, crop: {}".format(
                str(self.tfm_gens), str(self.crop_gen)))

        self.img_format = cfg.INPUT.FORMAT
        self.zip_read = cfg.INPUT.ZIP_READ
        self.is_train = is_train
        self.max_frame_dist = cfg.MODEL.DETR.MAX_FRAME_DIST
        self.ignore_same = cfg.MODEL.DETR.IGNORE_SAME

        # video2img --> 爆内存问题可能是出在这边,每次得释放掉 / 考虑放到builtin试试.
        if self.is_train:
            self.dataset_dicts = get_detection_dataset_dicts(
                cfg.DATASETS.TRAIN,
                filter_empty=cfg.DATALOADER.FILTER_EMPTY_ANNOTATIONS,
                min_keypoints=cfg.MODEL.ROI_KEYPOINT_HEAD.
                MIN_KEYPOINTS_PER_IMAGE if cfg.MODEL.KEYPOINT_ON else 0,
                proposal_files=cfg.DATASETS.PROPOSAL_FILES_TRAIN
                if cfg.MODEL.LOAD_PROPOSALS else None,
            )
            assert len(cfg.DATASETS.TRAIN) == 1, logging.\
                info("Only support ONE dataset each time, however, "
                     "there are {} datasets now.".format(len(cfg.DATASETS.TRAIN)))
            self.video_to_images = MetadataCatalog.get(
                cfg.DATASETS.TRAIN[0]).video_to_images
            self.image_to_index = MetadataCatalog.get(
                cfg.DATASETS.TRAIN[0]).image_to_index
        else:
            self.dataset_dicts = get_detection_dataset_dicts(
                cfg.DATASETS.TEST,
                filter_empty=False,
                min_keypoints=0,
                proposal_files=None)
            assert len(cfg.DATASETS.TEST) == 1, logging. \
                info("Only support ONE dataset each time, however, "
                     "there are {} datasets now.".format(len(cfg.DATASETS.TEST)))
            self.video_to_images = MetadataCatalog.get(
                cfg.DATASETS.TEST[0]).video_to_images
            self.image_to_index = MetadataCatalog.get(
                cfg.DATASETS.TEST[0]).image_to_index
Exemplo n.º 22
0
 def build_train_loader(cls, cfg):
     return build_detection_train_loader(
         cfg,
         mapper=DatasetMapper(cfg,
                              is_train=True,
                              augmentations=[
                                  T.RandomCrop("absolute_range",
                                               (300, 600)),
                                  T.RandomRotation(random.randrange(0,
                                                                    360)),
                                  T.RandomContrast(0.5, 1.5),
                                  T.RandomSaturation(0.5, 1.5)
                              ]))
Exemplo n.º 23
0
def build_Pt_collect_train_aug(cfg):
    augs = [
        T.ResizeShortestEdge(cfg.INPUT.MIN_SIZE_TRAIN,
                             cfg.INPUT.MAX_SIZE_TRAIN,
                             cfg.INPUT.MIN_SIZE_TRAIN_SAMPLING)
    ]
    if cfg.INPUT.CROP.ENABLED:
        augs.append(T.RandomCrop(
            cfg.INPUT.CROP.TYPE,
            cfg.INPUT.CROP.SIZE,
        ))
        augs.append(T.RandomRotation(angle=[-10, 10], ))
    augs.append(T.RandomFlip())
    return augs
Exemplo n.º 24
0
    def __init__(self, cfg, is_train=True):
        self.crop_gen = [
            T.ResizeShortestEdge([400, 500, 600], sample_style="choice"),
            T.RandomCrop(cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE),
        ]

        self.tfm_gens = build_transform_gen(cfg, is_train)
        logging.getLogger(__name__).info(
            "Full TransformGens used in training: {}, crop: {}".format(str(self.tfm_gens), 
            str(self.crop_gen))
        )

        self.img_format = cfg.INPUT.FORMAT
        self.is_train = is_train
Exemplo n.º 25
0
 def __init__(self, cfg, is_train=True):
     if cfg.INPUT.CROP.ENABLED and is_train:
         self.crop_gen = [
             T.ResizeShortestEdge([400, 500, 600], sample_style='choice'),
             T.RandomCrop(cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE)
         ]
     else:
         self.crop_gen = None
     self.mask_on = cfg.MODEL.MASK_ON
     self.tfm_gens = build_transform_gen(cfg, is_train)
     logging.getLogger(__name__).info(
         'Full TransformGens used in training: {}, crop: {}'.format(
             str(self.tfm_gens), str(self.crop_gen)))
     self.img_format = cfg.INPUT.FORMAT
     self.is_train = is_train
Exemplo n.º 26
0
 def build_train_loader1(cls, cfg: CfgNode, mapper=None):
     if mapper is None:
         mapper = DatasetMapper(
             cfg=cfg,
             is_train=True,
             augmentations=[
                 T.ResizeShortestEdge(
                     cfg.INPUT.MIN_SIZE_TRAIN,
                     cfg.INPUT.MAX_SIZE_TRAIN,
                     cfg.INPUT.MIN_SIZE_TRAIN_SAMPLING,
                 ),
                 T.RandomCrop(cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE),
                 T.RandomFlip(),
             ],
         )
     return build_detection_train_loader(cfg, mapper=mapper)
Exemplo n.º 27
0
    def __init__(self, cfg, is_train=True):
        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = [
                T.ResizeShortestEdge([400, 500, 600], sample_style="choice"),
                T.RandomCrop(cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE),
            ]
        else:
            self.crop_gen = None

        self.tfm_gens = build_transform_gen(cfg, is_train)
        logging.getLogger("detectron2.data.dataset_mapper").info(
            "Full TransformGens used in training: {}, crop: {}".format(
                str(self.tfm_gens), str(self.crop_gen)))

        self.img_format = cfg.INPUT.FORMAT
        self.is_train = is_train
Exemplo n.º 28
0
    def __init__(self, cfg, is_train=True):
        super().__init__(cfg, is_train)

        # fmt: off
        self.attribute_on      = cfg.MODEL.BUA.ATTRIBUTE_ON
        self.max_attr_per_ins  = cfg.INPUT.MAX_ATTR_PER_INS
        # fmt: on
        # NOTE Added to fit d202
        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE)
        else:
            self.crop_gen = None

        self.tfm_gens = utils.build_transform_gen(cfg, is_train)
        self.load_proposals = cfg.MODEL.LOAD_PROPOSALS
        self.mask_on        = cfg.MODEL.MASK_ON
        self.keypoint_on    = cfg.MODEL.KEYPOINT_ON
        self.mask_format    = cfg.INPUT.MASK_FORMAT
Exemplo n.º 29
0
    def __init__(self, cfg, is_train=True):
        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE,
                                         cfg.INPUT.CROP.SIZE)
            logging.getLogger(__name__).info("CropGen used in training: " +
                                             str(self.crop_gen))
        else:
            self.crop_gen = None

        self.tfm_gens = utils.build_transform_gen(cfg, is_train)

        # fmt: off
        self.img_format = cfg.INPUT.FORMAT
        self.hoi_on = cfg.MODEL.MASK_ON
        self.load_proposals = cfg.MODEL.LOAD_PROPOSALS
        # fmt: on

        self.is_train = is_train
Exemplo n.º 30
0
    def __init__(self, cfg, is_train=True):
        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE,
                                         cfg.INPUT.CROP.SIZE)
            logging.getLogger(__name__).info("CropGen used in training: " +
                                             str(self.crop_gen))
        else:
            self.crop_gen = None

        self.tfm_gens = utils.build_transform_gen(cfg, is_train)

        # fmt: off
        self.img_format = cfg.INPUT.FORMAT
        self.mask_on = cfg.MODEL.MASK_ON
        self.mask_format = cfg.INPUT.MASK_FORMAT
        self.keypoint_on = cfg.MODEL.KEYPOINT_ON
        self.load_proposals = cfg.MODEL.LOAD_PROPOSALS
        # fmt: on
        if self.keypoint_on and is_train:
            # Flip only makes sense in training
            self.keypoint_hflip_indices = utils.create_keypoint_hflip_indices(
                cfg.DATASETS.TRAIN)
        else:
            self.keypoint_hflip_indices = None

        if self.load_proposals:
            self.min_box_side_len = cfg.MODEL.PROPOSAL_GENERATOR.MIN_SIZE
            self.proposal_topk = (cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TRAIN
                                  if is_train else
                                  cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TEST)
        self.is_train = is_train
        self.vision_type = cfg.INPUT.VISION_TYPE
        self.manipulation_type = cfg.INPUT.INFER_MANIPULATION_TYPE
        self.manipulation_fun = None
        if self.manipulation_type != "":
            supported_manipulations = get_testing_augmentations()
            self.manipulation_fun = supported_manipulations[
                self.manipulation_type]
        self.manipulation_value = cfg.INPUT.INFER_MANIPULATION_VALUE
        self.opponent_space = cfg.INPUT.OPPONENT_SPACE
        self.contrast = cfg.INPUT.CONTRAST
        self.mosaic_pattern = cfg.INPUT.MOSAIC_PATTERN
        if self.contrast == 1.0:
            self.contrast = None